cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1497769 - in /cxf/branches/2.7.x-fixes: ./ 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/
Date Fri, 28 Jun 2013 13:39:05 GMT
Author: sergeyb
Date: Fri Jun 28 13:39:05 2013
New Revision: 1497769

URL: http://svn.apache.org/r1497769
Log:
Merged revisions 1497090 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1497090 | sergeyb | 2013-06-26 21:50:41 +0100 (Wed, 26 Jun 2013) | 1 line
  
  [CXF-5093] Initial try to update HTTPConduit and also RS client code to better deal with
requests with no payloads
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    cxf/branches/2.7.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1497090

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1497769&r1=1497768&r2=1497769&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Fri Jun 28 13:39:05 2013
@@ -70,6 +70,7 @@ import org.apache.cxf.interceptor.Interc
 import org.apache.cxf.interceptor.StaxInEndingInterceptor;
 import org.apache.cxf.jaxrs.client.spec.ClientRequestFilterInterceptor;
 import org.apache.cxf.jaxrs.client.spec.ClientResponseFilterInterceptor;
+import org.apache.cxf.jaxrs.ext.form.Form;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.UriBuilderImpl;
 import org.apache.cxf.jaxrs.model.ParameterType;
@@ -897,11 +898,11 @@ public abstract class AbstractClient imp
         }
         
         m.put(Message.CONTENT_TYPE, headers.getFirst(HttpHeaders.CONTENT_TYPE));
+        body = checkIfBodyEmpty(body);
+        setEmptyRequestPropertyIfNeeded(m, body);
         
         m.setContent(List.class, getContentsList(body));
-        if (body == null) {
-            setEmptyRequestProperty(m, httpMethod);
-        }
+        
         
         m.put(URITemplate.TEMPLATE_PARAMETERS, getState().getTemplates());
         
@@ -976,10 +977,20 @@ public abstract class AbstractClient imp
         exchange.putAll(reqContext);
     }
     
