You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mi...@apache.org on 2008/07/09 01:05:39 UTC
svn commit: r675029 - in
/ode/branches/APACHE_ODE_1.1/axis2/src/main/java/org/apache/ode/axis2/httpbinding:
HttpClientHelper.java HttpExternalService.java
Author: midon
Date: Tue Jul 8 16:05:39 2008
New Revision: 675029
URL: http://svn.apache.org/viewvc?rev=675029&view=rev
Log:
do not use stream!=null to check if body existence, this is error prone.
Modified:
ode/branches/APACHE_ODE_1.1/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpClientHelper.java
ode/branches/APACHE_ODE_1.1/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
Modified: ode/branches/APACHE_ODE_1.1/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpClientHelper.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.1/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpClientHelper.java?rev=675029&r1=675028&r2=675029&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.1/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpClientHelper.java (original)
+++ ode/branches/APACHE_ODE_1.1/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpClientHelper.java Tue Jul 8 16:05:39 2008
@@ -134,8 +134,8 @@
detailsEl.appendChild(statusLineEl);
// set the body if any
- final InputStream bodyAsStream = method.getResponseBodyAsStream();
- if (bodyAsStream != null) {
+ final String body = method.getResponseBodyAsString();
+ if (StringUtils.isNotEmpty(body)) {
Element bodyEl = doc.createElementNS(null, "responseBody");
detailsEl.appendChild(bodyEl);
// first, try to parse the body as xml
@@ -143,7 +143,7 @@
boolean exceptionDuringParsing = false;
if (bodyIsXml) {
try {
- Element parsedBodyEl = DOMUtils.parse(bodyAsStream).getDocumentElement();
+ Element parsedBodyEl = DOMUtils.stringToDOM(body);
bodyEl.appendChild(doc.importNode(parsedBodyEl, true));
} catch (Exception e) {
String errmsg = "Unable to parse the response body as xml. Body will be inserted as string.";
Modified: ode/branches/APACHE_ODE_1.1/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.1/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java?rev=675029&r1=675028&r2=675029&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.1/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java (original)
+++ ode/branches/APACHE_ODE_1.1/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java Tue Jul 8 16:05:39 2008
@@ -26,6 +26,7 @@
import org.apache.commons.httpclient.params.HttpParams;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.StringUtils;
import org.apache.ode.axis2.ExternalService;
import org.apache.ode.axis2.ODEService;
import org.apache.ode.axis2.Properties;
@@ -58,6 +59,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
+import java.io.StringReader;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
@@ -313,6 +315,7 @@
PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange) server.getEngine().getMessageExchange(mexId);
Operation opDef = odeMex.getOperation();
BindingOperation opBinding = portBinding.getBindingOperation(opDef.getName(), opDef.getInput().getName(), opDef.getOutput().getName());
+ String body = method.getResponseBodyAsString();
if (opDef.getFaults().isEmpty()) {
errmsg = "Operation " + opDef.getName() + " has no fault. This 500 error will be considered as a failure.";
if (log.isDebugEnabled()) log.debug(errmsg);
@@ -321,14 +324,13 @@
errmsg = "No fault binding. This 500 error will be considered as a failure.";
if (log.isDebugEnabled()) log.debug(errmsg);
odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, HttpClientHelper.prepareDetailsElement(method));
- } else if (method.getResponseBodyAsStream() == null) {
+ } else if (StringUtils.isEmpty(body)) {
errmsg = "No body in the response. This 500 error will be considered as a failure.";
if (log.isDebugEnabled()) log.debug(errmsg);
odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, HttpClientHelper.prepareDetailsElement(method));
} else {
- final InputStream bodyAsStream = method.getResponseBodyAsStream();
try {
- Element bodyEl = DOMUtils.parse(bodyAsStream).getDocumentElement();
+ Element bodyEl = DOMUtils.stringToDOM(body);
QName bodyName = new QName(bodyEl.getNamespaceURI(), bodyEl.getNodeName());
Fault faultDef = WsdlUtils.inferFault(opDef, bodyName);
@@ -400,8 +402,8 @@
try {
- final InputStream bodyAsStream = method.getResponseBodyAsStream();
- if (isBodyMandatory && bodyAsStream == null) {
+ final String body = method.getResponseBodyAsString();
+ if (isBodyMandatory && StringUtils.isEmpty(body)) {
String errmsg = "Response body is mandatory but missing! Msg Id=" + odeMex.getMessageExchangeId();
log.error(errmsg);
odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, null);
@@ -410,10 +412,10 @@
Message odeResponse = odeMex.createMessage(outputMessage.getQName());
// handle the body if any
- if (bodyAsStream != null) {
+ if (StringUtils.isNotEmpty(body)) {
// only text/xml is supported in the response body
try {
- Element bodyElement = DOMUtils.parse(bodyAsStream).getDocumentElement();
+ Element bodyElement = DOMUtils.stringToDOM(body);
Part part = outputMessage.getPart(outputContent.getPart());
Element partElement = httpMethodConverter.createPartElement(part, bodyElement);
odeResponse.setPart(part.getName(), partElement);