Author: midon
Date: Mon Jul 14 11:42:50 2008
New Revision: 676684
URL: http://svn.apache.org/viewvc?rev=676684&view=rev
Log:
less lines, better maintenance
Modified:
ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
Modified:
ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
URL:
http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java?rev=676684&r1=676683&r2=676684&view=diff
==============================================================================
---
ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
(original)
+++
ode/branches/APACHE_ODE_1.X/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
Mon Jul 14 11:42:50 2008
@@ -19,15 +19,15 @@
package org.apache.ode.axis2.httpbinding;
+import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.URIException;
-import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.params.HttpParams;
+import org.apache.commons.lang.StringUtils;
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;
@@ -288,10 +288,7 @@
}
private void unmanagedStatus() throws IOException {
- PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange)
server.getEngine().getMessageExchange(mexId);
- String errmsg = "Unmanaged Status Code! Status-Line: " +
method.getStatusLine() + " for " + method.getURI();
- log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
HttpHelper.prepareDetailsElement(method));
+ replyWithFailure("Unmanaged Status Code! Status-Line: " +
method.getStatusLine() + " for " + method.getURI());
}
/**
@@ -321,21 +318,13 @@
Header h = method.getResponseHeader("Content-Type");
String receivedType = h != null ? h.getValue() : null;
if (opDef.getFaults().isEmpty()) {
- errmsg = "Operation [" + opDef.getName() + "] has no fault.
This 500 error will be considered as a failure.";
- log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpHelper.prepareDetailsElement(method));
+ replyWithFailure("Operation [" + opDef.getName() + "] has no
fault. This 500 error will be considered as a failure.");
} else if (opBinding.getBindingFaults().isEmpty()) {
- errmsg = "No fault binding. This 500 error will be considered
as a failure.";
- log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpHelper.prepareDetailsElement(method));
+ replyWithFailure("No fault binding. This 500 error will be
considered as a failure.");
} else if (StringUtils.isEmpty(body)) {
- errmsg = "No body in the response. This 500 error will be
considered as a failure.";
- log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpHelper.prepareDetailsElement(method));
+ replyWithFailure("No body in the response. This 500 error will
be considered as a failure.");
} else if (receivedType != null &&
!HttpHelper.isXml(receivedType)) {
- errmsg = "Response Content-Type [" + receivedType + "] does
not describe XML entities. Faults must be XML. This 500 error will be
considered as a failure.";
- log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpHelper.prepareDetailsElement(method));
+ replyWithFailure("Response Content-Type [" + receivedType + "]
does not describe XML entities. Faults must be XML. This 500 error will be
considered as a failure.");
} else {
if (receivedType == null) {
@@ -348,9 +337,7 @@
try {
bodyElement = DOMUtils.stringToDOM(body);
} catch (Exception e) {
- errmsg = "Unable to parse the response body as xml. This
500 error will be considered as a failure.";
- log.error(errmsg, e);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpHelper.prepareDetailsElement(method));
+ replyWithFailure("Unable to parse the response body as
xml. This 500 error will be considered as a failure.");
return;
}
@@ -359,14 +346,10 @@
Fault faultDef = WsdlUtils.inferFault(opDef, bodyName);
if (faultDef == null) {
- errmsg = "Unknown Fault Type [" + bodyName + "] This 500
error will be considered as a failure.";
- log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpHelper.prepareDetailsElement(method));
+ replyWithFailure("Unknown Fault Type [" + bodyName + "]
This 500 error will be considered as a failure.");
} else if
(!WsdlUtils.isOdeFault(opBinding.getBindingFault(faultDef.getName()))) {
// is this fault bound with ODE extension?
- errmsg = "Fault [" + bodyName + "] is not bound with " +
new QName(Namespaces.ODE_HTTP_EXTENSION_NS, "fault") + ". This 500 error will
be considered as a failure.";
- log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpHelper.prepareDetailsElement(method));
+ replyWithFailure("Fault [" + bodyName + "] is not bound
with " + new QName(Namespaces.ODE_HTTP_EXTENSION_NS, "fault") + ". This 500
error will be considered as a failure.");
} else {
// a fault has only one part
Part partDef = (Part)
faultDef.getMessage().getParts().values().iterator().next();
@@ -394,17 +377,11 @@
}
private void _4xx_badRequest() throws IOException {
- PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange)
server.getEngine().getMessageExchange(mexId);
- String errmsg = "HTTP Status-Line: " + method.getStatusLine() + "
for " + method.getURI();
- log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
HttpClientHelper.prepareDetailsElement(method));
+ replyWithFailure("HTTP Status-Line: " + method.getStatusLine() + "
for " + method.getURI());
}
private void _3xx_redirection() throws IOException {
- PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange)
server.getEngine().getMessageExchange(mexId);
- String errmsg = "Redirections disabled! HTTP Status-Line: " +
method.getStatusLine() + " for " + method.getURI();
- log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
HttpClientHelper.prepareDetailsElement(method));
+ replyWithFailure("Redirections disabled! HTTP Status-Line: " +
method.getStatusLine() + " for " + method.getURI());
}
private void _2xx_success() throws IOException {
@@ -444,9 +421,7 @@
final boolean emptyBody = StringUtils.isEmpty(body);
if (emptyBody) {
if (isBodyMandatory) {
- String errmsg = "Response body is mandatory but missing!
Msg Id=" + odeMex.getMessageExchangeId();
- log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpHelper.prepareDetailsElement(method));
+ replyWithFailure("Response body is mandatory but missing!
Msg Id=" + odeMex.getMessageExchangeId());
return;
}
} else {
@@ -500,10 +475,14 @@
log.info("Response: " + (odeResponse.getMessage() != null
? DOMUtils.domToString(odeResponse.getMessage()) : "empty"));
odeMex.reply(odeResponse);
} catch (Exception ex) {
- String errmsg = "Unable to process response: " +
ex.getMessage();
- log.error(errmsg, ex);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpHelper.prepareDetailsElement(method));
+ replyWithFailure("Unable to process response: " +
ex.getMessage());
}
}
+
+ void replyWithFailure(String errmsg) {
+ log.error(errmsg);
+ PartnerRoleMessageExchange odeMex = (PartnerRoleMessageExchange)
server.getEngine().getMessageExchange(mexId);
+ odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
HttpHelper.prepareDetailsElement(method));
+ }
}
}