java - Jersey error when trying to suspend a connection of an asynchronous request -


im doing small test on suspending asynch request using jersey im getting error. let me show im trying , way server , running request failing:

path("/json/metallica") public class jsonservice {      @get     @path("/test")     @produces(mediatype.application_json)     public void getasynchhealthytracks(@suspended asyncresponse asyncresponse){          healthservice.getinstance().gethealththytracks(asyncresponse);     }  } 

when call local host on tomcat following error:

 http status 500 - javax.ws.rs.processingexception: attempt suspend connection of asynchronous request failed in underlying container.  type exception report  message javax.ws.rs.processingexception: attempt suspend connection of asynchronous request failed in underlying container.  description server encountered internal error prevented fulfilling request.  exception  javax.servlet.servletexception: javax.ws.rs.processingexception: attempt suspend connection of asynchronous request failed in underlying container.     org.glassfish.jersey.servlet.webcomponent.service(webcomponent.java:391)     org.glassfish.jersey.servlet.servletcontainer.service(servletcontainer.java:381)     org.glassfish.jersey.servlet.servletcontainer.service(servletcontainer.java:344)     org.glassfish.jersey.servlet.servletcontainer.service(servletcontainer.java:221)     org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:51) root cause  javax.ws.rs.processingexception: attempt suspend connection of asynchronous request failed in underlying container.     org.glassfish.jersey.server.model.resourcemethodinvoker.apply(resourcemethodinvoker.java:312)     org.glassfish.jersey.server.model.resourcemethodinvoker.apply(resourcemethodinvoker.java:103)     org.glassfish.jersey.server.serverruntime$1.run(serverruntime.java:271)     org.glassfish.jersey.internal.errors$1.call(errors.java:271)     org.glassfish.jersey.internal.errors$1.call(errors.java:267)     org.glassfish.jersey.internal.errors.process(errors.java:315)     org.glassfish.jersey.internal.errors.process(errors.java:297)     org.glassfish.jersey.internal.errors.process(errors.java:267)     org.glassfish.jersey.process.internal.requestscope.runinscope(requestscope.java:297)     org.glassfish.jersey.server.serverruntime.process(serverruntime.java:254)     org.glassfish.jersey.server.applicationhandler.handle(applicationhandler.java:1028)     org.glassfish.jersey.servlet.webcomponent.service(webcomponent.java:372)     org.glassfish.jersey.servlet.servletcontainer.service(servletcontainer.java:381)     org.glassfish.jersey.servlet.servletcontainer.service(servletcontainer.java:344)     org.glassfish.jersey.servlet.servletcontainer.service(servletcontainer.java:221)     org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:51) 

i have <async-supported>true</async-supported> in web.xml file , here contents of web.xml file:

 <!doctype web-app public  "-//sun microsystems, inc.//dtd web application 2.3//en"  "http://java.sun.com/dtd/web-app_2_3.dtd" >  <web-app>   <display-name>archetype created web application</display-name>       <servlet>         <servlet-name>jersey-servlet</servlet-name>         <servlet-class>org.glassfish.jersey.servlet.servletcontainer</servlet-class>         <init-param>             <param-name>jersey.config.server.provider.packages</param-name>             <param-value>com.example.ema,com.fasterxml.jackson.jaxrs.json</param-value>             <async-supported>true</async-supported>             <load-on-startup>1</load-on-startup>         </init-param>          <init-param>             <param-name>com.sun.jersey.api.json.pojomappingfeature</param-name>             <param-value>true</param-value>         </init-param>      </servlet>     <servlet-mapping>         <servlet-name>jersey-servlet</servlet-name>         <url-pattern>/rest/*</url-pattern>     </servlet-mapping>    </web-app> 

the health service builds pojo object , should send json. anyway, here service:

public class healthservice { private static healthservice instance = null; protected healthservice() {     // exists defeat instantiation. } public static healthservice getinstance() {     if(instance == null) {         instance = new healthservice();     }     return instance; }  public void gethealthytracks(asyncresponse asyncresponse){       try {         thread.sleep(3000);     } catch (interruptedexception e) {         e.printstacktrace();     }       track track = new track();     track.setsinger("micheal jackson");     track.settitle("thriller");      asyncresponse.resume(track); } 

}

i put break point , not reach initial jersey call. server stops. end goal sleep few seconds , send response.

update: here photo of web.xml now:

enter image description here

i figured out issue. tag "true" should not put in init params section. should put inside servlet tag in web.xml file. web.xml looks this:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"          xmlns:web="http://xmlns.jcp.org/xml/ns/javaee"          xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"          xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"          version="3.1">    <display-name>archetype created web application</display-name>       <servlet>         <servlet-name>jersey-servlet</servlet-name>         <servlet-class>org.glassfish.jersey.servlet.servletcontainer</servlet-class>         <async-supported>true</async-supported>         <init-param>             <param-name>jersey.config.server.provider.packages</param-name>             <param-value>com.example.ema,com.fasterxml.jackson.jaxrs.json</param-value>              <load-on-startup>1</load-on-startup>         </init-param>          <init-param>             <param-name>com.sun.jersey.api.json.pojomappingfeature</param-name>             <param-value>true</param-value>         </init-param>      </servlet>     <servlet-mapping>         <servlet-name>jersey-servlet</servlet-name>         <url-pattern>/rest/*</url-pattern>     </servlet-mapping>    </web-app> 

Comments