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] [Comment Edited] (CXF-6929) Request hangs when using JAX-RS AsyncResponse and Exception mapper
Date Mon, 20 Jun 2016 14:45:05 GMT

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

Sergey Beryozkin edited comment on CXF-6929 at 6/20/16 2:44 PM:
----------------------------------------------------------------

It appears you use an older version of Jetty, please remove the direct jetty dependencies
and instead add: 
{code:xml}
<dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>3.1.7-SNAPSHOT</version>
</dependency>
{code}
and then rewrite your demo code as follows:
{code:java}
        org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000);
        final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
        final ServletContextHandler context = new ServletContextHandler();      
        context.setContextPath("/");
        context.addServlet(servletHolder, "/*");  
        
        servletHolder.setInitParameter( "jaxrs.serviceClasses", Resource.class.getName() );
        servletHolder.setInitParameter( "jaxrs.providers", Mapper.class.getName() );
                
        server.setHandler(context);
        server.start();
        server.join();
{code}

?

Works for me:

{noformat}
curl localhost:9000/foo -v

* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9000 (#0)
> GET /foo HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:9000
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Mon, 20 Jun 2016 14:40:15 GMT
< Date: Mon, 20 Jun 2016 14:40:15 GMT
< Content-Length: 0
* Server Jetty(9.3.5.v20151012) is not blacklisted
< Server: Jetty(9.3.5.v20151012)
< 
* Connection #0 to host localhost left intact

{noformat}



was (Author: sergey_beryozkin):
It appears you use an older version of Jetty, please remove the direct jetty dependencies
instead add: 
{code:xml}
<dependency>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-rt-transports-http-jetty</artifactId>
            <version>3.1.7-SNAPSHOT</version>
</dependency>
{code}
and then rewrite your demo code as follows:
{code:java}
        org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000);
        final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
        final ServletContextHandler context = new ServletContextHandler();      
        context.setContextPath("/");
        context.addServlet(servletHolder, "/*");  
        
        servletHolder.setInitParameter( "jaxrs.serviceClasses", Resource.class.getName() );
        servletHolder.setInitParameter( "jaxrs.providers", Mapper.class.getName() );
                
        server.setHandler(context);
        server.start();
        server.join();
{code}

?

Works for me:

{noformat}
curl localhost:9000/foo -v

* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9000 (#0)
> GET /foo HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:9000
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Mon, 20 Jun 2016 14:40:15 GMT
< Date: Mon, 20 Jun 2016 14:40:15 GMT
< Content-Length: 0
* Server Jetty(9.3.5.v20151012) is not blacklisted
< Server: Jetty(9.3.5.v20151012)
< 
* Connection #0 to host localhost left intact

{noformat}


> 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