I was working in Resteasy where I've to make a asynchronous request to server. The real purpose is, I'll be submitting a form which will be converted into a .xlsx file which will take atleast 10 seconds to complete. So Asynchronous request is the best way here. I followed the procedures from the following link.
If I simply make a ajax request, it gives me 503 Service unavailable error but I do get my Asynchronous task executed, I can confirm by seeing my sysout present in wildfly log. But this is not a way how a asynchronous should be done. I've to be able to see the response of my asynchronous task in the second request. I followed the procedures in this link.
If I put ?asynch=true in the request url, immediately i get a response of 202 Accepted with a location of asynchronous job in response. But it didn't even entered into the try statement. An error is thrown in the wildfly terminal like this.
If I made the same request again with asynch=true, it shows the same error but with (pool-4-thread-2) instead of (pool-4-thread-1)
This means exception is not occured at the server side but at the runtime layer. Coz any exception occured inside my code will be present in log file but not in wildfly terminal. I'll post the web.xml, WebConfig.java, build.gradle files. I'm just replicating the same thing which is done in jboss docs, but I cant figure out why is this exception occuring at the wildfly layer.
Web.xml
<?xml version="1.0" encoding="UTF-8"?><web-appxmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version="3.0"><display-name>Web Application</display-name><distributable/><listener><listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class></listener><listener><listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class></listener><!-- Context Configuration locations for Spring XML files --><context-param><param-name>contextConfigLocation</param-name><param-value>
classpath:/applicationContext-resources.xml
classpath:/applicationContext-dao.xml
classpath:/applicationContext-service.xml
classpath*:/applicationContext.xml
/WEB-INF/applicationContext*.xml
</param-value></context-param><context-param><param-name>resteasy.servlet.mapping.prefix</param-name><param-value>/rest</param-value></context-param><context-param><param-name>resteasy.async.job.service.enabled</param-name><param-value>true</param-value></context-param><context-param><param-name>resteasy.async.job.service.max.job.results</param-name><param-value>100</param-value></context-param><!-- Maximum wait time on a job when a client is querying for it --><context-param><param-name>resteasy.async.job.service.max.wait</param-name><param-value>300000</param-value></context-param><!-- Thread pool size of background threads that run the job --><context-param><param-name>resteasy.async.job.service.thread.pool.size</param-name><param-value>100</param-value></context-param><!-- Set the base path for the Job uris --><context-param><param-name>resteasy.async.job.service.base.path</param-name><param-value>/asynch/jobs</param-value></context-param><servlet><servlet-name>resteasy-servlet</servlet-name><servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class><init-param><param-name>javax.ws.rs.Application</param-name><param-value>com.mypackage.service.WebConfig</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>resteasy-servlet</servlet-name><url-pattern>/rest/*</url-pattern></servlet-mapping><welcome-file-list><welcome-file>login.html</welcome-file></welcome-file-list></web-app>
According to the JAX-RS 2.0 spec, "JAX-RS implementations are REQUIRED to generate a ServiceUnavailableException , a subclass of WebApplicationException with its status set to 503, if the timeout value is reached and no timeout handler is registered." I don't see anything that would cause a timeout in your case - the default behavior is to allow the response to suspend indefinitely.
In particular, see org.jboss.resteasy.test.async.JaxrsAsyncTest. You can run it with
mvn install -Dtest=JaxrsAsyncTest
Or, you can start jetty with
mvn jetty:run
and then run the test in an IDE.
One thing I can tell you is that I'm not sure what happens when you mix "Asynchronous HTTP Request Processing" from Chapter 34 of the Resteasy guide and "Asynchronous Job Service" from Chapter 35. That might be why you're getting a NullPointerException.
Note that the JAX-RS 2.0 spec defines an asynchronous client side facility, which you can use if you want to poll the server. See
I was working in Resteasy where I've to make a asynchronous request to server. The real purpose is, I'll be submitting a form which will be converted into a .xlsx file which will take atleast 10 seconds to complete. So Asynchronous request is the best way here. I followed the procedures from the following link.
https://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html_single/#Asynchronous_HTTP_Request_Processing
I'm making the ajax request like this.
ParentClass.java
If I simply make a ajax request, it gives me 503 Service unavailable error but I do get my Asynchronous task executed, I can confirm by seeing my sysout present in wildfly log. But this is not a way how a asynchronous should be done. I've to be able to see the response of my asynchronous task in the second request. I followed the procedures in this link.
https://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html_single/#async_job
If I put ?asynch=true in the request url, immediately i get a response of 202 Accepted with a location of asynchronous job in response. But it didn't even entered into the try statement. An error is thrown in the wildfly terminal like this.
If I made the same request again with asynch=true, it shows the same error but with (pool-4-thread-2) instead of (pool-4-thread-1)
This means exception is not occured at the server side but at the runtime layer. Coz any exception occured inside my code will be present in log file but not in wildfly terminal. I'll post the web.xml, WebConfig.java, build.gradle files. I'm just replicating the same thing which is done in jboss docs, but I cant figure out why is this exception occuring at the wildfly layer.
Web.xml
WebConfig.java
Build.gradle
Hi Naveen,
According to the JAX-RS 2.0 spec, "JAX-RS implementations are REQUIRED to generate a ServiceUnavailableException , a subclass of WebApplicationException with its status set to 503, if the timeout value is reached and no timeout handler is registered." I don't see anything that would cause a timeout in your case - the default behavior is to allow the response to suspend indefinitely.
There is an asynchronous example here:
In particular, see org.jboss.resteasy.test.async.JaxrsAsyncTest. You can run it with
Or, you can start jetty with
and then run the test in an IDE.
One thing I can tell you is that I'm not sure what happens when you mix "Asynchronous HTTP Request Processing" from Chapter 34 of the Resteasy guide and "Asynchronous Job Service" from Chapter 35. That might be why you're getting a NullPointerException.
Note that the JAX-RS 2.0 spec defines an asynchronous client side facility, which you can use if you want to poll the server. See
for example.
-Ron