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/15 22:15:40 UTC
svn commit: r677025 - in /ode/trunk/axis2/src/main/java/org/apache/ode/axis2:
httpbinding/HttpExternalService.java httpbinding/HttpHelper.java
util/URLEncodedTransformer.java util/UrlReplacementTransformer.java
Author: midon
Date: Tue Jul 15 13:15:40 2008
New Revision: 677025
URL: http://svn.apache.org/viewvc?rev=677025&view=rev
Log:
better logging
Modified:
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpExternalService.java
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpHelper.java
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/URLEncodedTransformer.java
ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/UrlReplacementTransformer.java
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=677025&r1=677024&r2=677025&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 15 13:15:40 2008
@@ -83,6 +83,7 @@
protected Binding portBinding;
public HttpExternalService(ProcessConf pconf, QName serviceName, String portName, BpelServer server) {
+ if(log.isDebugEnabled()) log.debug("new HTTP External service, service name=["+serviceName+"]; port name=["+portName+"]");
this.portName = portName;
this.serviceName = serviceName;
this.server = server;
@@ -168,15 +169,15 @@
}
} catch (UnsupportedEncodingException e) {
String errmsg = "The returned HTTP encoding isn't supported " + odeMex;
- log.error(errmsg, e);
+ log.error("[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] "+errmsg, e);
odeMex.replyWithFailure(MessageExchange.FailureType.FORMAT_ERROR, errmsg, null);
} catch (URIException e) {
String errmsg = "Invalid URI " + odeMex;
- log.error(errmsg, e);
+ log.error("[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] "+errmsg, e);
odeMex.replyWithFailure(MessageExchange.FailureType.FORMAT_ERROR, errmsg, null);
} catch (Exception e) {
String errmsg = "Unknown HTTP call error for ODE mex " + odeMex;
- log.error(errmsg, e);
+ log.error("[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] "+errmsg, e);
odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, null);
}
@@ -198,24 +199,29 @@
try {
// simply execute the http method
HttpClient client = new HttpClient(connections);
- if (log.isDebugEnabled())
+ if (log.isDebugEnabled()){
log.debug("Executing http request : " + method.getName() + " " + method.getURI());
+ log.debug(HttpHelper.requestToString(method));
+ }
final int statusCode = client.executeMethod(method);
// invoke getResponseBody to force the loading of the body
// Actually the processResponse may happen in a separate thread and
// as a result the connection might be closed before the body processing (see the finally clause below).
byte[] responseBody = method.getResponseBody();
// ... and process the response
- if (log.isDebugEnabled()) log.debug("Received response for MEX " + odeMex);
+ if (log.isDebugEnabled()) {
+ log.debug("Received response for MEX " + odeMex);
+ log.debug(HttpHelper.responseToString(method));
+ }
processResponse(statusCode);
} catch (final IOException e) {
// Something happened, recording the failure
try {
String errmsg = "Unable to execute HTTP request : " + e.getMessage();
- log.error(errmsg, e);
+ log.error("[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] "+errmsg, e);
odeMex.replyWithFailure(MessageExchange.FailureType.COMMUNICATION_ERROR, errmsg, null);
} catch (Exception e1) {
- String errmsg = "Error executing reply transaction; reply will be lost.";
+ String errmsg = "[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] Error executing reply transaction; reply will be lost.";
log.error(errmsg, e);
}
} finally {
@@ -235,7 +241,7 @@
log.debug("OneWay HTTP Request, Status-Line: " + method.getStatusLine() + " for " + method.getURI());
}
} catch (URIException e) {
- String errmsg = "Exception occured while processing the HTTP response of a one-way request: " + e.getMessage();
+ String errmsg = "[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] Exception occured while processing the HTTP response of a one-way request: " + e.getMessage();
log.error(errmsg, e);
}
}
@@ -262,7 +268,7 @@
}
} catch (Exception e) {
String errmsg = "Exception occured while processing the HTTP response of a two-way request: " + e.getMessage();
- log.error(errmsg, e);
+ log.error("[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] "+errmsg, e);
odeMex.replyWithFailure(MessageExchange.FailureType.FORMAT_ERROR, errmsg, null);
}
}
@@ -279,7 +285,7 @@
private void _5xx_serverError() throws IOException {
String errmsg;
if (log.isWarnEnabled()) {
- errmsg = "Status-Line: " + method.getStatusLine() + " for " + method.getURI();
+ errmsg = "[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] Status-Line: " + method.getStatusLine() + " for " + method.getURI();
log.warn(errmsg);
}
@@ -290,7 +296,7 @@
try {
body = method.getResponseBodyAsString();
} catch (IOException e) {
- errmsg = "Unable to get the request body : " + e.getMessage();
+ errmsg = "[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] Unable to get the request body : " + e.getMessage();
log.error(errmsg, e);
odeMex.replyWithFailure(MessageExchange.FailureType.FORMAT_ERROR, errmsg, HttpHelper.prepareDetailsElement(method));
return;
@@ -310,7 +316,7 @@
if (receivedType == null) {
if (log.isWarnEnabled())
- log.warn("Received Response with a body but no 'Content-Type' header! Will try to parse nevertheless.");
+ log.warn("[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] Received Response with a body but no 'Content-Type' header! Will try to parse nevertheless.");
}
// try to parse body
@@ -350,7 +356,7 @@
// finally send the fault. We did it!
if (log.isWarnEnabled())
- log.warn("Fault response: faultName=" + faultName + " faultType=" + faultType + "\n" + DOMUtils.domToString(response.getMessage()));
+ log.warn("[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] Fault response: faultName=" + faultName + " faultType=" + faultType + "\n" + DOMUtils.domToString(response.getMessage()));
odeMex.replyWithFault(faultName, response);
}
@@ -368,7 +374,7 @@
private void _2xx_success() throws IOException {
if (log.isDebugEnabled())
- log.debug("HTTP Status-Line: " + method.getStatusLine() + " for " + method.getURI());
+ log.debug("[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] HTTP Status-Line: " + method.getStatusLine() + " for " + method.getURI());
if (log.isDebugEnabled()) log.debug("Received response for MEX " + odeMex);
Operation opDef = odeMex.getOperation();
@@ -397,7 +403,7 @@
try {
body = method.getResponseBodyAsString();
} catch (IOException e) {
- String errmsg = "Unable to get the request body : " + e.getMessage();
+ String errmsg = "[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] Unable to get the request body : " + e.getMessage();
log.error(errmsg, e);
odeMex.replyWithFailure(MessageExchange.FailureType.FORMAT_ERROR, errmsg, HttpHelper.prepareDetailsElement(method));
return;
@@ -435,7 +441,7 @@
Element bodyElement = DOMUtils.stringToDOM(body);
partElement = httpMethodConverter.createPartElement(partDef, bodyElement);
} catch (Exception e) {
- String errmsg = "Unable to parse the response body: " + e.getMessage();
+ String errmsg = "[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] Unable to parse the response body: " + e.getMessage();
log.error(errmsg, e);
odeMex.replyWithFailure(MessageExchange.FailureType.FORMAT_ERROR, errmsg, HttpHelper.prepareDetailsElement(method));
return;
@@ -465,7 +471,7 @@
}
void replyWithFailure(String errmsg) {
- log.error(errmsg);
+ log.error("[Service: "+serviceName+", Port: "+portName+", Operation: "+odeMex.getOperationName()+"] "+errmsg);
odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg, HttpHelper.prepareDetailsElement(method));
}
}
Modified: ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpHelper.java
URL: http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpHelper.java?rev=677025&r1=677024&r2=677025&view=diff
==============================================================================
--- ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpHelper.java (original)
+++ ode/trunk/axis2/src/main/java/org/apache/ode/axis2/httpbinding/HttpHelper.java Tue Jul 15 13:15:40 2008
@@ -28,6 +28,9 @@
import org.apache.commons.httpclient.StatusLine;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.params.HttpParams;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -38,6 +41,10 @@
import org.w3c.dom.Document;
import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.io.StringWriter;
+import java.io.PipedOutputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -208,4 +215,67 @@
public static boolean isText(String contentType) {
return TEXT_MIME_TYPE_PATTERN.matcher(contentType).matches();
}
+
+
+ public static String requestToString(HttpMethod m) {
+ StringBuilder sb = new StringBuilder(256);
+ try {
+ sb.append("HTTP Request Details: \n").append(m.getName()).append(" ").append(m.getURI());
+ } catch (URIException e) {
+ // not that important
+ if (log.isDebugEnabled()) log.debug(e);
+ }
+ sb.append("\nRequest Headers:");
+ Header[] headers = m.getRequestHeaders();
+ if (headers.length == 0) sb.append(" n/a");
+ for (int i = 0; i < headers.length; i++) {
+ Header h = headers[i];
+ sb.append("\n\t").append(h.getName()).append(": ").append(h.getValue());
+ }
+ if (m instanceof EntityEnclosingMethod) {
+ EntityEnclosingMethod eem = (EntityEnclosingMethod) m;
+ if (eem.getRequestEntity() != null) {
+ sb.append("\nRequest Entity:");
+ sb.append("\n\tContent-Type:").append(eem.getRequestEntity().getContentType());
+ sb.append("\n\tContent-Length:").append(eem.getRequestEntity().getContentLength());
+ if (eem.getRequestEntity() instanceof StringRequestEntity) {
+ StringRequestEntity sre = (StringRequestEntity) eem.getRequestEntity();
+ sb.append("\n\tContent-Charset:").append(sre.getCharset());
+ sb.append("\n\tRequest Entity:\n").append(sre.getContent());
+ }
+ }
+ }
+ return sb.toString();
+ }
+
+ public static String responseToString(HttpMethod m) {
+ StringBuilder sb = new StringBuilder(256);
+ try {
+ sb.append("HTTP Response Details: \n").append(m.getName()).append(" ").append(m.getURI());
+ } catch (URIException e) {
+ // not that important
+ if (log.isDebugEnabled()) log.debug(e);
+ }
+ sb.append("\nStatus-Line: ").append(m.getStatusLine());
+ Header[] headers = m.getResponseHeaders();
+ if (headers.length != 0) sb.append("\nResponse Headers: ");
+ for (int i = 0; i < headers.length; i++) {
+ Header h = headers[i];
+ sb.append("\n\t").append(h.getName()).append(": ").append(h.getValue());
+ }
+ try {
+ if (StringUtils.isNotEmpty(m.getResponseBodyAsString())) {
+ sb.append("\nResponse Entity:\n").append(m.getResponseBodyAsString());
+ }
+ } catch (IOException e) {
+ log.error(e);
+ }
+ Header[] footers = m.getResponseFooters();
+ if (footers.length != 0) sb.append("\nResponse Footers: ");
+ for (int i = 0; i < footers.length; i++) {
+ Header h = footers[i];
+ sb.append("\n\t").append(h.getName()).append(": ").append(h.getValue());
+ }
+ return sb.toString();
+ }
}
Modified: ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/URLEncodedTransformer.java
URL: http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/URLEncodedTransformer.java?rev=677025&r1=677024&r2=677025&view=diff
==============================================================================
--- ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/URLEncodedTransformer.java (original)
+++ ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/URLEncodedTransformer.java Tue Jul 15 13:15:40 2008
@@ -52,13 +52,10 @@
String partName = e.getKey();
Element node = e.getValue();
String nodeContent = DOMUtils.isEmptyElement(node) ? "" : DOMUtils.getTextContent(node);
- if (nodeContent == null) {
- // if it is not a simple type, skip it
- if (log.isDebugEnabled())
- log.debug("Part " + partName + " skipped because associated element is not of a simple type.");
- continue;
+ // if it is not a simple type, skip it
+ if (nodeContent != null) {
+ l.add(new NameValuePair(e.getKey(), nodeContent));
}
- l.add(new NameValuePair(e.getKey(), nodeContent));
}
return EncodingUtil.formUrlEncode(l.toArray(new NameValuePair[0]), "UTF-8");
}
Modified: ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/UrlReplacementTransformer.java
URL: http://svn.apache.org/viewvc/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/UrlReplacementTransformer.java?rev=677025&r1=677024&r2=677025&view=diff
==============================================================================
--- ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/UrlReplacementTransformer.java (original)
+++ ode/trunk/axis2/src/main/java/org/apache/ode/axis2/util/UrlReplacementTransformer.java Tue Jul 15 13:15:40 2008
@@ -73,26 +73,24 @@
{
Element value = e.getValue();
replacementValue = DOMUtils.isEmptyElement(value) ? "" : DOMUtils.getTextContent(value);
- if (replacementValue == null) {
- // if it is not a simple type, skip it
- if(log.isDebugEnabled()) log.debug("Part "+partName+" skipped because associated element is not of a simple type.");
- continue;
- }
}
- try {
- replacementValue = URIUtil.encodeWithinQuery(replacementValue);
- } catch (URIException urie) {
- // this exception is never thrown by the code of httpclient
- if (log.isWarnEnabled()) log.warn(urie.getMessage(), urie);
- }
+ // if it is not a simple type, skip it
+ if (replacementValue!=null) {
+ try {
+ replacementValue = URIUtil.encodeWithinQuery(replacementValue);
+ } catch (URIException urie) {
+ // this exception is never thrown by the code of httpclient
+ if (log.isWarnEnabled()) log.warn(urie.getMessage(), urie);
+ }
- // first, search for parentheses
- String partPattern = "\\(" + partName + "\\)";
- if(!replace(result, partPattern, replacementValue)){
- // if parentheses not found, try braces
- partPattern = "\\{" + partName + "\\}";
- replace(result, partPattern, replacementValue);
+ // first, search for parentheses
+ String partPattern = "\\(" + partName + "\\)";
+ if(!replace(result, partPattern, replacementValue)){
+ // if parentheses not found, try braces
+ partPattern = "\\{" + partName + "\\}";
+ replace(result, partPattern, replacementValue);
+ }
}
}