Author: midon
Date: Thu Jun 26 19:29:15 2008
New Revision: 672093
URL: http://svn.apache.org/viewvc?rev=672093&view=rev
Log:
make all methods static
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=672093&r1=672092&r2=672093&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
Thu Jun 26 19:29:15 2008
@@ -19,62 +19,32 @@
package org.apache.ode.axis2.httpbinding;
-import org.apache.commons.httpclient.Header;
+import org.apache.axis2.transport.http.HttpTransportProperties;
import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.StatusLine;
import org.apache.commons.httpclient.URI;
import org.apache.commons.httpclient.URIException;
-import org.apache.commons.httpclient.StatusLine;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
-import org.apache.commons.httpclient.methods.DeleteMethod;
-import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
-import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.params.HttpParams;
-import org.apache.commons.httpclient.params.HostParams;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.commons.lang.StringUtils;
import org.apache.ode.axis2.Properties;
-import org.apache.ode.axis2.util.URLEncodedTransformer;
-import org.apache.ode.axis2.util.UrlReplacementTransformer;
-import org.apache.ode.bpel.epr.MutableEndpoint;
-import org.apache.ode.bpel.iapi.PartnerRoleMessageExchange;
import org.apache.ode.utils.DOMUtils;
-import org.apache.ode.utils.wsdl.Messages;
-import org.apache.ode.utils.wsdl.WsdlUtils;
-import org.apache.axis2.transport.http.HttpTransportProperties;
-import org.w3c.dom.Element;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
-import javax.wsdl.Binding;
-import javax.wsdl.BindingInput;
-import javax.wsdl.BindingOperation;
-import javax.wsdl.Message;
-import javax.wsdl.Operation;
-import javax.wsdl.Part;
-import javax.wsdl.extensions.http.HTTPOperation;
-import javax.wsdl.extensions.mime.MIMEContent;
-import javax.xml.namespace.QName;
-import java.io.UnsupportedEncodingException;
import java.io.IOException;
import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Collection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class HttpClientHelper {
private static final Log log = LogFactory.getLog(HttpClientHelper.class);
- public void configure(HostConfiguration hostConfig, HttpState state, URI
targetURI, HttpParams params) throws URIException {
+ public static void configure(HostConfiguration hostConfig, HttpState
state, URI targetURI, HttpParams params) throws URIException {
if (log.isDebugEnabled()) log.debug("Configuring http client...");
// proxy configuration
if (ProxyConf.isProxyEnabled(params, targetURI.getHost())) {
@@ -95,11 +65,11 @@
* @throws HttpException
* @see #statusLineToElement(org.w3c.dom.Document,
org.apache.commons.httpclient.StatusLine)
*/
- public Element statusLineToElement(String statusLine) throws HttpException
{
+ public static Element statusLineToElement(String statusLine) throws
HttpException {
return statusLineToElement(new StatusLine(statusLine));
}
- public Element statusLineToElement(StatusLine statusLine) {
+ public static Element statusLineToElement(StatusLine statusLine) {
return statusLineToElement(DOMUtils.newDocument(), statusLine);
}
@@ -116,7 +86,7 @@
* @param doc - the document to use to create new nodes
* @return an Element
*/
- public Element statusLineToElement(Document doc, StatusLine statusLine) {
+ public static Element statusLineToElement(Document doc, StatusLine
statusLine) {
Element statusLineEl = doc.createElementNS(null, "Status-Line");
Element versionEl = doc.createElementNS(null, "HTTP-Version");
Element codeEl = doc.createElementNS(null, "Status-Code");
@@ -143,18 +113,17 @@
* @return
* @throws IOException
*/
- public Element prepareDetailsElement(HttpMethod method) throws IOException
{
+ public static Element prepareDetailsElement(HttpMethod method) throws
IOException {
return prepareDetailsElement(method, true);
}
/**
- *
* @param method
* @param bodyIsXml if true the body will be parsed as xml else the body
will be inserted as string
* @return
* @throws IOException
*/
- public Element prepareDetailsElement(HttpMethod method, boolean bodyIsXml)
throws IOException {
+ public static Element prepareDetailsElement(HttpMethod method, boolean
bodyIsXml) throws IOException {
Document doc = DOMUtils.newDocument();
Element detailsEl = doc.createElementNS(null, "details");
Element statusLineEl = statusLineToElement(doc,
method.getStatusLine());
@@ -184,4 +153,42 @@
}
return detailsEl;
}
+
+ private static final Pattern NON_LWS_PATTERN =
Pattern.compile("\r\n([^\\s])");
+
+ /**
+ * This method ensures that a header value containing CRLF does not mess
up the HTTP request.
+ * Actually CRLF is the end-of-line marker for headers.
+ * <p/>
+ * To do so, all CRLF followed by a non-whitespace character are replaced
by CRLF HT.
+ * <p/>
+ * This is possible because the
+ * <a
href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2">Section
2.2</a> of HTTP standard (RFC2626) states that:
+ * <p/>
+ * <quote>
+ * HTTP/1.1 header field values can be folded onto multiple lines if the
+ * continuation line begins with a space or horizontal tab. All linear
+ * white space, including folding, has the same semantics as SP. A
+ * recipient MAY replace any linear white space with a single SP before
+ * interpreting the field value or forwarding the message downstream.
+ * <p/>
+ * LWS = [CRLF] 1*( SP | HT )
+ * <p/>
+ * </quote>
+ * <p/>
+ * FYI, HttpClient 3.x.x does not check this.
+ *
+ * @param header
+ * @return the string properly ready to be used as an HTTP header
field-content
+ */
+ public static String replaceCRLFwithLWS(String header) {
+ Matcher m = NON_LWS_PATTERN.matcher(header);
+ StringBuffer sb = new StringBuffer(header.length());
+ while (m.find()) {
+ m.appendReplacement(sb, "\r\n\t");
+ sb.append(m.group(1));
+ }
+ m.appendTail(sb);
+ return sb.toString();
+ }
}
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=672093&r1=672092&r2=672093&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
Thu Jun 26 19:29:15 2008
@@ -82,7 +82,6 @@
protected String portName;
protected WSAEndpoint endpointReference;
- protected HttpClientHelper helper;
protected HttpMethodConverter httpMethodConverter;
protected Binding portBinding;
@@ -120,7 +119,6 @@
endpointReference =
EndpointFactory.convertToWSA(ODEService.createServiceRef(eprElmt));
httpMethodConverter = new HttpMethodConverter(this.portBinding);
- helper = new HttpClientHelper();
connections = new MultiThreadedHttpConnectionManager();
}
@@ -156,7 +154,7 @@
client.getParams().setDefaults(params);
// configure the client (proxy, security, etc)
- helper.configure(client.getHostConfiguration(), client.getState(),
method.getURI(), params);
+ HttpClientHelper.configure(client.getHostConfiguration(),
client.getState(), method.getURI(), params);
// this callable encapsulates the http method execution and the
process of the response
final Callable executionCallable;
@@ -296,7 +294,7 @@
private void unmanagedStatus() throws IOException {
String errmsg = "Unmanaged Status Code! " + method.getStatusLine();
log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
helper.prepareDetailsElement(method));
+ odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
HttpClientHelper.prepareDetailsElement(method));
}
/**
@@ -313,15 +311,15 @@
if (opDef.getFaults().isEmpty()) {
errmsg = "Operation has no fault. This 500 error will be
considered as a failure.";
if (log.isDebugEnabled()) log.debug(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, helper.prepareDetailsElement(method));
+ odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpClientHelper.prepareDetailsElement(method));
} else if (opBinding.getBindingFaults().isEmpty()) {
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, helper.prepareDetailsElement(method));
+ odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpClientHelper.prepareDetailsElement(method));
} else if (method.getResponseBodyAsStream() == null) {
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, helper.prepareDetailsElement(method));
+ odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpClientHelper.prepareDetailsElement(method));
} else {
final InputStream bodyAsStream =
method.getResponseBodyAsStream();
try {
@@ -333,7 +331,7 @@
if
(!WsdlUtils.isOdeFault(opBinding.getBindingFault(faultDef.getName()))) {
errmsg = "Fault " + bodyName + " is not bound with " +
new QName(Namespaces.ODE_HTTP_EXTENSION_NS, "fault") + ". This 500 error will
be considered as a failure.";
if (log.isDebugEnabled()) log.debug(errmsg);
-
odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
helper.prepareDetailsElement(method));
+
odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
HttpClientHelper.prepareDetailsElement(method));
} else {
Part partDef = (Part)
faultDef.getMessage().getParts().values().iterator().next();
@@ -358,7 +356,7 @@
} catch (Exception e) {
errmsg = "Unable to parse the response body as xml. This
500 error will be considered as a failure.";
if (log.isDebugEnabled()) log.debug(errmsg, e);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, helper.prepareDetailsElement(method, false));
+ odeMex.replyWithFailure(MessageExchange.FailureType.OTHER,
errmsg, HttpClientHelper.prepareDetailsElement(method, false));
}
}
@@ -367,13 +365,13 @@
private void _4xx_badRequest() throws IOException {
String errmsg = "Bad Request! " + method.getStatusLine();
log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
helper.prepareDetailsElement(method));
+ odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
HttpClientHelper.prepareDetailsElement(method));
}
private void _3xx_redirection() throws IOException {
String errmsg = "Redirections are not supported! " +
method.getStatusLine();
log.error(errmsg);
- odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
helper.prepareDetailsElement(method));
+ odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
HttpClientHelper.prepareDetailsElement(method));
}
private void _2xx_success() {
@@ -427,7 +425,7 @@
} catch (Exception ex) {
String errmsg = "Unable to process response: " +
ex.getMessage();
log.error(errmsg, ex);
-
odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
helper.prepareDetailsElement(method));
+
odeMex.replyWithFailure(MessageExchange.FailureType.OTHER, errmsg,
HttpClientHelper.prepareDetailsElement(method));
}
}
} catch (IOException e) {