atmosphere
  1. atmosphere
  2. ATMOSPHERE-72

WebApplicationException with Response.ok not working

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Incomplete
    • Affects Version/s: 0.6.1
    • Fix Version/s: 0.6
    • Component/s: runtime
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      72

      Description

      As suggested in the newsgroup, I am using the following syntax to avoid
      suspending in a long polling scenario if data is already present.
      // data present, return without suspending
      throw new WebApplicationException(Response.ok(sl).build());

      Using Tomcat6, this works fine with
      <param-name>org.atmosphere.useBlocking</param-name>
      <param-value>false</param-value>

      but when useBlocking is true, the "exception" is treated as a real exception by
      Atmospehere and the client sees a 400 error.

        Activity

        Hide
        mrbeatle added a comment -

        actually, looks like the problem has nothing to do with blocking or not. I am
        having the same problem on glassfish with native=true and blocking=false.

        Is the cause maybe because I moved away from annotation based suspend and
        instead used SuspendRersponse?

        @Path("/signon/response")
        @GET
        @Produces(

        {MediaType.APPLICATION_JSON}

        )
        public SuspendResponse<ResponseWrapper>
        signOnGetResponse(@QueryParam("requestReplyId") String requestReplyId){
        log.debug("GET /signon/response: requestReplyId" +
        requestReplyId);
        try {
        Broadcaster responseBroadcaster =
        BroadcasterFactory.getDefault().get(JerseyBroadcaster.class, requestReplyId);

        responseBroadcaster.broadcastOnResume(ResponseWrapper.getTimeoutWrapper(requestR
        eplyId));
        ResponseWrapper result = (ResponseWrapper)
        ScmaCache.getInstance().get(requestReplyId);
        if (result != null)

        { // return the result immediately log.debug("GET /signon/response: result broadcasted immediately for requestReplyId: " + requestReplyId + "result: " + result); throw new WebApplicationException(Response.ok(result).build()); }

        else

        { log.debug("GET /signon/response: result for requestReplyId: " + requestReplyId + "not found in the cache, so suspending"); SuspendResponse<ResponseWrapper> r = new SuspendResponse.SuspendResponseBuilder<ResponseWrapper>() .broadcaster(responseBroadcaster) .outputComments(false) //.addListener(new EventsLogger()) .period(1, TimeUnit.SECONDS) .resumeOnBroadcast(true) .header("requestReplyId", requestReplyId) .build(); return r; }


        } catch (Exception e)

        { log.error("error calling signon", e); throw new WebApplicationException(400); }


        }

        here is the stack trace.
        javax.ws.rs.WebApplicationException
        at
        com.xxx.myapp.webservices.services.social.SocialCentralService.signOnGetResponse
        (SocialCentralService.java:763)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
        sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
        sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
        a:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
        com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchP
        rovider$JResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.jav
        a:214)
        at
        com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.di
        spatch(ResourceJavaMethodDispatcher.java:67)
        at
        com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:2
        76)
        at
        com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.
        java:133)
        at
        com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.
        java:83)
        at
        com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.
        java:133)
        at
        com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResource
        ClassesRule.java:71)
        at
        com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebAppl
        icationImpl.java:1171)
        at
        com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebAppl
        icationImpl.java:1103)
        at
        com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebAppli
        cationImpl.java:1053)
        at
        com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebAppli
        cationImpl.java:1043)
        at
        com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:406)
        at
        com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.j
        ava:477)
        at
        com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.j
        ava:662)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at
        org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:15
        5)
        at
        org.atmosphere.util.AtmosphereFilterChain.invokeFilterChain(AtmosphereFilterChai
        n.java:116)
        at
        org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.servi
        ce(ReflectorServletProcessor.java:271)
        at
        org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProce
        ssor.java:135)
        at
        org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:187)
        at
        org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:14
        6)
        at
        org.atmosphere.container.GrizzlyCometSupport.service(GrizzlyCometSupport.java:10
        4)
        at
        org.atmosphere.cpr.AtmosphereServlet.doCometSupport(AtmosphereServlet.java:1083)
        at
        org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:1066)
        at
        com.xxx.myapp.webservices.WebServicesServletContainer.doPost(WebServicesServletC
        ontainer.java:62)
        at
        org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:1052)
        at
        com.xxx.myapp.webservices.WebServicesServletContainer.doGet(WebServicesServletCo
        ntainer.java:68)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
        at
        org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
        at
        org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:2
        79)
        at
        org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:1
        88)
        at
        org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
        at
        com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingS
        tandardPipeline.java:85)
        at
        org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
        at
        org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
        at
        org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233)
        at
        com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java
        :165)
        at
        com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
        at
        com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:473)
        at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:341)
        at
        com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:84)
        at
        com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java
        :161)
        at
        com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:137
        )
        at
        com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:88)
        at com.sun.grizzly.http.TaskBase.run(TaskBase.java:189)
        at
        com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:33
        0)
        at
        com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
        at java.lang.Thread.run(Thread.java:619)

        Show
        mrbeatle added a comment - actually, looks like the problem has nothing to do with blocking or not. I am having the same problem on glassfish with native=true and blocking=false. Is the cause maybe because I moved away from annotation based suspend and instead used SuspendRersponse? @Path("/signon/response") @GET @Produces( {MediaType.APPLICATION_JSON} ) public SuspendResponse<ResponseWrapper> signOnGetResponse(@QueryParam("requestReplyId") String requestReplyId){ log.debug("GET /signon/response: requestReplyId" + requestReplyId); try { Broadcaster responseBroadcaster = BroadcasterFactory.getDefault().get(JerseyBroadcaster.class, requestReplyId); responseBroadcaster.broadcastOnResume(ResponseWrapper.getTimeoutWrapper(requestR eplyId)); ResponseWrapper result = (ResponseWrapper) ScmaCache.getInstance().get(requestReplyId); if (result != null) { // return the result immediately log.debug("GET /signon/response: result broadcasted immediately for requestReplyId: " + requestReplyId + "result: " + result); throw new WebApplicationException(Response.ok(result).build()); } else { log.debug("GET /signon/response: result for requestReplyId: " + requestReplyId + "not found in the cache, so suspending"); SuspendResponse<ResponseWrapper> r = new SuspendResponse.SuspendResponseBuilder<ResponseWrapper>() .broadcaster(responseBroadcaster) .outputComments(false) //.addListener(new EventsLogger()) .period(1, TimeUnit.SECONDS) .resumeOnBroadcast(true) .header("requestReplyId", requestReplyId) .build(); return r; } } catch (Exception e) { log.error("error calling signon", e); throw new WebApplicationException(400); } } here is the stack trace. javax.ws.rs.WebApplicationException at com.xxx.myapp.webservices.services.social.SocialCentralService.signOnGetResponse (SocialCentralService.java:763) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav a:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchP rovider$JResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.jav a:214) at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.di spatch(ResourceJavaMethodDispatcher.java:67) at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:2 76) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule. java:133) at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule. java:83) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule. java:133) at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResource ClassesRule.java:71) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebAppl icationImpl.java:1171) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebAppl icationImpl.java:1103) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebAppli cationImpl.java:1053) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebAppli cationImpl.java:1043) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:406) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.j ava:477) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.j ava:662) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:15 5) at org.atmosphere.util.AtmosphereFilterChain.invokeFilterChain(AtmosphereFilterChai n.java:116) at org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.servi ce(ReflectorServletProcessor.java:271) at org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProce ssor.java:135) at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:187) at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:14 6) at org.atmosphere.container.GrizzlyCometSupport.service(GrizzlyCometSupport.java:10 4) at org.atmosphere.cpr.AtmosphereServlet.doCometSupport(AtmosphereServlet.java:1083) at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:1066) at com.xxx.myapp.webservices.WebServicesServletContainer.doPost(WebServicesServletC ontainer.java:62) at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:1052) at com.xxx.myapp.webservices.WebServicesServletContainer.doGet(WebServicesServletCo ntainer.java:68) at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:2 79) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:1 88) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingS tandardPipeline.java:85) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:233) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java :165) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791) at com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:473) at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:341) at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:84) at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java :161) at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:137 ) at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:88) at com.sun.grizzly.http.TaskBase.run(TaskBase.java:189) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:33 0) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309) at java.lang.Thread.run(Thread.java:619)
        Hide
        jfarcand added a comment -

        Add Paul for feedback

        Show
        jfarcand added a comment - Add Paul for feedback
        Hide
        mrbeatle added a comment -

        sorry, this is my error! I was catching the exception myself, thus breaking the
        mechanism.

        Show
        mrbeatle added a comment - sorry, this is my error! I was catching the exception myself, thus breaking the mechanism.
        Hide
        jfarcand added a comment -

        You beat me on the test

        Closing then . Thanks for all the feedback Continue !!!

        Show
        jfarcand added a comment - You beat me on the test Closing then . Thanks for all the feedback Continue !!!

          People

          • Assignee:
            atmosphere-issues
            Reporter:
            mrbeatle
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: