You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2017/01/22 09:29:57 UTC

svn commit: r1779786 - in /axis/axis2/java/core/trunk/modules/transport: http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/ http/src/org/apache/axis2/transport/http/ http/src/org/apache/axis2/transport/http/impl/httpclient4/

Author: veithen
Date: Sun Jan 22 09:29:57 2017
New Revision: 1779786

URL: http://svn.apache.org/viewvc?rev=1779786&view=rev
Log:
Unify the CommonsTransportHeaders code.

Removed:
    axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/HTTPTransportHeaders.java
    axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPTransportHeaders.java
Modified:
    axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
    axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java
    axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/CommonsTransportHeaders.java
    axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/Request.java
    axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java
    axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java

Modified: axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java?rev=1779786&r1=1779785&r2=1779786&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java Sun Jan 22 09:29:57 2017
@@ -33,6 +33,7 @@ import org.apache.axis2.context.MessageC
 import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.transport.http.AxisRequestEntity;
+import org.apache.axis2.transport.http.CommonsTransportHeaders;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.transport.http.HTTPSender;
 import org.apache.axis2.transport.http.Request;
@@ -77,13 +78,13 @@ public class HTTPSenderImpl extends HTTP
      * @throws AxisFault
      *             if problems occur
      */
-    protected void obtainHTTPHeaderInformation(HttpMethod method, MessageContext msgContext)
+    protected void obtainHTTPHeaderInformation(Request request, HttpMethod method, MessageContext msgContext)
             throws AxisFault {
         // Set RESPONSE properties onto the REQUEST message context. They will
         // need to be copied off the request context onto
         // the response context elsewhere, for example in the
         // OutInOperationClient.
-        Map transportHeaders = new HTTPTransportHeaders(method.getResponseHeaders());
+        Map transportHeaders = new CommonsTransportHeaders(request.getResponseHeaders());
         msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, transportHeaders);
         msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_CODE,
                 new Integer(method.getStatusCode()));
@@ -172,9 +173,9 @@ public class HTTPSenderImpl extends HTTP
         return cookie;
     }
 
