Questions asked by ptgianghttps://answers.axonivy.com/questions/asked-by/1242/ptgiang/?type=rssQuestions asked by <a href="/users/1242/ptgiang" >ptgiang</a>enWed, 25 Mar 2020 04:40:40 -0400Can I define REST API endpoint in a jar file?https://answers.axonivy.com/questions/4470/can-i-define-rest-api-endpoint-in-a-jar-file<p>Hello everyone,</p> <p>I have a <strong>maven project</strong> (<strong>jar</strong>), for example, my-api. In this project, I defined a REST API endpoint:</p> <pre><code>@Path("/v1/dossiers") public class MyAPI { @Path("/") public Response getDossiers() { // our logic return response; } } </code></pre> <p>I have an <strong>ivy project</strong>, for example, my-app and I added the jar dependency <strong>my-api</strong>. I can't access the API above from client</p> <p>But, I tried to create a <strong>my-api</strong> as an ivy project (<strong>iar</strong>) and added it as an iar dependency my-app. It works well.</p> <p>My question is: Can I define the REST API endpoint in a jar file? If yes, how can I do that?</p> <p>P/s: We're using Ivy 7.0.11</p>ptgiangWed, 25 Mar 2020 04:40:40 -0400https://answers.axonivy.com/questions/4470/can-i-define-rest-api-endpoint-in-a-jar-fileivyrestCan not add @Provider to handle an specific exception for rest apihttps://answers.axonivy.com/questions/4452/can-not-add-provider-to-handle-an-specific-exception-for-rest-api<p>hi all,</p> <p>I'm creating a rest API for one application. It's working now. I would like to handle some specific exceptions and to return some specific data responses. I used <strong>@Provider</strong> from <strong>javax.ws.rs.ext.Provider</strong> to handle it, but I got an error 500.</p> <pre><code>import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.Provider; import ch.axonivy.fintech.export.dossier.exception.RecordNotFoundException; import ch.axonivy.fintech.export.dossier.response.ExportingErrorResponse; @Provider public class RecordNotFoundExceptionMapper implements ExceptionMapper&lt;RecordNotFoundException&gt; { @Override public Response toResponse(RecordNotFoundException ex) { ExportingErrorResponse response = new ExportingErrorResponse(); response.setStatusCode(Status.NOT_FOUND.getStatusCode()); response.setErrorMessage(ex.getMessage()); return Response.status(response.getStatusCode()).entity(response).type(MediaType.APPLICATION_JSON).build(); } } </code></pre> <p>The following is error:</p> <pre><code>14:59:41.299 WARN [ch.ivyteam.bus.internal] [Worker-45] [executionContext=SYSTEM] Error occured: java.lang.NullPointerException at org.glassfish.jersey.server.ResourceBag$Builder.registerModel(ResourceBag.java:116) at org.glassfish.jersey.server.ResourceBag$Builder.registerProgrammaticResource(ResourceBag.java:110) at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:459) at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184) at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350) at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347) at org.glassfish.jersey.internal.Errors.process(Errors.java:315) at org.glassfish.jersey.internal.Errors.process(Errors.java:297) at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:255) at org.glassfish.jersey.server.ApplicationHandler.&lt;init&gt;(ApplicationHandler.java:347) at org.glassfish.jersey.servlet.WebComponent.&lt;init&gt;(WebComponent.java:392) at org.glassfish.jersey.servlet.ServletContainer.reload(ServletContainer.java:681) at ch.ivyteam.ivy.webserver.internal.rest.RestLifecycleListener.reloadInContext(RestLifecycleListener.java:62) at ch.ivyteam.ivy.webserver.internal.rest.RestLifecycleListener.reload(RestLifecycleListener.java:47) at ch.ivyteam.ivy.webserver.internal.rest.RestLifecycleListener.handleDeprectatedClassLoader(RestLifecycleListener.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.engio.mbassy.dispatch.ReflectiveHandlerInvocation.invoke(ReflectiveHandlerInvocation.java:29) at net.engio.mbassy.dispatch.MessageDispatcher.dispatch(MessageDispatcher.java:30) at net.engio.mbassy.dispatch.FilteredMessageDispatcher.dispatch(FilteredMessageDispatcher.java:42) at net.engio.mbassy.subscription.Subscription.publish(Subscription.java:72) at net.engio.mbassy.bus.MessagePublication.execute(MessagePublication.java:49) at net.engio.mbassy.bus.MBassador.publish(MBassador.java:66) at ch.ivyteam.bus.internal.EventBus.publish(EventBus.java:30) at ch.ivyteam.ivy.java.internal.ClassLoaderHolder.deprecateClassLoaderInternal(ClassLoaderHolder.java:349) at ch.ivyteam.ivy.java.internal.ClassLoaderHolder.deprecateClassLoader(ClassLoaderHolder.java:323) at ch.ivyteam.ivy.java.internal.ClassLoaderHolder.reinstantiateClassLoader(ClassLoaderHolder.java:299) at ch.ivyteam.ivy.java.internal.ClassloaderReinstatiateCompilationParticipant.reinstatiateProjectClassloader(ClassloaderReinstatiateCompilationParticipant.java:82) at ch.ivyteam.ivy.java.internal.ClassloaderReinstatiateCompilationParticipant.buildFinished(ClassloaderReinstatiateCompilationParticipant.java:70) at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:235) at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246) at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:299) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:302) at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:358) at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:381) at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143) at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54) 15:41:38.174 ERROR [org.apache.catalina.core.ContainerBase.[ivy].[localhost].[/ivy].[org.glassfish.jersey.servlet.ServletContainer]] [http-nio-8081-exec-1] [requestId=2832] Servlet.service() for servlet [org.glassfish.jersey.servlet.ServletContainer] in context with path [/ivy] threw exception [java.lang.IllegalStateException: Request scope has been already shut down.] with root cause java.lang.IllegalStateException: Request scope has been already shut down. at jersey.repackaged.com.google.common.base.Preconditions.checkState(Preconditions.java:173) at org.glassfish.jersey.process.internal.RequestScope.retrieveCurrent(RequestScope.java:239) at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:314) at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473) at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341) at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at ch.ivyteam.ivy.webserver.internal.IvyFilter.doFilterInternal(IvyFilter.java:247) at ch.ivyteam.ivy.webserver.internal.IvyFilter.doFilter(IvyFilter.java:152) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at ch.ivyteam.ivy.webserver.internal.IvyExecuteAsSystemFilter$1.call(IvyExecuteAsSystemFilter.java:45) at ch.ivyteam.ivy.webserver.internal.IvyExecuteAsSystemFilter$1.call(IvyExecuteAsSystemFilter.java:1) at ch.ivyteam.ivy.security.internal.SecurityManager.executeAsSystem(SecurityManager.java:1310) at ch.ivyteam.ivy.webserver.internal.IvyExecuteAsSystemFilter.doFilter(IvyExecuteAsSystemFilter.java:39) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.filters.HttpHeaderSecurityFilter.doFilter(HttpHeaderSecurityFilter.java:124) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at ch.ivyteam.ivy.webserver.internal.startup.IvyEngineUnavailableFilter.doFilter(IvyEngineUnavailableFilter.java:48) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at ch.ivyteam.ivy.webserver.internal.filter.IvyCurrentHttpRequestFilter.doFilter(IvyCurrentHttpRequestFilter.java:39) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:120) at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:135) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at ch.ivyteam.ivy.webserver.internal.PerformanceLogValve.invoke(PerformanceLogValve.java:55) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) 15:41:38.325 ERROR [org.apache.myfaces.application.ApplicationImpl] [http-nio-8081-exec-1] [requestId=2832] Could not instantiate component componentType = guiEventListenerComponent [errorId=170D30E5B15459D4, requestId=2832] ch.ivyteam.ivy.environment.EnvironmentNotAvailableException: Access to ivy environment outside a process request thread is not possible. Current thread: Thread[http-nio-8081-exec-1,5,main] at ch.ivyteam.ivy.environment.Ivy.getIvy(Ivy.java:577) at ch.ivyteam.ivy.environment.Ivy.getEnvironmentData(Ivy.java:556) at ch.ivyteam.ivy.environment.Ivy.getEnvironmentData(Ivy.java:551) at ch.ivyteam.ivy.environment.Ivy.request(Ivy.java:244) at ch.axonivy.fintech.guiframework.component.GuiEventListenerFactoryServiceProvider.getProjectClassLoader(GuiEventListenerFactoryServiceProvider.java:67) at ch.axonivy.fintech.guiframework.component.GuiEventListenerFactoryServiceProvider.getFactory(GuiEventListenerFactoryServiceProvider.java:32) at ch.axonivy.fintech.guiframework.component.GuiEventListenerComponent.&lt;init&gt;(GuiEventListenerComponent.java:46) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.Class.newInstance(Class.java:442) at org.apache.myfaces.application.ApplicationImpl.createComponent(ApplicationImpl.java:1469) at javax.faces.application.ApplicationWrapper.createComponent(ApplicationWrapper.java:129) at org.apache.myfaces.view.facelets.compiler.FaceletsCompilerSupport.loadLibraries(FaceletsCompilerSupport.java:141) at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.loadLibraries(FaceletViewDeclarationLanguage.java:2526) at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.createCompiler(FaceletViewDeclarationLanguage.java:2172) at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.initialize(FaceletViewDeclarationLanguage.java:2464) at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.&lt;init&gt;(FaceletViewDeclarationLanguage.java:309) at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguageStrategy.&lt;init&gt;(FaceletViewDeclarationLanguageStrategy.java:52) at org.apache.myfaces.view.ViewDeclarationLanguageFactoryImpl.initialize(ViewDeclarationLanguageFactoryImpl.java:104) at org.apache.myfaces.view.ViewDeclarationLanguageFactoryImpl.getViewDeclarationLanguage(ViewDeclarationLanguageFactoryImpl.java:73) at org.apache.myfaces.application.ViewHandlerImpl.getViewDeclarationLanguage(ViewHandlerImpl.java:183) at javax.faces.application.ViewHandlerWrapper.getViewDeclarationLanguage(ViewHandlerWrapper.java:133) at org.apache.myfaces.shared.application.DefaultViewHandlerSupport.checkResourceExists(DefaultViewHandlerSupport.java:569) at org.apache.myfaces.shared.application.DefaultViewHandlerSupport.handleSuffixMapping(DefaultViewHandlerSupport.java:507) at org.apache.myfaces.shared.application.DefaultViewHandlerSupport.calculateViewId(DefaultViewHandlerSupport.java:113) at org.apache.myfaces.application.ViewHandlerImpl.deriveLogicalViewId(ViewHandlerImpl.java:122) at javax.faces.application.ViewHandlerWrapper.deriveLogicalViewId(ViewHandlerWrapper.java:112) at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:225) at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:196) at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:143) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:728) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:469) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:392) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:311) at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:395) at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:254) at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:349) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:175) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at ch.ivyteam.ivy.webserver.internal.PerformanceLogValve.invoke(PerformanceLogValve.java:55) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) </code></pre> <p>P/s: I’m using Axon Ivy 7.0.11</p> <p>Could you please give me some suggestions or any hints to overcome this issue? Thank you!</p>ptgiangFri, 13 Mar 2020 06:10:26 -0400https://answers.axonivy.com/questions/4452/can-not-add-provider-to-handle-an-specific-exception-for-rest-apiivyrest