Author: midon
Date: Tue Jul 8 14:52:54 2008
New Revision: 674983
URL: http://svn.apache.org/viewvc?rev=674983&view=rev
Log:
do not use stream!=null to check if body existence, this is error prone.
Modified:
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpClientHelper.java
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
Modified:
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpClientHelper.java
URL:
http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpClientHelper.java?rev=674983&r1=674982&r2=674983&view=diff
==============================================================================
---
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpClientHelper.java
(original)
+++
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpClientHelper.java
Tue Jul 8 14:52:54 2008
@@ -162,8 +162,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
@@ -171,7 +171,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/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
URL:
http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java?rev=674983&r1=674982&r2=674983&view=diff
==============================================================================
---
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
(original)
+++
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
Tue Jul 8 14:52:54 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;
@@ -57,6 +58,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;
@@ -286,6 +288,7 @@
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);
@@ -294,14 +297,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);
@@ -367,8 +369,8 @@
boolean isBodyMandatory = outputContent != null &&
outputContent.getType().endsWith("text/xml");
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);
@@ -377,10 +379,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);