cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1350582 - /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Date Fri, 15 Jun 2012 11:35:26 GMT
Author: sergeyb
Date: Fri Jun 15 11:35:25 2012
New Revision: 1350582

URL: http://svn.apache.org/viewvc?rev=1350582&view=rev
Log:
[CXF-3562] Removing references to HTTPUrlConnection from the jjaxrs client code, applying
a patch from Willem

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.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=1350582&r1=1350581&r2=1350582&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
Fri Jun 15 11:35:25 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