-    protected void setEmptyRequestProperty(Message outMessage, String httpMethod) {
-        if ("POST".equals(httpMethod)) {
-            outMessage.put("org.apache.cxf.post.empty", true);
+    protected void setEmptyRequestPropertyIfNeeded(Message outMessage, Object body) {
+        if (body == null) {
+            outMessage.put("org.apache.cxf.empty.request", true);
+        }
+    }
+
+    protected Object checkIfBodyEmpty(Object body) {
+        if (body != null 
+            && (body.getClass() == String.class && ((String)body).length()
== 0 
+            || body.getClass() == Form.class && ((Form)body).getData().isEmpty()
+            || Map.class.isAssignableFrom(body.getClass()) && ((Map<?, ?>)body).isEmpty()))
{
+            body = null;
         }
+        return body;
     }
     
     protected void setPlainOperationNameProperty(Message outMessage, String name) {

Modified: cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=1497769&r1=1497768&r2=1497769&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
Fri Jun 28 13:39:05 2013
@@ -166,7 +166,8 @@ public abstract class HTTPConduit 
 
     private static final String HTTP_POST_METHOD = "POST"; 
     private static final String HTTP_PUT_METHOD = "PUT";
-    
+    private static final Set<String> KNOWN_HTTP_VERBS_WITH_NO_CONTENT = 
+        new HashSet<String>(Arrays.asList(new String[]{"GET", "DELETE", "HEAD", "OPTIONS",
"TRACE"}));
     /**
      * This constant is the Message(Map) key for a list of visited URLs that
      * is used in redirect loop protection.
@@ -1264,21 +1265,16 @@ public abstract class HTTPConduit 
             
             // Trust is okay, set up for writing the request.
             
-            // If this is a GET method we must not touch the output
-            // stream as this automatically turns the request into a POST.
-            // Nor it should be done in case of DELETE/HEAD/OPTIONS 
-            // - strangely, empty PUTs work ok
             String method = getMethod();
-            if (!"POST".equals(method)
-                && !"PUT".equals(method)) {
+            if (KNOWN_HTTP_VERBS_WITH_NO_CONTENT.contains(method)) {
                 handleNoOutput();
                 return;
             }
-            if (outMessage.get("org.apache.cxf.post.empty") != null) {
+
+            if (outMessage.get("org.apache.cxf.empty.request") != null) {
                 handleNoOutput();
                 return;
             }
-            
             setupWrappedStream();
         }
         

Modified: cxf/branches/2.7.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java?rev=1497769&r1=1497768&r2=1497769&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java
Fri Jun 28 13:39:05 2013
@@ -42,6 +42,7 @@ import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.io.AbstractThresholdOutputStream;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageContentsList;
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.MessageObserver;
@@ -138,7 +139,7 @@ public class HTTPConduitURLEasyMockTest 
     public void testSend() throws Exception {
         control = EasyMock.createNiceControl();
         HTTPConduit conduit = setUpConduit(true, false);
-        Message message = new MessageImpl();
+        Message message = createMessage();
         conduit.prepare(message);
         verifySentMessage(conduit, message, "POST");
         finalVerify();
@@ -148,14 +149,20 @@ public class HTTPConduitURLEasyMockTest 
     public void testSendWithHeaders() throws Exception {
         control = EasyMock.createNiceControl();
         HTTPConduit conduit = setUpConduit(true, false);
-        Message message = new MessageImpl();
-        message.put("Content-Type", "text/xml;charset=utf8");
+        Message message = createMessage();
         setUpHeaders(message);
         conduit.prepare(message);
         verifySentMessage(conduit, message, true, "POST", false);
         finalVerify();
     }
     
+    private Message createMessage() {
+        Message message = new MessageImpl();
+        message.put("Content-Type", "text/xml;charset=utf8");
+        message.setContent(List.class, new MessageContentsList("<body/>"));
+        return message;
+    }
+    
     public void testSendWithHeadersCheckErrorStream() throws Exception {
         control = EasyMock.createNiceControl();
         HTTPConduit conduit = setUpConduit(true, false);
@@ -171,7 +178,7 @@ public class HTTPConduitURLEasyMockTest 
     public void testSendHttpConnection() throws Exception {
         control = EasyMock.createNiceControl();
         HTTPConduit conduit = setUpConduit(true, false);
-        Message message = new MessageImpl();
+        Message message = createMessage();
         conduit.prepare(message);
         verifySentMessage(conduit, message, "POST");
         finalVerify();
@@ -181,7 +188,7 @@ public class HTTPConduitURLEasyMockTest 
     public void testSendHttpConnectionAutoRedirect() throws Exception {
         control = EasyMock.createNiceControl();
         HTTPConduit conduit = setUpConduit(true, true);
-        Message message = new MessageImpl();
+        Message message = createMessage();
         conduit.prepare(message);
         verifySentMessage(conduit, message, "POST");
         finalVerify();
@@ -216,7 +223,7 @@ public class HTTPConduitURLEasyMockTest 
         throws Exception {
         control = EasyMock.createNiceControl();
         HTTPConduit conduit = setUpConduit(true, false);
-        Message message = new MessageImpl();
+        Message message = createMessage();
         conduit.prepare(message);
         message.put(Message.PROCESS_ONEWAY_RESPONSE, Boolean.TRUE);
         verifySentMessage(conduit, 
@@ -233,7 +240,7 @@ public class HTTPConduitURLEasyMockTest 
         throws Exception {
         control = EasyMock.createNiceControl();
         HTTPConduit conduit = setUpConduit(true, false);
-        Message message = new MessageImpl();
+        Message message = createMessage();
         conduit.prepare(message);
         verifySentMessage(conduit, 
                           message, 
@@ -249,7 +256,7 @@ public class HTTPConduitURLEasyMockTest 
         throws Exception {
         control = EasyMock.createNiceControl();
         HTTPConduit conduit = setUpConduit(true, false);
-        Message message = new MessageImpl();
+        Message message = createMessage();
         conduit.prepare(message);
         verifySentMessage(conduit, 
                           message, 



Mime
View raw message