Florian Diebold created CXF-6929:
------------------------------------

             Summary: 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
            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. 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)

Reply via email to