Questions Tagged With resthttps://answers.axonivy.com/tags/rest/?type=rss&user=Genzer%20Hawkerquestions tagged <span class="tag">rest</span>enMon, 03 Jun 2019 09:22:49 -0400Consuming Rest in Plugin Projecthttps://answers.axonivy.com/questions/3834/consuming-rest-in-plugin-project<p>Currently, I face the difficulties that there are some lacking libraries when I consuming rest API in Ivy plugin I follow this instruction : <a href="https://answers.axonivy.com/questions/2477/how-to-register-my-code-that-runs-on-every-engine-startup">https://answers.axonivy.com/questions/2477/how-to-register-my-code-that-runs-on-every-engine-startup</a> When user logs in, logs out or gets time-out, I want to call rest service to do some stuff: <img alt="alt text" src="https://answers.axonivy.com/upfiles/call_rest.png"></p> <p>But I get an error like this when calling rest service in the plugin: <img alt="alt text" src="https://answers.axonivy.com/upfiles/error_FGhNT7s.png"></p> <p>Currently, I just add some dependencies like this picture into the plugin but it doesn't work <img alt="alt text" src="https://answers.axonivy.com/upfiles/hint.png"></p> <p>Do you have any hint or any suggestion for this problem? Thanks in advance :)</p>Genzer HawkerMon, 03 Jun 2019 09:22:49 -0400https://answers.axonivy.com/questions/3834/consuming-rest-in-plugin-projectrestHow can I use JAX-RS ContainerRequestFilter/ResponseFilter for my JAX-RS resources.https://answers.axonivy.com/questions/3412/how-can-i-use-jax-rs-containerrequestfilter-responsefilter-for-my-jax-rs-resources<p>Hi,</p> <p>I want to implement my own <code>ContainerRequestFilter</code> and <code>ContainerResponseFilter</code> for my JAX-RS resources in my Axon.ivy projects. Typically, I would create an implementation of the filter:</p> <pre><code>import java.util.logging.*; @Provider public class MyRequestFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { Logger.getLogger("Test").log(Level.WARNING, "LOOK MA! IT WORKS"); } } </code></pre> <p>I assume that Jersey will register my filter and it will works. However, I got </p> <pre><code>javax.servlet.ServletException: java.lang.IllegalStateException: Request scope has been already shut down. at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:489) 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) ... Caused by: 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) ... 46 more </code></pre> <p>..when I call my resources.</p> <p>Is it possible (at all) to use <code>ContainerRequestFilter/ResponseFilter</code> (and <code>Feature</code>, <code>DynamicFeature</code>) in an Axon.ivy project? And without introducing JAR files into <code>webapps/ivy/WEB-INF/lib/</code>?</p> <p>Thanks</p>Genzer HawkerMon, 10 Sep 2018 02:24:40 -0400https://answers.axonivy.com/questions/3412/how-can-i-use-jax-rs-containerrequestfilter-responsefilter-for-my-jax-rs-resourcesjax-rsjerseyrestIs it possible to access Ivy's RESTful API from an HtmlDialog or within the same session?https://answers.axonivy.com/questions/2462/is-it-possible-to-access-ivy-s-restful-api-from-an-htmldialog-or-within-the-same-session<p>Hi Ivy Team</p> <p>I have a HtmlDialog containing several links to our RESTful API (implemented using Axon.ivy). However, every time the user accesses to the API, the browser requires authentication even though the user has already logged in.</p> <p>I'm aware of the <code>javax.annotation.security.PermitAll/DenyAll</code> (-- which seems to be the only annotations supported?) but I want to keep the Basic authentication intact.</p> <p>Say the page could be like this:</p> <pre><code>&lt; !-- The HelloWorld dialog --&gt; &lt; h:html&gt; &lt; h:body&gt; &lt; h:outputLink value="/ivy/api/designer/helloworld" target="_blank"&gt; Click to see Hello World &lt; /h:outputLink&gt; &lt; h:outputLink value="/ivy/file/designer/session/some_file_already_created.txt" target="_blank"&gt; Get content of file &lt; /h:outputLink&gt; &lt; h:/body&gt; &lt; /h:html&gt; </code></pre> <p>The first link will require authentication whereas the second works normally.</p> <p>Is there a possible way to overcome this?</p>Genzer HawkerWed, 22 Feb 2017 08:26:22 -0500https://answers.axonivy.com/questions/2462/is-it-possible-to-access-ivy-s-restful-api-from-an-htmldialog-or-within-the-same-sessionsecurityrestJAX-RS method returns StreamingOutput fails with "Access to ivy environment outside a process request thread is not possible"https://answers.axonivy.com/questions/2072/jax-rs-method-returns-streamingoutput-fails-with-access-to-ivy-environment-outside-a-process-request-thread-is-not-possible<p>Hi Ivy team</p> <p>I want to build a JAX-RS API returning response in a streaming manner (chunked transfer encoding). The code looks like below:</p> <pre><code>@Path("{applicationName}/streams") public class StreamingResponseRestSResource { @GET public Response getStreamingResponse() { // This works by keeping a reference then pass it to the anonymous class. // It may NOT work in all situations. final Logger logger = Ivy.log(); StreamingOutput streamingOutput = new StreamingOutput() { @Override public void write(OutputStream output) throws IOException, WebApplicationException { PrintWriter out = new PrintWriter(new BufferedWriter( new OutputStreamWriter(output)), true); Ivy.log().error("HHH - BREAK HERE"); logger.error("HHH - It works with passed reference of Logger"); IntStream.range(0, 100_000) .forEach(c -&gt; out.println("HHH - Count up to " + c)); } }; return Response.ok(streamingOutput).build(); } } </code></pre> <p>Full code here: <a href="http://pastebin.com/tEAMGFB3">http://pastebin.com/tEAMGFB3</a></p> <p>If I do</p> <p><code>curl -i -u Developer:Developer <a href="http://localhost:8081/ivy/api/designer/streams">http://localhost:8081/ivy/api/designer/streams</a></code></p> <p>the response would be:</p> <p><code>{ "errorId": "1578A42A15718503", "errorMessage": "Access to ivy environment outside a process request thread is not possible.\nCurrent thread: Thread[http-nio-8081-exec-14,5,main]", "statusCode": 500 }</code></p> <p>If I comment out the line ...</p> <p><code>Ivy.log().error("HHH - BREAK HERE");</code></p> <p>...the error disappears.</p> <p>Is there anyway to fix the access to <code>Ivy</code> with <code>StreamingOutput</code> implementation?</p>Genzer HawkerMon, 03 Oct 2016 14:50:20 -0400https://answers.axonivy.com/questions/2072/jax-rs-method-returns-streamingoutput-fails-with-access-to-ivy-environment-outside-a-process-request-thread-is-not-possibleivyrest