You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2014/01/24 23:43:50 UTC
svn commit: r1561222 - in /cxf/trunk:
rt/transports/http/src/main/java/org/apache/cxf/transport/http/
systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
systests/jaxrs/src/test/resources/jaxrs_async/WEB-INF/
Author: reta
Date: Fri Jan 24 22:43:50 2014
New Revision: 1561222
URL: http://svn.apache.org/r1561222
Log:
CXF-5417: Added ConnectionCallback test case and root cause detection
Added:
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationClient.java
Modified:
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsServlet3Test.java
cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_async/WEB-INF/beans.xml
Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java?rev=1561222&r1=1561221&r2=1561222&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Servlet3ContinuationProvider.java Fri Jan 24 22:43:50 2014
@@ -125,7 +125,9 @@ public class Servlet3ContinuationProvide
obj = null;
if (callback != null) {
final Exception ex = inMessage.getExchange().get(Exception.class);
- if (ex instanceof IOException && isClientDisconnected(ex)) {
+ Throwable cause = isCausedByIO( ex );
+
+ if (cause != null && isClientDisconnected(cause)) {
callback.onDisconnect();
}
}
@@ -172,7 +174,18 @@ public class Servlet3ContinuationProvide
//REVISIT: isResumed = true;
redispatch();
}
- private boolean isClientDisconnected(Exception ex) {
+
+ private Throwable isCausedByIO(final Exception ex) {
+ Throwable cause = ex;
+
+ while(cause != null && !(cause instanceof IOException)) {
+ cause = cause.getCause();
+ }
+
+ return cause;
+ }
+
+ private boolean isClientDisconnected(Throwable ex) {
String exName = (String)inMessage.getContextualProperty("disconnected.client.exception.class");
if (exName != null) {
return exName.equals(IOException.class.getName()) || exName.equals(ex.getClass().getName());
Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationClient.java?rev=1561222&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationClient.java (added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationClient.java Fri Jan 24 22:43:50 2014
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.jaxrs;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.testutil.common.AbstractTestServerBase;
+import org.apache.cxf.testutil.common.TestUtil;
+
+public class BookContinuationClient extends AbstractTestServerBase {
+ public static final String PORT = TestUtil.getPortNumber(BookContinuationServlet3Server.class);
+
+ protected void run() {
+
+ }
+
+ public static void main(String args[]) throws InterruptedException, ExecutionException {
+ final String url = "http://localhost:" + PORT + "/async/bookstore/disconnect";
+ WebClient wc = WebClient.create(url);
+ try {
+ System.out.println("server ready");
+ wc.async().get().get(500, TimeUnit.MILLISECONDS);
+ } catch (TimeoutException ex) {
+ ex.printStackTrace();
+ } finally {
+ System.out.println("server stopped");
+ System.out.println("done!");
+ System.exit(0);
+ }
+ }
+}
Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java?rev=1561222&r1=1561221&r2=1561222&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookContinuationStore.java Fri Jan 24 22:43:50 2014
@@ -35,6 +35,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.CompletionCallback;
+import javax.ws.rs.container.ConnectionCallback;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.container.TimeoutHandler;
@@ -136,6 +137,27 @@ public class BookContinuationStore {
throw new BookNotFoundFault("");
}
+ @GET
+ @Path("/disconnect")
+ public void handleClientDisconnects(@Suspended AsyncResponse response) {
+ response.setTimeout(0, TimeUnit.SECONDS);
+
+ response.register(new ConnectionCallback() {
+ @Override
+ public void onDisconnect(AsyncResponse disconnected) {
+ System.out.println("ConnectionCallback: onDisconnect, client disconnects");
+ }
+ });
+
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException ex) {
+ // ignore
+ }
+
+ response.resume(books.values().toString());
+ }
+
private void resumeSuspended(final String id, final AsyncResponse response) {
Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsServlet3Test.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsServlet3Test.java?rev=1561222&r1=1561221&r2=1561222&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsServlet3Test.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSContinuationsServlet3Test.java Fri Jan 24 22:43:50 2014
@@ -20,13 +20,15 @@
package org.apache.cxf.systest.jaxrs;
import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
-
+import org.apache.cxf.testutil.common.ServerLauncher;
import org.junit.BeforeClass;
import org.junit.Test;
public class JAXRSContinuationsServlet3Test extends AbstractJAXRSContinuationsTest {
public static final String PORT = BookContinuationServlet3Server.PORT;
+
+
@BeforeClass
public static void startServers() throws Exception {
AbstractResourceInfo.clearAllMaps();
@@ -42,6 +44,14 @@ public class JAXRSContinuationsServlet3T
doTestTimeoutAndCancel("/asyncexecutor/bookstore");
}
+ @Test
+ public void testClientDisconnect() throws Exception {
+ ServerLauncher launcher = new ServerLauncher(BookContinuationClient.class.getName());
+ assertTrue("server did not launch correctly", launcher.launchServer());
+ Thread.sleep(4000);
+ }
+
+
protected String getBaseAddress() {
return "/async/bookstore";
}
Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_async/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_async/WEB-INF/beans.xml?rev=1561222&r1=1561221&r2=1561222&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_async/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs_async/WEB-INF/beans.xml Fri Jan 24 22:43:50 2014
@@ -34,7 +34,10 @@
<jaxrs:server id="bookservice" address="/async">
<jaxrs:serviceBeans>
<ref bean="serviceBean"/>
- </jaxrs:serviceBeans>
+ </jaxrs:serviceBeans>
+ <jaxrs:properties>
+ <entry key="disconnected.client.exception.class" value="org.eclipse.jetty.io.EofException"/>
+ </jaxrs:properties>
</jaxrs:server>
<jaxrs:server id="bookservice2" address="/asyncexecutor">