cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1350583 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Date Fri, 15 Jun 2012 11:38:14 GMT
Author: sergeyb
Date: Fri Jun 15 11:38:14 2012
New Revision: 1350583

URL: http://svn.apache.org/viewvc?rev=1350583&view=rev
Log:
Merged revisions 1350582 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1350582 | sergeyb | 2012-06-15 12:35:25 +0100 (Fri, 15 Jun 2012) | 1 line
  
  [CXF-3562] Removing references to HTTPUrlConnection from the jjaxrs client code, applying
a patch from Willem
........

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1350582

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Jun 15 11:38:14 2012
@@ -1 +1 @@
-/cxf/trunk:1-1348209,1348845,1348862,1348866,1349016,1349264,1349307,1349406,1349549,1349714-1349717,1349723,1349825,1350114,1350141,1350186,1350215-1350303,1350305,1350318
+/cxf/trunk:1-1348209,1348845,1348862,1348866,1349016,1349264,1349307,1349406,1349549,1349714-1349717,1349723,1349825,1350114,1350141,1350186,1350215-1350303,1350305,1350318,1350582

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1350583&r1=1350582&r2=1350583&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Fri Jun 15 11:38:14 2012
@@ -20,6 +20,7 @@ package org.apache.cxf.jaxrs.client;
 
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.Reader;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.net.HttpURLConnection;
@@ -46,6 +47,7 @@ import javax.ws.rs.core.Response.Respons
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
+import javax.xml.stream.XMLStreamReader;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.i18n.BundleUtils;
@@ -74,7 +76,6 @@ import org.apache.cxf.phase.PhaseManager
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.model.BindingOperationInfo;
 import org.apache.cxf.transport.MessageObserver;
-import org.apache.cxf.transport.http.HTTPConduit;
 
 /**
  * Common proxy and http-centric client implementation
@@ -316,17 +317,25 @@ public abstract class AbstractClient imp
     }
     
     protected ResponseBuilder setResponseBuilder(Message outMessage, Exchange exchange) throws
Exception {
-        HttpURLConnection conn = (HttpURLConnection)outMessage.get(HTTPConduit.KEY_HTTP_CONNECTION);
-        
-        if (conn == null) {
-            throw new ClientWebApplicationException("HTTP Connection is null"); 
-        }
         checkClientException(exchange.getOutMessage(), exchange.getOutMessage().getContent(Exception.class));
         
         int status = (Integer)exchange.get(Message.RESPONSE_CODE);
         ResponseBuilder currentResponseBuilder = Response.status(status);
         
-        for (Map.Entry<String, List<String>> entry : conn.getHeaderFields().entrySet())
{
+        Message responseMessage = exchange.getInMessage() != null 
+            ? exchange.getInMessage() : exchange.getInFaultMessage();
+        // if there is no response message, we just send the response back directly
+        if (responseMessage == null) {
+            ResponseBuilder rb = currentResponseBuilder.clone();
+            state.setResponseBuilder(currentResponseBuilder);
+            return rb;
+        }
+                
+        @SuppressWarnings("unchecked")
+        Map<String, List<String>> protocolHeaders = 
+            (Map<String, List<String>>)responseMessage.get(Message.PROTOCOL_HEADERS);
+                
+        for (Map.Entry<String, List<String>> entry : protocolHeaders.entrySet())
{
             if (null == entry.getKey()) {
                 continue;
             }
@@ -357,27 +366,9 @@ public abstract class AbstractClient imp
                 }
             }
         }
-        InputStream mStream = null;
+        InputStream mStream = responseMessage.getContent(InputStream.class);
+        currentResponseBuilder.entity(mStream);
         
-        Message inMessage = exchange.getInMessage();
-        if (inMessage != null) {
-            mStream = inMessage.getContent(InputStream.class);
-        }
-        if (status >= 400) {
-            try {
-                InputStream errorStream = mStream == null ? conn.getErrorStream() : mStream;
-                currentResponseBuilder.entity(errorStream);
-            } catch (Exception ex) {
-                // nothing we can do really
-            }
-        } else {
-            try {
-                InputStream stream = mStream == null ? conn.getInputStream() : mStream;
-                currentResponseBuilder.entity(stream);
-            } catch (Exception ex) {
-                // it may that the successful response has no response body
-            }
-        }
         ResponseBuilder rb = currentResponseBuilder.clone();
         state.setResponseBuilder(currentResponseBuilder);
         return rb;
@@ -412,12 +403,20 @@ public abstract class AbstractClient imp
     }
     
     @SuppressWarnings("unchecked")
-    protected <T> T readBody(Response r, Message inMessage, Class<T> cls, 
+    protected <T> T readBody(Response r, Message outMessage, Class<T> cls, 
                              Type type, Annotation[] anns) {
-
         InputStream inputStream = (InputStream)r.getEntity();
         if (inputStream == null) {
-            return cls == Response.class ? cls.cast(r) : null;
+            Message responseMessage = outMessage.getExchange().getInMessage();
+            if (responseMessage == null) {
+                responseMessage = outMessage.getExchange().getInFaultMessage();    
+            }    
+            if (responseMessage == null
+                || responseMessage.getContent(XMLStreamReader.class) == null
+                    && responseMessage.getContent(Reader.class) == null) {
+            
+                return cls == Response.class ? cls.cast(r) : null;
+            }
         }
         
         int status = r.getStatus();
@@ -436,8 +435,8 @@ public abstract class AbstractClient imp
         MediaType contentType = getResponseContentType(r);
         
         MessageBodyReader<T> mbr 
-            = ProviderFactory.getInstance(inMessage).createMessageBodyReader(
-                cls, type, anns, contentType, inMessage);
+            = ProviderFactory.getInstance(outMessage).createMessageBodyReader(
+                cls, type, anns, contentType, outMessage);
         if (mbr != null) {
             try {
                 MultivaluedMap<String, String> m 



Mime
View raw message