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 bi...@apache.org on 2020/04/14 20:03:15 UTC
[axis-axis2-java-core] 09/15: Merged r1324778 to the AXIS2-4318
branch.
This is an automated email from the ASF dual-hosted git repository.
billblough pushed a commit to branch AXIS2-4318
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git
commit 10997203f96395ea5b9e8ce4643b6d3c2c0e80aa
Author: Sagara Gunathunga <sa...@apache.org>
AuthorDate: Wed Apr 11 14:45:06 2012 +0000
Merged r1324778 to the AXIS2-4318 branch.
---
.../apache/axis2/transport/http/HTTPSender.java | 35 ++++++++++++-
.../http/impl/httpclient3/HTTPSenderImpl.java | 26 ++++-----
.../axis2/transport/http/HTTPSenderTest.java | 41 +++++++++++++++
.../http/mock/server/BasicHttpServer.java | 6 +++
.../http/mock/server/BasicHttpServerImpl.java | 61 +++++++++++++++++++++-
5 files changed, 151 insertions(+), 18 deletions(-)
diff --git a/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java b/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
index 118ffbf..5cce62c 100644
--- a/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
+++ b/modules/transport/http/src/org/apache/axis2/transport/http/HTTPSender.java
@@ -121,6 +121,37 @@ public abstract class HTTPSender extends AbstractHTTPSender {
}
this.sendViaPost(msgContext, url, soapActionString);
- }
-
+ }
+
+ /**
+ * Used to determine the family of HTTP status codes to which the given code
+ * belongs.
+ *
+ * @param statusCode
+ * - The HTTP status code
+ */
+ protected HTTPStatusCodeFamily getHTTPStatusCodeFamily(int statusCode) {
+ switch (statusCode / 100) {
+ case 1:
+ return HTTPStatusCodeFamily.INFORMATIONAL;
+ case 2:
+ return HTTPStatusCodeFamily.SUCCESSFUL;
+ case 3:
+ return HTTPStatusCodeFamily.REDIRECTION;
+ case 4:
+ return HTTPStatusCodeFamily.CLIENT_ERROR;
+ case 5:
+ return HTTPStatusCodeFamily.SERVER_ERROR;
+ default:
+ return HTTPStatusCodeFamily.OTHER;
+ }
+ }
+
+ /**
+ * The set of HTTP status code families.
+ */
+ protected enum HTTPStatusCodeFamily {
+ INFORMATIONAL, SUCCESSFUL, REDIRECTION, CLIENT_ERROR, SERVER_ERROR, OTHER
+ }
+
}
diff --git a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
index 4c5d7b8..2c09c35 100644
--- a/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
+++ b/modules/transport/http/src/org/apache/axis2/transport/http/impl/httpclient3/HTTPSenderImpl.java
@@ -296,23 +296,19 @@ public class HTTPSenderImpl extends HTTPSender {
return;
}
int statusCode = method.getStatusCode();
+ HTTPStatusCodeFamily family = getHTTPStatusCodeFamily(statusCode);
log.trace("Handling response - " + statusCode);
- if (statusCode == HttpStatus.SC_OK) {
- // Save the HttpMethod so that we can release the connection when
- // cleaning up
- msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
- processResponse(method, msgContext);
- } else if (statusCode == HttpStatus.SC_ACCEPTED) {
- /*
- * 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.
- */
+ if (statusCode == HttpStatus.SC_ACCEPTED) {
+ /* 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. */
obtainHTTPHeaderInformation(method, msgContext);
- // Since we don't expect any content with a 202 response, we must
- // release the connection
- method.releaseConnection();
+ // Since we don't expect any content with a 202 response, we must release the connection
+ method.releaseConnection();
+ } else if (HTTPStatusCodeFamily.SUCCESSFUL.equals(family)) {
+ // Save the HttpMethod so that we can release the connection when cleaning up
+ msgContext.setProperty(HTTPConstants.HTTP_METHOD, method);
+ processResponse(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
diff --git a/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java b/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java
index dd77c51..d51b28d 100644
--- a/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java
+++ b/modules/transport/http/test/org/apache/axis2/transport/http/HTTPSenderTest.java
@@ -31,6 +31,7 @@ import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
import org.apache.axis2.transport.http.mock.server.AbstractHTTPServerTest;
+import org.apache.axis2.transport.http.mock.server.BasicHttpServer;
/**
* The Class HTTPSenderTest.
@@ -253,5 +254,45 @@ public abstract class HTTPSenderTest extends AbstractHTTPServerTest {
getHeaders().get(HttpHeaders.USER_AGENT));
}
+ public void testHandleResponseHTTPStatusCode200() throws Exception {
+ httpSender = getHTTPSender();
+ int port = getBasicHttpServer().getPort();
+ getBasicHttpServer().setResponseTemplate(BasicHttpServer.RESPONSE_HTTP_200);
+ sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST, "urn:postService",
+ "http://localhost:" + port + "/postService", true);
+ }
+
+ public void testHandleResponseHTTPStatusCode201() throws Exception {
+ httpSender = getHTTPSender();
+ int port = getBasicHttpServer().getPort();
+ getBasicHttpServer().setResponseTemplate(BasicHttpServer.RESPONSE_HTTP_201);
+ sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST, "urn:postService",
+ "http://localhost:" + port + "/postService", true);
+ }
+
+ public void testHandleResponseHTTPStatusCode202() throws Exception {
+ httpSender = getHTTPSender();
+ int port = getBasicHttpServer().getPort();
+ getBasicHttpServer().setResponseTemplate(BasicHttpServer.RESPONSE_HTTP_202);
+ sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST, "urn:postService",
+ "http://localhost:" + port + "/postService", true);
+ }
+
+ public void testHandleResponseHTTPStatusCode400() throws Exception {
+ httpSender = getHTTPSender();
+ int port = getBasicHttpServer().getPort();
+ getBasicHttpServer().setResponseTemplate(BasicHttpServer.RESPONSE_HTTP_400);
+ sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST, "urn:postService",
+ "http://localhost:" + port + "/postService", true);
+ }
+
+ public void testHandleResponseHTTPStatusCode500() throws Exception {
+ httpSender = getHTTPSender();
+ int port = getBasicHttpServer().getPort();
+ getBasicHttpServer().setResponseTemplate(BasicHttpServer.RESPONSE_HTTP_500);
+ sendViaHTTP(Constants.Configuration.HTTP_METHOD_POST, "urn:postService",
+ "http://localhost:" + port + "/postService", true);
+ }
+
}
diff --git a/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java b/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java
index 211525a..aa20c74 100644
--- a/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java
+++ b/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServer.java
@@ -148,5 +148,11 @@ public interface BasicHttpServer {
public static final String RESPONSE_HTTP_404 = "response.http.404";
public static final String RESPONSE_HTTP_OK_XML = "response.http.ok.xml";
public static final String RESPONSE_HTTP_OK_LOOP_BACK = "response.http.ok.loop.back";
+ public static final String RESPONSE_HTTP_200 = "response.http.200";
+ public static final String RESPONSE_HTTP_201 = "response.http.201";
+ public static final String RESPONSE_HTTP_202 = "response.http.202";
+ public static final String RESPONSE_HTTP_400 = "response.http.400";
+ public static final String RESPONSE_HTTP_500 = "response.http.500";
+
}
diff --git a/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java b/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java
index 4ef79b1..a93e670 100644
--- a/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java
+++ b/modules/transport/http/test/org/apache/axis2/transport/http/mock/server/BasicHttpServerImpl.java
@@ -238,7 +238,66 @@ public class BasicHttpServerImpl implements BasicHttpServer {
}
});
- }
+
+ } else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_200)) {
+ response.setStatusCode(HttpStatus.SC_OK);
+ body = new EntityTemplate(new ContentProducer() {
+
+ public void writeTo(final OutputStream outstream) throws IOException {
+ OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+ writer.write("<Response> SC_ACCEPTED 202 <Response>");
+ writer.flush();
+ }
+
+ });
+
+ } else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_201)) {
+ response.setStatusCode(HttpStatus.SC_CREATED);
+ body = new EntityTemplate(new ContentProducer() {
+
+ public void writeTo(final OutputStream outstream) throws IOException {
+ OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+ //writer.write("<Response> SC_ACCEPTED 202 <Response>");
+ writer.flush();
+ }
+
+ });
+
+ } else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_202)) {
+ response.setStatusCode(HttpStatus.SC_ACCEPTED);
+ body = new EntityTemplate(new ContentProducer() {
+ public void writeTo(final OutputStream outstream) throws IOException {
+ OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+ //writer.write("<Response> SC_ACCEPTED 202 <Response>");
+ writer.flush();
+ }
+
+ });
+
+ } else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_400)) {
+ response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
+ body = new EntityTemplate(new ContentProducer() {
+ public void writeTo(final OutputStream outstream) throws IOException {
+ OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+ //writer.write("<Response> SC_ACCEPTED 202 <Response>");
+ writer.flush();
+ }
+
+ });
+
+ } else if (server.getResponseTemplate().equals(BasicHttpServer.RESPONSE_HTTP_500)) {
+ response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ body = new EntityTemplate(new ContentProducer() {
+ public void writeTo(final OutputStream outstream) throws IOException {
+ OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8");
+ writer.write(" Server Error");
+ writer.flush();
+ }
+
+ });
+
+ }
+
// TODO - customize to send content type depend on expectations.
body.setContentType("text/html; charset=UTF-8");
response.setEntity(body);