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/17 19:02:42 UTC

svn commit: r1779232 - in /axis/axis2/java/core/trunk/modules/transport/http: src/org/apache/axis2/transport/http/HTTPSender.java test/org/apache/axis2/transport/http/HTTPClient4SenderTest.java

Author: veithen
Date: Tue Jan 17 19:02:42 2017
New Revision: 1779232

URL: http://svn.apache.org/viewvc?rev=1779232&view=rev
Log:
Don't set the Host header ourselves, especially because the value is incorrect: it's missing the port number! Instead let HTTPClient do it. Note that HTTPClient 3.x ignores the provided Host header anyway and always sends a properly computed value. HTTPClient 4.x on the other hand happily sends the incorrect value.

This also means that we can remove the test methods from HTTPClient4SenderTest which were all overriding the corresponding test methods in HTTPSender, except that they asserted the wrong Host header value.

Modified:
    axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
    axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPClient4SenderTest.java

Modified: axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java?rev=1779232&r1=1779231&r2=1779232&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java Tue Jan 17 19:02:42 2017
@@ -114,8 +114,6 @@ public abstract class HTTPSender extends
             request = preparePost(msgContext, url, buildRequestEntity(messageFormatter, msgContext, soapActionString));
         }
 
-        request.setHeader(HTTPConstants.HEADER_HOST, url.getHost());
-
         if (msgContext.getOptions() != null && msgContext.getOptions().isManageSession()) {
             // setting the cookie in the out path
             Object cookieString = msgContext.getProperty(HTTPConstants.COOKIE_STRING);

Modified: axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPClient4SenderTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPClient4SenderTest.java?rev=1779232&r1=1779231&r2=1779232&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPClient4SenderTest.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPClient4SenderTest.java Tue Jan 17 19:02:42 2017
@@ -19,159 +19,12 @@
 
 package org.apache.axis2.transport.http;
 
-import org.apache.axis2.Constants;
 import org.apache.axis2.transport.http.impl.httpclient4.HTTPSenderImpl;
 
-import static com.google.common.truth.Truth.assertAbout;
-import static org.apache.axiom.truth.xml.XMLTruth.xml;
-
-import javax.ws.rs.core.HttpHeaders;
-
 public class HTTPClient4SenderTest extends HTTPSenderTest {
 
     @Override
     protected HTTPSender getHTTPSender() {
         return new HTTPSenderImpl();
     }
-
-    @Override
-    public void testSendViaGet() throws Exception {
-        int port = getBasicHttpServer().getPort();
-        sendViaHTTP(Constants.Configuration.HTTP_METHOD_GET, "urn:getService", "http://localhost:"
-                                                                               + port + "/getService", true);
-        assertEquals("Not the expected HTTP Method", Constants.Configuration.HTTP_METHOD_GET,
-                     getHTTPMethod());
-        assertEquals("Not the expected content", "/getService?part=sample%20data",
-                     getStringContent());
-        assertNull("Not the expected HTTP Header value", getHeaders().get("SOAPAction"));
-        assertEquals("Not the expected HTTP Header value",
-                     "application/x-www-form-urlencoded;action=\"urn:getService\";",
-                     getHeaders().get(HttpHeaders.CONTENT_TYPE));
-        assertEquals("Not the expected HTTP Header value", "localhost",
-                     getHeaders().get(HttpHeaders.HOST));
-        assertEquals("Not the expected HTTP Header value", "Axis2",
-                     getHeaders().get(HttpHeaders.USER_AGENT));
-    }
-
-    @Override
-    public void testSendViaPost() throws Exception {
-        // test with REST payload
-        int port = getBasicHttpServer().getPort();
-        sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST, "urn:postService",
-                    "http://localhost:" + port + "/postService", true);
-        assertEquals("Not the expected HTTP Method", Constants.Configuration.HTTP_METHOD_POST,
-                     getHTTPMethod());
-        assertEquals("Not the expected content", getEnvelope().getFirstElement().getFirstElement()
-                .toString(), getStringContent());
-        assertNull("Not the expected HTTP Header value", getHeaders().get("SOAPAction"));
-        assertEquals("Not the expected HTTP Header value", "application/xml",
-                     getHeaders().get(HttpHeaders.CONTENT_TYPE));
-        assertEquals("Not the expected HTTP Header value", "localhost",
-                     getHeaders().get(HttpHeaders.HOST));
-        assertEquals("Not the expected HTTP Header value", "Axis2",
-                     getHeaders().get(HttpHeaders.USER_AGENT));
-
-        // test with SOAP payload.
-        sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST, "urn:postService",
-                    "http://localhost:" + port + "/postService", false);
-        assertEquals("Not the expected HTTP Method", Constants.Configuration.HTTP_METHOD_POST,
-                     getHTTPMethod());
-        assertAbout(xml()).that(getStringContent()).hasSameContentAs(getEnvelope().toString());
-        assertEquals("Not the expected HTTP Header value", "urn:postService",
-                     getHeaders().get("SOAPAction").replace("\"", ""));
-        assertEquals("Not the expected HTTP Header value", "text/xml",
-                     getHeaders().get(HttpHeaders.CONTENT_TYPE));
-        assertEquals("Not the expected HTTP Header value", "localhost",
-                     getHeaders().get(HttpHeaders.HOST));
-        assertEquals("Not the expected HTTP Header value", "Axis2",
-                     getHeaders().get(HttpHeaders.USER_AGENT));
-    }
-
-    @Override
-    public void testSendViaPut() throws Exception {
-        // test with REST payload
-        int port = getBasicHttpServer().getPort();
-        sendViaHTTP(Constants.Configuration.HTTP_METHOD_PUT, "urn:putService", "http://localhost:"
-                                                                               + port + "/putService", true);
-        assertEquals("Not the expected HTTP Method", Constants.Configuration.HTTP_METHOD_PUT,
-                     getHTTPMethod());
-        assertEquals("Not the expected content", getEnvelope().getFirstElement().getFirstElement()
-                .toString(), getStringContent());
-        assertNull("Not the expected HTTP Header value", getHeaders().get("SOAPAction"));
-        assertEquals("Not the expected HTTP Header value", "application/xml",
-                     getHeaders().get(HttpHeaders.CONTENT_TYPE));
-        assertEquals("Not the expected HTTP Header value", "localhost",
-                     getHeaders().get(HttpHeaders.HOST));
-        assertEquals("Not the expected HTTP Header value", "Axis2",
-                     getHeaders().get(HttpHeaders.USER_AGENT));
-
-        // test with SOAP payload.
-        sendViaHTTP(Constants.Configuration.HTTP_METHOD_PUT, "urn:putService", "http://localhost:"
-                                                                               + port + "/putService", false);
-        assertEquals("Not the expected HTTP Method", Constants.Configuration.HTTP_METHOD_PUT,
-                     getHTTPMethod());
-        assertAbout(xml()).that(getStringContent()).hasSameContentAs(getEnvelope().toString());
-        assertEquals("Not the expected HTTP Header value", "urn:putService",
-                     getHeaders().get("SOAPAction").replace("\"", ""));
-        assertEquals("Not the expected HTTP Header value", "text/xml",
-                     getHeaders().get(HttpHeaders.CONTENT_TYPE));
-        assertEquals("Not the expected HTTP Header value", "localhost",
-                     getHeaders().get(HttpHeaders.HOST));
-        assertEquals("Not the expected HTTP Header value", "Axis2",
-                     getHeaders().get(HttpHeaders.USER_AGENT));
-    }
-
-    @Override
-    public void testSendViaDelete() throws Exception {
-        // test with REST payload
-        int port = getBasicHttpServer().getPort();
-        sendViaHTTP(Constants.Configuration.HTTP_METHOD_DELETE, "urn:deleteService",
-                    "http://localhost:" + port + "/deleteService", true);
-        assertEquals("Not the expected HTTP Method", Constants.Configuration.HTTP_METHOD_DELETE,
-                     getHTTPMethod());
-        assertEquals("Not the expected content", "/deleteService?part=sample%20data",
-                     getStringContent());
-        assertEquals("Not the expected HTTP Header value",
-                     "application/x-www-form-urlencoded;action=\"urn:deleteService\";", getHeaders()
-                .get(HttpHeaders.CONTENT_TYPE));
-        assertEquals("Not the expected HTTP Header value", "localhost",
-                     getHeaders().get(HttpHeaders.HOST));
-        assertEquals("Not the expected HTTP Header value", "Axis2",
-                     getHeaders().get(HttpHeaders.USER_AGENT));
-    }
-
-    @Override
-    public void testSendViaHead() throws Exception {
-        int port = getBasicHttpServer().getPort();
-        sendViaHTTP(Constants.Configuration.HTTP_METHOD_HEAD, "urn:deleteService",
-                    "http://localhost:" + port + "/deleteService", true);
-        assertEquals("Not the expected HTTP Method", Constants.Configuration.HTTP_METHOD_POST,
-                     getHTTPMethod());
-        assertEquals("Not the expected content", getEnvelope().getFirstElement().getFirstElement()
-                .toString(), getStringContent());
-        assertEquals("Not the expected HTTP Header value", "application/xml",
-                     getHeaders().get(HttpHeaders.CONTENT_TYPE));
-        assertEquals("Not the expected HTTP Header value", "localhost",
-                     getHeaders().get(HttpHeaders.HOST));
-        assertEquals("Not the expected HTTP Header value", "Axis2",
-                     getHeaders().get(HttpHeaders.USER_AGENT));
-
-    }
-
-    @Override
-    public void testSendNOHTTPMethod() throws Exception {
-        int port = getBasicHttpServer().getPort();
-        sendViaHTTP(null, "urn:noService", "http://localhost:" + port + "/noService", true);
-        assertEquals("Not the expected HTTP Method", Constants.Configuration.HTTP_METHOD_POST,
-                     getHTTPMethod());
-        assertEquals("Not the expected content", getEnvelope().getFirstElement().getFirstElement()
-                .toString(), getStringContent());
-        assertNull("Not the expected HTTP Header value", getHeaders().get("SOAPAction"));
-        assertEquals("Not the expected HTTP Header value", "application/xml",
-                     getHeaders().get(HttpHeaders.CONTENT_TYPE));
-        assertEquals("Not the expected HTTP Header value", "localhost",
-                     getHeaders().get(HttpHeaders.HOST));
-        assertEquals("Not the expected HTTP Header value", "Axis2",
-                     getHeaders().get(HttpHeaders.USER_AGENT));
-    }
 }