cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-6929) Request hangs when using JAX-RS AsyncResponse and Exception mapper
Date Wed, 08 Jun 2016 15:44:21 GMT

    [ https://issues.apache.org/jira/browse/CXF-6929?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15320772#comment-15320772
] 

Sergey Beryozkin commented on CXF-6929:
---------------------------------------

I haven't had time to look at it, but I guess you can try a more AsyncResponse friendly way
to report the exception in meantime: asyncResponse.resume(new MyException());

> Request hangs when using JAX-RS AsyncResponse and Exception mapper
> ------------------------------------------------------------------
>
>                 Key: CXF-6929
>                 URL: https://issues.apache.org/jira/browse/CXF-6929
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 3.1.1, 3.1.6
>            Reporter: Florian Diebold
>
> I have a JAX-RS resource which takes an AsyncResponse, but immediately throws an exception
before returning from the function. If the exception is then mapped by an ExceptionMapper,
the response seems to be never sent, and the request hangs (stays suspended forever). Am I
doing something wrong?
> Example code:
> {code}
> import javax.ws.rs.GET;
> import javax.ws.rs.Path;
> import javax.ws.rs.Produces;
> import javax.ws.rs.container.AsyncResponse;
> import javax.ws.rs.container.Suspended;
> import javax.ws.rs.core.Response;
> import javax.ws.rs.ext.ExceptionMapper;
> import org.apache.commons.lang.NotImplementedException;
> import org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet;
> import org.eclipse.jetty.server.Connector;
> import org.eclipse.jetty.server.Server;
> import org.eclipse.jetty.server.ServerConnector;
> import org.eclipse.jetty.servlet.ServletContextHandler;
> import org.eclipse.jetty.servlet.ServletHolder;
> public class ServerDemo2 {
>     public static void main( final String[] args ) throws Exception {
>         final Server server = new Server();
>         final ServerConnector connector = new ServerConnector( server );
>         connector.setHost( "localhost" );
>         connector.setPort( 8888 );
>         server.setConnectors( new Connector[] { connector } );
>         final ServletContextHandler handler = new ServletContextHandler();
>         final ServletHolder holder = new ServletHolder( CXFNonSpringJaxrsServlet.class
);
>         holder.setInitParameter( "jaxrs.serviceClasses", Resource.class.getName() );
>         holder.setInitParameter( "jaxrs.providers", Mapper.class.getName() );
>         handler.addServlet( holder, "/*" );
>         server.setHandler( handler );
>         server.start();
>         System.in.read();
>         server.stop();
>     }
>     public static class Mapper implements ExceptionMapper<NotImplementedException>
{
>         @Override
>         public Response toResponse( final NotImplementedException exception ) {
>             exception.printStackTrace();
>             return Response.ok().build();
>         }
>     }
>     @Path( "/" )
>     public static class Resource {
>         @GET
>         @Path( "/foo" )
>         @Produces( "text/plain" )
>         public void foo( @Suspended final AsyncResponse response ) {
>             throw new NotImplementedException( "foo" );
>         }
>         @GET
>         @Path( "/bar" )
>         @Produces( "text/plain" )
>         public void bar( @Suspended final AsyncResponse response ) {
>             throw new RuntimeException( "bar" );
>         }
>     }
> }
> {code}
> curl localhost:8888/foo hangs forever; curl localhost:8888/bar does not.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message