-    protected void processResponse(HttpMethodBase httpMethod, MessageContext msgContext)
+    protected void processResponse(Request request, HttpMethodBase httpMethod, MessageContext msgContext)
             throws IOException {
-        obtainHTTPHeaderInformation(httpMethod, msgContext);
+        obtainHTTPHeaderInformation(request, httpMethod, msgContext);
 
         InputStream in = httpMethod.getResponseBodyAsStream();
         if (in == null) {

Modified: axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java?rev=1779786&r1=1779785&r2=1779786&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http-hc3/src/main/java/org/apache/axis2/transport/http/impl/httpclient3/RequestImpl.java Sun Jan 22 09:29:57 2017
@@ -116,9 +116,7 @@ final class RequestImpl implements Reque
         method.addRequestHeader(name, value);
     }
 
-    @Override
-    public Header[] getRequestHeaders() {
-        org.apache.commons.httpclient.Header[] headers = method.getRequestHeaders();
+    private static Header[] convertHeaders(org.apache.commons.httpclient.Header[] headers) {
         Header[] result = new Header[headers.length];
         for (int i=0; i<headers.length; i++) {
             result[i] = new Header(headers[i].getName(), headers[i].getValue());
@@ -127,6 +125,16 @@ final class RequestImpl implements Reque
     }
 
     @Override
+    public Header[] getRequestHeaders() {
+        return convertHeaders(method.getRequestHeaders());
+    }
+
+    @Override
+    public Header[] getResponseHeaders() {
+        return convertHeaders(method.getResponseHeaders());
+    }
+
+    @Override
     public void execute() throws AxisFault {
         try {
             executeMethod();
@@ -172,13 +180,13 @@ final class RequestImpl implements Reque
             /* When an HTTP 202 Accepted code has been received, this will be the case of an execution 
              * of an in-only operation. In such a scenario, the HTTP response headers should be returned,
              * i.e. session cookies. */
-            sender.obtainHTTPHeaderInformation(method, msgContext);
+            sender.obtainHTTPHeaderInformation(this, method, msgContext);
             // Since we don't expect any content with a 202 response, we must release the connection
             method.releaseConnection();            
         } else if (statusCode >= 200 && statusCode < 300) {
             // Save the HttpMethod so that we can release the connection when cleaning up
             msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
-            sender.processResponse(method, msgContext);
+            sender.processResponse(this, method, msgContext);
         } else if (statusCode == HttpStatus.SC_INTERNAL_SERVER_ERROR
                 || statusCode == HttpStatus.SC_BAD_REQUEST) {
             // Save the HttpMethod so that we can release the connection when
@@ -199,7 +207,7 @@ final class RequestImpl implements Reque
             }
             if (value != null) {
 
-                sender.processResponse(method, msgContext);
+                sender.processResponse(this, method, msgContext);
             }
 
             if (org.apache.axis2.util.Utils.isClientThreadNonBlockingPropertySet(msgContext)) {

Modified: axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/CommonsTransportHeaders.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/CommonsTransportHeaders.java?rev=1779786&r1=1779785&r2=1779786&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/CommonsTransportHeaders.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/CommonsTransportHeaders.java Sun Jan 22 09:29:57 2017
@@ -25,11 +25,22 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
-public abstract class CommonsTransportHeaders implements Map {  
+import org.apache.axiom.mime.Header;
 
-    HashMap headerMap = null;
-   
-    protected abstract void init();
+public final class CommonsTransportHeaders implements Map<String,String> {  
+    private final Header[] headers;
+    private Map<String,String> headerMap;
+    
+    public CommonsTransportHeaders(Header[] headers) {
+        this.headers = headers;
+    }
+
+    private void init() {
+        headerMap = new HashMap<String,String>();
+        for (int i = 0; i < headers.length; i++) {
+            headerMap.put(headers[i].getName(), headers[i].getValue());
+        }
+    }
     
     public int size() {
         if (headerMap == null) {
@@ -65,62 +76,52 @@ public abstract class CommonsTransportHe
         return headerMap.containsValue(value);
     }
 
-    public Collection values() {
+    public Collection<String> values() {
         if (headerMap == null) {
             init();
         }
         return headerMap.values();
     }
 
-    public void putAll(Map t) {
+    public void putAll(Map<? extends String,? extends String> t) {
         if (headerMap == null) {
             init();
         }
         headerMap.putAll(t);
     }
 
-    public Set entrySet() {
+    public Set<Map.Entry<String,String>> entrySet() {
         if (headerMap == null) {
             init();
         }
         return headerMap.entrySet();
     }
 
-    public Set keySet() {
+    public Set<String> keySet() {
         if (headerMap == null) {
             init();
         }
         return headerMap.keySet();
     }
 
-    public Object get(Object key) {
+    public String get(Object key) {
         if (headerMap == null) {
             init();
         }
         return headerMap.get(key);
     }
 
-    public Object remove(Object key) {
+    public String remove(Object key) {
         if (headerMap == null) {
             init();
         }
         return headerMap.remove(key);
     }
 
-    public Object put(Object key, Object value) {
+    public String put(String key, String value) {
         if (headerMap == null) {
             init();
         }
         return headerMap.put(key, value);
     }
-
-    public HashMap getHeaderMap() {
-        return headerMap;
-    }
-
-    public void setHeaderMap(HashMap headerMap) {
-        this.headerMap = headerMap;
-    }
-    
-    
 }

Modified: axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/Request.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/Request.java?rev=1779786&r1=1779785&r2=1779786&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/Request.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/Request.java Sun Jan 22 09:29:57 2017
@@ -31,4 +31,5 @@ public interface Request {
     Header[] getRequestHeaders();
     void enableAuthentication(HTTPAuthenticator authenticator);
     void execute() throws AxisFault;
+    Header[] getResponseHeaders();
 }

Modified: axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java?rev=1779786&r1=1779785&r2=1779786&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/HTTPSenderImpl.java Sun Jan 22 09:29:57 2017
@@ -26,6 +26,7 @@ import org.apache.axis2.context.MessageC
 import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.transport.http.AxisRequestEntity;
+import org.apache.axis2.transport.http.CommonsTransportHeaders;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.transport.http.HTTPSender;
 import org.apache.axis2.transport.http.Request;
@@ -87,13 +88,13 @@ public class HTTPSenderImpl extends HTTP
      *                   NOT!
      * @throws AxisFault if problems occur
      */
-    protected void obtainHTTPHeaderInformation(HttpResponse response, MessageContext msgContext)
+    protected void obtainHTTPHeaderInformation(Request request, HttpResponse response, MessageContext msgContext)
             throws AxisFault {
         // Set RESPONSE properties onto the REQUEST message context. They will
         // need to be copied off the request context onto
         // the response context elsewhere, for example in the
         // OutInOperationClient.
-        Map transportHeaders = new HTTPTransportHeaders(response.getAllHeaders());
+        Map transportHeaders = new CommonsTransportHeaders(request.getResponseHeaders());
         msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, transportHeaders);
         msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_CODE,
                                new Integer(response.getStatusLine().getStatusCode()));

Modified: axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java?rev=1779786&r1=1779785&r2=1779786&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient4/RequestImpl.java Sun Jan 22 09:29:57 2017
@@ -129,9 +129,7 @@ final class RequestImpl implements Reque
         method.addHeader(name, value);
     }
 
-    @Override
-    public Header[] getRequestHeaders() {
-        org.apache.http.Header[] headers = method.getAllHeaders();
+    private static Header[] convertHeaders(org.apache.http.Header[] headers) {
         Header[] result = new Header[headers.length];
         for (int i=0; i<headers.length; i++) {
             result[i] = new Header(headers[i].getName(), headers[i].getValue());
@@ -140,6 +138,16 @@ final class RequestImpl implements Reque
     }
 
     @Override
+    public Header[] getRequestHeaders() {
+        return convertHeaders(method.getAllHeaders());
+    }
+
+    @Override
+    public Header[] getResponseHeaders() {
+        return convertHeaders(response.getAllHeaders());
+    }
+
+    @Override
     public void execute() throws AxisFault {
         try {
             executeMethod();
@@ -197,7 +205,7 @@ final class RequestImpl implements Reque
                 throw new AxisFault(Messages.getMessage("transportError", String.valueOf(statusCode),
                                                         response.getStatusLine().toString()));
             }
-            sender.obtainHTTPHeaderInformation(response, msgContext);
+            sender.obtainHTTPHeaderInformation(this, response, msgContext);
             if (processResponse) {
                 OperationContext opContext = msgContext.getOperationContext();
                 MessageContext inMessageContext = opContext == null ? null