You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2010/11/16 13:43:32 UTC
svn commit: r1035614 - in /cxf/trunk:
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/
rt/transports/http/src/main/java/org/apache/cxf/transport/http/
rt/transports/http/src/test/java/org/apache/cxf/transport/http/
systests/jaxrs/src/test/j...
Author: sergeyb
Date: Tue Nov 16 12:43:32 2010
New Revision: 1035614
URL: http://svn.apache.org/viewvc?rev=1035614&view=rev
Log:
[CXF-3127] Updating HttpConduit to check a non-error input stream only in case of successful requests
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1035614&r1=1035613&r2=1035614&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java Tue Nov 16 12:43:32 2010
@@ -601,6 +601,9 @@ public class AbstractClient implements C
exchange.put(MessageObserver.class, new ClientMessageObserver(cfg));
exchange.put(Endpoint.class, cfg.getConduitSelector().getEndpoint());
exchange.setOneWay("true".equals(headers.getFirst(Message.ONE_WAY_REQUEST)));
+ // no need for the underlying conduit to throw the IO exceptions in case of
+ // client requests returning error HTTP code, it can be overridden if really needed
+ exchange.put("org.apache.cxf.http.no_io_exceptions", true);
m.setExchange(exchange);
PhaseInterceptorChain chain = setupOutInterceptorChain(cfg);
@@ -614,6 +617,7 @@ public class AbstractClient implements C
m.put(Message.INVOCATION_CONTEXT, context);
m.putAll(cfg.getRequestContext());
exchange.putAll(cfg.getRequestContext());
+ exchange.putAll(cfg.getResponseContext());
}
//setup conduit selector
Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=1035614&r1=1035613&r2=1035614&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Tue Nov 16 12:43:32 2010
@@ -2178,12 +2178,20 @@ public class HTTPConduit
}
}
}
- if (responseCode != HttpURLConnection.HTTP_NOT_FOUND) {
- in = in == null
- ? connection.getErrorStream() == null
- ? connection.getInputStream()
- : connection.getErrorStream()
- : in;
+ if (in == null) {
+ if (responseCode >= HttpURLConnection.HTTP_BAD_REQUEST) {
+ in = connection.getErrorStream();
+ if (in == null) {
+ try {
+ // just in case - but this will most likely cause an exception
+ in = connection.getInputStream();
+ } catch (IOException ex) {
+ // ignore
+ }
+ }
+ } else {
+ in = connection.getInputStream();
+ }
}
// if (in == null) : it's perfectly ok for non-soap http services
// have no response body : those interceptors which do need it will check anyway
Modified: cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java?rev=1035614&r1=1035613&r2=1035614&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java (original)
+++ cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java Tue Nov 16 12:43:32 2010
@@ -55,7 +55,7 @@ import org.junit.Test;
*/
public class HTTPConduitURLEasyMockTest extends Assert {
- private enum ResponseStyle { NONE, BACK_CHANNEL, DECOUPLED };
+ private enum ResponseStyle { NONE, BACK_CHANNEL, BACK_CHANNEL_ERROR, DECOUPLED };
private enum ResponseDelimiter { LENGTH, CHUNKED, EOF };
private static final String NOWHERE = "http://nada.nothing.nowhere.null/";
@@ -136,7 +136,18 @@ public class HTTPConduitURLEasyMockTest
message.put("Content-Type", "text/xml;charset=utf8");
setUpHeaders(message);
conduit.prepare(message);
- verifySentMessage(conduit, message, true, "POST");
+ verifySentMessage(conduit, message, true, "POST", false);
+ finalVerify();
+ }
+
+ public void testSendWithHeadersCheckErrorStream() throws Exception {
+ control = EasyMock.createNiceControl();
+ HTTPConduit conduit = setUpConduit(true, false);
+ Message message = new MessageImpl();
+ message.put("Content-Type", "text/xml;charset=utf8");
+ setUpHeaders(message);
+ conduit.prepare(message);
+ verifySentMessage(conduit, message, true, "POST", true);
finalVerify();
}
@@ -308,18 +319,19 @@ public class HTTPConduitURLEasyMockTest
private void verifySentMessage(HTTPConduit conduit, Message message, String method)
throws IOException {
- verifySentMessage(conduit, message, false, method);
+ verifySentMessage(conduit, message, false, method, false);
}
private void verifySentMessage(HTTPConduit conduit,
Message message,
boolean expectHeaders,
- String method)
+ String method,
+ boolean errorExpected)
throws IOException {
verifySentMessage(conduit,
message,
expectHeaders,
- ResponseStyle.BACK_CHANNEL,
+ errorExpected ? ResponseStyle.BACK_CHANNEL_ERROR : ResponseStyle.BACK_CHANNEL,
method);
}
@@ -396,9 +408,7 @@ public class HTTPConduitURLEasyMockTest
assertNotNull("expected in message", inMessage);
Map<?, ?> headerMap = (Map<?, ?>) inMessage.get(Message.PROTOCOL_HEADERS);
assertEquals("unexpected response headers", headerMap.size(), 0);
- Integer expectedResponseCode = style == ResponseStyle.BACK_CHANNEL
- ? HttpURLConnection.HTTP_OK
- : HttpURLConnection.HTTP_ACCEPTED;
+ Integer expectedResponseCode = getResponseCode(style);
assertEquals("unexpected response code",
expectedResponseCode,
inMessage.get(Message.RESPONSE_CODE));
@@ -472,9 +482,7 @@ public class HTTPConduitURLEasyMockTest
HTTPConduit conduit) throws IOException {
connection.getHeaderFields();
EasyMock.expectLastCall().andReturn(Collections.EMPTY_MAP).anyTimes();
- int responseCode = style == ResponseStyle.BACK_CHANNEL
- ? HttpURLConnection.HTTP_OK
- : HttpURLConnection.HTTP_ACCEPTED;
+ int responseCode = getResponseCode(style);
if (conduit.getClient().isAutoRedirect()) {
connection.getResponseCode();
EasyMock.expectLastCall().andReturn(301).once().andReturn(responseCode).anyTimes();
@@ -513,9 +521,12 @@ public class HTTPConduitURLEasyMockTest
break;
case BACK_CHANNEL:
+ break;
+
+ case BACK_CHANNEL_ERROR:
connection.getErrorStream();
EasyMock.expectLastCall().andReturn(null);
- break;
+ break;
default:
break;
@@ -528,5 +539,16 @@ public class HTTPConduitURLEasyMockTest
control = null;
}
}
-
+
+ private int getResponseCode(ResponseStyle style) {
+ int code;
+ if (style == ResponseStyle.BACK_CHANNEL) {
+ code = HttpURLConnection.HTTP_OK;
+ } else if (style == ResponseStyle.BACK_CHANNEL_ERROR) {
+ code = HttpURLConnection.HTTP_BAD_REQUEST;
+ } else {
+ code = HttpURLConnection.HTTP_ACCEPTED;
+ }
+ return code;
+ }
}
Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=1035614&r1=1035613&r2=1035614&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java Tue Nov 16 12:43:32 2010
@@ -74,7 +74,7 @@ public class JAXRSSoapBookTest extends A
@BeforeClass
public static void startServers() throws Exception {
assertTrue("server did not launch correctly",
- launchServer(BookServerRestSoap.class, true));
+ launchServer(BookServerRestSoap.class));
}
@Test
@@ -543,7 +543,7 @@ public class JAXRSSoapBookTest extends A
@Test
public void testServerFaultInInterceptor() throws Exception {
//testing faults created by server handled correctly
- serverFaultInInterceptorTest("321");
+
//999 causes error code of 404, 404 has a different code path so need to test too
serverFaultInInterceptorTest("999");
//322 causes a checked exception to be thrown so need to
@@ -586,6 +586,7 @@ public class JAXRSSoapBookTest extends A
features.add((AbstractFeature)testFeature);
bean.setFeatures(features);
BookStoreJaxrsJaxws proxy = (BookStoreJaxrsJaxws)bean.create();
+ WebClient.getConfig(proxy).getRequestContext().put("org.apache.cxf.http.no_io_exceptions", false);
try {
//321 is special case - causes error code of 525
proxy.getBook(new Long(param));