You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ke...@apache.org on 2007/02/05 09:21:19 UTC
svn commit: r503585 [8/9] - in /webservices/axis2/trunk/java: etc/
modules/adb-codegen/ modules/adb-codegen/src/org/apache/axis2/schema/
modules/adb-codegen/src/org/apache/axis2/schema/template/ modules/adb/
modules/addressing/ modules/addressing/src/o...
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java?view=diff&rev=503585&r1=503584&r2=503585
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java Mon Feb 5 00:21:12 2007
@@ -16,94 +16,148 @@
package org.apache.axis2.transport.http;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Iterator;
-
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.WSDL2Constants;
import org.apache.axis2.i18n.Messages;
+import org.apache.axis2.transport.http.util.ComplexPart;
+import org.apache.axis2.util.JavaUtils;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.methods.DeleteMethod;
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.multipart.MultipartRequestEntity;
+import org.apache.commons.httpclient.methods.multipart.Part;
+import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import javax.xml.namespace.QName;
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+
public class RESTSender extends AbstractHTTPSender {
private static final Log log = LogFactory.getLog(RESTSender.class);
+ public Part[] createMultipatFormDataRequest(MessageContext msgContext, OMElement dataOut) {
+ ArrayList parts = new ArrayList();
+ String requestData = "";
+ if (dataOut != null) {
+ Iterator iter1 = dataOut.getChildElements();
+
+ while (iter1.hasNext()) {
+ OMElement ele = (OMElement) iter1.next();
+ // check whether the element is a complex type
+ if (ele.getFirstElement() != null) {
+ requestData = "<" + ele.getQName().getLocalPart() + ">";
+ requestData = requestData + processComplexType(ele.getChildElements());
+ requestData = requestData + "</" + ele.getQName().getLocalPart() + ">";
+ parts.add(new ComplexPart(ele.getQName().getLocalPart(), requestData));
+ } else {
+ parts.add(new StringPart(ele.getQName().getLocalPart(), ele.getText()));
+ }
+ }
+ }
+ Part[] partsArray = new Part[parts.size()];
+ return (Part[]) parts.toArray(partsArray);
+ }
+
+ private String processComplexType(Iterator iter) {
+ String data = "";
+ while (iter.hasNext()) {
+ OMElement ele = (OMElement) iter.next();
+ data = data + "<" + ele.getQName().getLocalPart() + ">\n";
+ if (ele.getFirstElement() != null) {
+ data = data + processComplexType(ele.getChildElements());
+ } else {
+ data = data + "<" + ele.getQName().getLocalPart() + ">";
+ data = data + ele.getText();
+ data = data + "</" + ele.getQName().getLocalPart() + ">\n";
+ }
+ }
+ return data;
+ }
+
/*Obtain two strings;one to go in the url and rest to pass in the body
**when doing POST in application/x-www-form-urlencoded form.
*/
public RequestData createRequest(MessageContext msgContext, OMElement dataout) {
RequestData data = new RequestData();
- Iterator iter1 = dataout.getChildElements();
- ArrayList paraList = new ArrayList();
- ArrayList urlList = new ArrayList();
-
- // urlParameterList contains the parameters which go in the URL
- String[] urlParameterList = new String[0];
- if (msgContext.getProperty(Constants.Configuration.URL_PARAMETER_LIST) != null) {
- urlParameterList = (String[]) msgContext.getProperty(Constants.Configuration.URL_PARAMETER_LIST);
- }
- OMElement bodypara = OMAbstractFactory.getOMFactory().createOMElement("temp", null);
-
- while (iter1.hasNext()) {
- OMElement ele = (OMElement) iter1.next();
- boolean has = false;
+ if (dataout != null) {
+ Iterator iter1 = dataout.getChildElements();
+ ArrayList paraList = new ArrayList();
+ ArrayList urlList = new ArrayList();
+
+ // urlParameterList contains the parameters which go in the URL
+ String[] urlParameterList = new String[0];
+ if (msgContext.getProperty(Constants.Configuration.URL_PARAMETER_LIST) != null) {
+ urlParameterList = (String[]) msgContext
+ .getProperty(Constants.Configuration.URL_PARAMETER_LIST);
+ }
- for (int i = 0; i < urlParameterList.length; i++) {
- if (urlParameterList[i].equals(ele.getLocalName())) {
- has = true;
+ OMElement bodypara = OMAbstractFactory.getOMFactory().createOMElement("temp", null);
- break;
+ while (iter1.hasNext()) {
+ OMElement ele = (OMElement) iter1.next();
+ boolean parameterFound = false;
+
+ for (int i = 0; i < urlParameterList.length; i++) {
+ if (urlParameterList[i].equals(ele.getLocalName())) {
+ parameterFound = true;
+ break;
+ }
}
- }
- String parameter1;
+ String parameter;
- if (has) {
- parameter1 = ele.getLocalName() + "=" + ele.getText();
- urlList.add(parameter1);
- } else {
- bodypara.addChild(ele);
+ if (parameterFound) {
+ parameter = ele.getLocalName() + "=" + ele.getText();
+ urlList.add(parameter);
+ } else {
+ bodypara.addChild(ele);
+ }
}
- }
- String urlString = "";
- for (int i = 0; i < urlList.size(); i++) {
- String c = (String) urlList.get(i);
- urlString = "".equals(urlString) ? c : (urlString + "&" + c);
- data.urlRequest = urlString;
- }
+ Iterator it = bodypara.getChildElements();
- Iterator it = bodypara.getChildElements();
+ while (it.hasNext()) {
+ OMElement ele1 = (OMElement) it.next();
+ String parameter2;
- while (it.hasNext()) {
- OMElement ele1 = (OMElement) it.next();
- String parameter2;
+ parameter2 = ele1.getLocalName() + "=" + ele1.getText();
+ paraList.add(parameter2);
+ }
- parameter2 = ele1.getLocalName() + "=" + ele1.getText();
- paraList.add(parameter2);
- }
+ String paraString = "";
- String paraString = "";
+ for (int j = 0; j < paraList.size(); j++) {
+ String b = (String) paraList.get(j);
+ paraString = "".equals(paraString) ? b : (paraString + "&" + b);
+ data.bodyRequest = paraString;
+ }
- for (int j = 0; j < paraList.size(); j++) {
- String b = (String) paraList.get(j);
- paraString = "".equals(paraString) ? b : (paraString + "&" + b);
- data.bodyRequest = paraString;
+ if (dataout.getFirstOMChild() == null) {
+ dataout.detach();
+ }
}
return data;
@@ -120,53 +174,165 @@
* @param soapActionString
*/
public void send(MessageContext msgContext, OMElement dataout, URL url,
- String soapActionString) {
+ String soapActionString) throws AxisFault {
try {
String httpMethod =
(String) msgContext.getProperty(Constants.Configuration.HTTP_METHOD);
- if ((httpMethod != null)
- && Constants.Configuration.HTTP_METHOD_GET.equalsIgnoreCase(httpMethod)) {
- this.sendViaGet(msgContext, url);
-
- return;
+ if (httpMethod != null) {
+ if (Constants.Configuration.HTTP_METHOD_GET.equalsIgnoreCase(httpMethod)) {
+ this.sendViaGet(msgContext, url);
+ return;
+ } else if (Constants.Configuration.HTTP_METHOD_POST.equalsIgnoreCase(httpMethod)) {
+ this.sendViaPost(msgContext, dataout, url, soapActionString);
+ return;
+ } else
+ if (Constants.Configuration.HTTP_METHOD_DELETE.equalsIgnoreCase(httpMethod)) {
+ this.sendViaDelete(msgContext, url);
+ return;
+ } else if (Constants.Configuration.HTTP_METHOD_PUT.equalsIgnoreCase(httpMethod)) {
+ this.sendViaPut(msgContext, dataout, url, soapActionString);
+ return;
+ }
+ } else {
+ this.sendViaPost(msgContext, dataout, url, soapActionString);
}
-
- this.sendViaPost(msgContext, dataout, url, soapActionString);
- } catch (Exception e) {
+ } catch (MalformedURLException e) {
+ log.error("Error in extracting transport properties from message context", e);
+ throw new AxisFault("Error in extracting transport properties from message context");
+ } catch (IOException e) {
log.error("Error in extracting transport properties from message context", e);
+ throw new AxisFault("Error in extracting transport properties from message context");
+ }
+ }
+
+ private void sendViaDelete(MessageContext msgContext, URL url)
+ throws AxisFault, IOException {
+
+ DeleteMethod deleteMethod = new DeleteMethod();
+ if (isAuthenticationEnabled(msgContext)) {
+ deleteMethod.setDoAuthentication(true);
+ }
+ String urlString = url.toString();
+ int separator = urlString.indexOf('{');
+ if (separator > 0) {
+ String path = urlString.substring(0, separator - 1);
+ String query = urlString.substring(separator - 1);
+ String replacedQuery;
+ replacedQuery = applyURITemplating(msgContext, query, true);
+ url = new URL(path + replacedQuery);
+ }
+
+ deleteMethod.setPath(url.getPath());
+ String query = url.getQuery();
+ String ignoreUncited =
+ (String) msgContext.getProperty(WSDL2Constants.ATTR_WHTTP_IGNORE_UNCITED);
+ // If ignoreUncited property is true we can ignore the uncited parameters in the url, If it is not specified it
+ // defaults to false hence we append the additional query parameters.
+ if (ignoreUncited != null && JavaUtils.isTrueExplicitly(ignoreUncited)) {
+ deleteMethod.setQueryString(query);
+ } else {
+ deleteMethod.setQueryString(appendQueryParameters(msgContext, url.getQuery()));
+ }
+ // Serialization as "application/x-www-form-urlencoded"
+ String charEncoding =
+ (String) msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
+
+ String contentType = null;
+
+ // Default encoding scheme
+ if (charEncoding == null) {
+ contentType = HTTPConstants.MEDIA_TYPE_X_WWW_FORM + "; charset="
+ + MessageContext.DEFAULT_CHAR_SET_ENCODING;
+ } else {
+ contentType = HTTPConstants.MEDIA_TYPE_X_WWW_FORM + "; charset="
+ + charEncoding;
+ }
+
+ String action = msgContext.getOptions().getAction();
+
+ if (action != null) {
+ contentType = contentType + ";" + "action=" + action;
+ }
+
+ deleteMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE, contentType);
+
+ HttpClient httpClient = getHttpClient(msgContext);
+ executeMethod(httpClient, msgContext, url, deleteMethod);
+
+ if (deleteMethod.getStatusCode() == HttpStatus.SC_OK) {
+ processResponse(deleteMethod, msgContext);
+ } else if (deleteMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
+ } else if (deleteMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
+ Header contenttypeHheader =
+ deleteMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
+ String value = contenttypeHheader.getValue();
+
+ if (value != null) {
+ if ((value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0)
+ || (value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >= 0)) {
+ processResponse(deleteMethod, msgContext);
+ }
+ }
+ } else {
+ throw new AxisFault(Messages.getMessage("transportError",
+ String.valueOf(deleteMethod.getStatusCode()),
+ deleteMethod.getResponseBodyAsString()));
}
}
private void sendViaGet(MessageContext msgContext, URL url)
- throws MalformedURLException, AxisFault, IOException {
- String param = getParam(msgContext);
+ throws AxisFault, IOException {
+ String param = getQueryParameters(msgContext);
GetMethod getMethod = new GetMethod();
if (isAuthenticationEnabled(msgContext)) {
getMethod.setDoAuthentication(true);
}
- if (param != null && param.length() > 0) {
- getMethod.setPath(url.getFile() + "?" + param);
+ String urlString = url.toString();
+ int separator = urlString.indexOf('{');
+ if (separator > 0) {
+ String path = urlString.substring(0, separator - 1);
+ String query = urlString.substring(separator - 1);
+ String replacedQuery;
+ replacedQuery = applyURITemplating(msgContext, query, true);
+ url = new URL(path + replacedQuery);
+ }
+
+ getMethod.setPath(url.getPath());
+ String query = url.getQuery();
+ String ignoreUncited =
+ (String) msgContext.getProperty(WSDL2Constants.ATTR_WHTTP_IGNORE_UNCITED);
+ // If ignoreUncited property is true we can ignore the uncited parameters in the url, If it is not specified it
+ // defaults to false hence we append the additional query parameters.
+ if (ignoreUncited != null && JavaUtils.isTrueExplicitly(ignoreUncited)) {
+ getMethod.setQueryString(query);
} else {
- getMethod.setPath(url.getFile());
+ getMethod.setQueryString(appendQueryParameters(msgContext, url.getQuery()));
}
-
// Serialization as "application/x-www-form-urlencoded"
String charEncoding =
(String) msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
+ String contentType = null;
+
// Default encoding scheme
if (charEncoding == null) {
- getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
- HTTPConstants.MEDIA_TYPE_X_WWW_FORM + "; charset="
- + MessageContext.DEFAULT_CHAR_SET_ENCODING);
+ contentType = HTTPConstants.MEDIA_TYPE_X_WWW_FORM + "; charset="
+ + MessageContext.DEFAULT_CHAR_SET_ENCODING;
} else {
- getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
- HTTPConstants.MEDIA_TYPE_X_WWW_FORM + "; charset="
- + charEncoding);
+ contentType = HTTPConstants.MEDIA_TYPE_X_WWW_FORM + "; charset="
+ + charEncoding;
}
+ String action = msgContext.getOptions().getAction();
+
+ if (action != null) {
+ contentType = contentType + ";" + "action=" + action;
+ }
+
+ getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE, contentType);
+
HttpClient httpClient = getHttpClient(msgContext);
executeMethod(httpClient, msgContext, url, getMethod);
@@ -186,20 +352,20 @@
}
} else {
throw new AxisFault(Messages.getMessage("transportError",
- String.valueOf(getMethod.getStatusCode()),
- getMethod.getResponseBodyAsString()));
+ String.valueOf(getMethod.getStatusCode()),
+ getMethod.getResponseBodyAsString()));
}
}
private void sendViaPost(MessageContext msgContext, OMElement dataout, URL url,
- String soapActionString) {
+ String soapActionString) throws MalformedURLException, AxisFault {
// execute the HtttpMethodBase - a connection manager can be given for
// handle multiple
HttpClient httpClient = getHttpClient(msgContext);
PostMethod postMethod = new PostMethod(url.toString());
- if(isAuthenticationEnabled(msgContext)) {
+ if (isAuthenticationEnabled(msgContext)) {
postMethod.setDoAuthentication(true);
}
String httpContentType;
@@ -217,24 +383,41 @@
charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
+ String urlString = url.toString();
+ int separator = urlString.indexOf('{');
+ if (separator > 0) {
+ String path = urlString.substring(0, separator - 1);
+ String query = urlString.substring(separator - 1);
+ String replacedQuery;
+ if (httpContentType.equalsIgnoreCase(HTTPConstants.MEDIA_TYPE_X_WWW_FORM)) {
+ replacedQuery = applyURITemplating(msgContext, query, true);
+ } else {
+ replacedQuery = applyURITemplating(msgContext, query, false);
+ }
+ url = new URL(path + replacedQuery);
+ }
+
+ postMethod.setPath(url.getPath());
+ postMethod.setQueryString(url.getQuery());
+
// if POST as application/x-www-form-urlencoded
RequestData reqData;
if (httpContentType.equalsIgnoreCase(HTTPConstants.MEDIA_TYPE_X_WWW_FORM)) {
reqData = createRequest(msgContext, dataout);
- postMethod.setPath(url.getPath() + ((reqData.urlRequest) != null
- ? ("?" + reqData.urlRequest)
- : ""));
-
if (reqData.bodyRequest == null) {
reqData.bodyRequest = "0";
}
- postMethod.setRequestEntity(new RESTRequestEntity2(reqData.bodyRequest,httpContentType));
+ postMethod.setRequestEntity(
+ new AxisRESTRequestEntity(reqData.bodyRequest, httpContentType));
+ } else if (httpContentType.equalsIgnoreCase(HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA)) {
+ Part[] parts = createMultipatFormDataRequest(msgContext, dataout);
+ postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams()));
} else {
- postMethod.setPath(url.getPath());
- postMethod.setRequestEntity(new RESTRequestEntity(dataout, chunked, msgContext,
- charEncoding, soapActionString, format));
+ postMethod.setRequestEntity(new AxisRequestEntity(dataout, chunked, msgContext,
+ charEncoding, soapActionString,
+ httpContentType));
}
if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) {
@@ -247,14 +430,14 @@
if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) {
httpClient.getParams().setVersion(HttpVersion.HTTP_1_0);
postMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
- HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
+ HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
} else {
// allowing keep-alive for 1.1
postMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
- HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
+ HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
postMethod.setRequestHeader(HTTPConstants.HEADER_EXPECT,
- HTTPConstants.HEADER_EXPECT_100_Continue);
+ HTTPConstants.HEADER_EXPECT_100_Continue);
}
}
@@ -287,14 +470,137 @@
}
throw new AxisFault(Messages.getMessage("transportError",
- String.valueOf(postMethod.getStatusCode()),
- postMethod.getResponseBodyAsString()));
+ String.valueOf(postMethod.getStatusCode()),
+ postMethod.getResponseBodyAsString()));
} catch (Exception e) {
log.error("Error in processing POST request", e);
+ throw new AxisFault("Error in processing POST request");
}
}
- public String getParam(MessageContext msgContext) {
+
+ private void sendViaPut(MessageContext msgContext, OMElement dataout, URL url,
+ String soapActionString) throws MalformedURLException, AxisFault {
+
+ // execute the HtttpMethodBase - a connection manager can be given for
+ // handle multiple
+ HttpClient httpClient = getHttpClient(msgContext);
+
+ PutMethod putMethod = new PutMethod(url.toString());
+ if (isAuthenticationEnabled(msgContext)) {
+ putMethod.setDoAuthentication(true);
+ }
+ String httpContentType;
+
+ if (msgContext.getProperty(Constants.Configuration.CONTENT_TYPE) != null) {
+ httpContentType = (String) msgContext.getProperty(Constants.Configuration.CONTENT_TYPE);
+ } else {
+ httpContentType = HTTPConstants.MEDIA_TYPE_APPLICATION_XML;
+ }
+
+ String charEncoding =
+ (String) msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
+
+ if (charEncoding == null) {
+ charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
+ }
+
+ String urlString = url.toString();
+ int separator = urlString.indexOf('{');
+ if (separator > 0) {
+ String path = urlString.substring(0, separator - 1);
+ String query = urlString.substring(separator - 1);
+ String replacedQuery;
+ if (httpContentType.equalsIgnoreCase(HTTPConstants.MEDIA_TYPE_X_WWW_FORM)) {
+ replacedQuery = applyURITemplating(msgContext, query, true);
+ } else {
+ replacedQuery = applyURITemplating(msgContext, query, false);
+ }
+ url = new URL(path + replacedQuery);
+ }
+
+ putMethod.setPath(url.getPath());
+ putMethod.setQueryString(url.getQuery());
+
+ // if POST as application/x-www-form-urlencoded
+ RequestData reqData;
+
+ if (httpContentType.equalsIgnoreCase(HTTPConstants.MEDIA_TYPE_X_WWW_FORM)) {
+ reqData = createRequest(msgContext, dataout);
+ if (reqData.bodyRequest == null) {
+ reqData.bodyRequest = "0";
+ }
+ putMethod.setRequestEntity(
+ new AxisRESTRequestEntity(reqData.bodyRequest, httpContentType));
+
+ } else if (httpContentType.equalsIgnoreCase(HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA)) {
+ Part[] parts = createMultipatFormDataRequest(msgContext, dataout);
+ putMethod.setRequestEntity(new MultipartRequestEntity(parts, putMethod.getParams()));
+ } else {
+ putMethod.setRequestEntity(new AxisRequestEntity(dataout, chunked, msgContext,
+ charEncoding, soapActionString,
+ httpContentType));
+ }
+
+ if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) {
+ putMethod.setContentChunked(true);
+ }
+
+ putMethod.setRequestHeader(HTTPConstants.HEADER_HOST, url.getHost());
+
+ if (httpVersion != null) {
+ if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) {
+ httpClient.getParams().setVersion(HttpVersion.HTTP_1_0);
+ putMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
+ HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
+ } else {
+
+ // allowing keep-alive for 1.1
+ putMethod.setRequestHeader(HTTPConstants.HEADER_CONNECTION,
+ HTTPConstants.HEADER_CONNECTION_KEEPALIVE);
+ putMethod.setRequestHeader(HTTPConstants.HEADER_EXPECT,
+ HTTPConstants.HEADER_EXPECT_100_Continue);
+ }
+ }
+
+ /**
+ * main excecution takes place..
+ */
+ try {
+ executeMethod(httpClient, msgContext, url, putMethod);
+
+ if (putMethod.getStatusCode() == HttpStatus.SC_OK) {
+ processResponse(putMethod, msgContext);
+
+ return;
+ } else if (putMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
+ return;
+ } else if (putMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
+ Header contenttypeHheader =
+ putMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
+
+ if (contenttypeHheader != null) {
+ String value = contenttypeHheader.getValue();
+
+ if ((value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0)
+ || (value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >= 0)) {
+ processResponse(putMethod, msgContext);
+
+ return;
+ }
+ }
+ }
+
+ throw new AxisFault(Messages.getMessage("transportError",
+ String.valueOf(putMethod.getStatusCode()),
+ putMethod.getResponseBodyAsString()));
+ } catch (Exception e) {
+ log.error("Error in processing POST request", e);
+ throw new AxisFault("Error in processing POST request");
+ }
+ }
+
+ public String getQueryParameters(MessageContext msgContext) {
OMElement dataOut;
dataOut = msgContext.getEnvelope().getBody().getFirstElement();
@@ -321,8 +627,154 @@
return paraString;
}
+ public class AxisRequestEntity implements RequestEntity {
+ private boolean doingMTOM = false;
+ private byte[] bytes;
+ private String charSetEnc;
+ private boolean chunked;
+ private OMElement element;
+ private MessageContext msgCtxt;
+ private String soapActionString;
+ private String contentType;
+
+ public AxisRequestEntity(OMElement element, boolean chunked,
+ MessageContext msgCtxt,
+ String charSetEncoding,
+ String soapActionString,
+ String contentType) {
+ this.element = element;
+ this.chunked = chunked;
+ this.msgCtxt = msgCtxt;
+ this.doingMTOM = msgCtxt.isDoingMTOM();
+ this.charSetEnc = charSetEncoding;
+ this.soapActionString = soapActionString;
+ this.contentType = contentType;
+ }
+
+ private void handleOMOutput(OutputStream out, boolean doingMTOM)
+ throws XMLStreamException {
+ format.setDoOptimize(doingMTOM);
+ element.serializeAndConsume(out, format);
+ }
+
+ public byte[] writeBytes() throws AxisFault {
+ try {
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+
+ if (!doingMTOM) {
+ OMOutputFormat format2 = new OMOutputFormat();
+
+ format2.setCharSetEncoding(charSetEnc);
+ element.serializeAndConsume(bytesOut, format2);
+
+ return bytesOut.toByteArray();
+ } else {
+ format.setCharSetEncoding(charSetEnc);
+ format.setDoOptimize(true);
+ element.serializeAndConsume(bytesOut, format);
+
+ return bytesOut.toByteArray();
+ }
+ } catch (XMLStreamException e) {
+ throw new AxisFault(e);
+ } catch (FactoryConfigurationError e) {
+ throw new AxisFault(e);
+ }
+ }
+
+ public void writeRequest(OutputStream out) throws IOException {
+ try {
+ {
+ if (chunked) {
+ this.handleOMOutput(out, doingMTOM);
+ } else if (element != null) {
+ if (bytes == null) {
+ bytes = writeBytes();
+ }
+
+ out.write(bytes);
+ }
+ }
+
+ out.flush();
+ } catch (XMLStreamException e) {
+ throw new AxisFault(e);
+ } catch (FactoryConfigurationError e) {
+ throw new AxisFault(e);
+ } catch (IOException e) {
+ throw new AxisFault(e);
+ }
+ }
+
+ public long getContentLength() {
+ try {
+ {
+ if (chunked) {
+ return -1;
+ } else if (element != null) {
+ if (bytes == null) {
+ bytes = writeBytes();
+ }
+
+ return bytes.length;
+ }
+
+ return 0;
+ }
+ } catch (AxisFault e) {
+ return -1;
+ }
+ }
+
+ public String getContentType() {
+ String encoding = format.getCharSetEncoding();
+ if (encoding != null) {
+ contentType += "; charset=" + encoding;
+ }
+
+ // action header is not mandated in SOAP 1.2. So putting it, if available
+ if (!msgCtxt.isSOAP11() && (soapActionString != null)
+ && !"".equals(soapActionString.trim()) &&
+ !"\"\"".equals(soapActionString.trim())) {
+ contentType =
+ contentType + ";action=\"" + soapActionString + "\";";
+ }
+
+ return contentType;
+ }
+
+ public boolean isRepeatable() {
+ return true;
+ }
+ }
+
+ public class AxisRESTRequestEntity implements RequestEntity {
+ private String contentType;
+ private String postRequestBody;
+
+ public AxisRESTRequestEntity(String postRequestBody, String contentType) {
+ this.postRequestBody = postRequestBody;
+ this.contentType = contentType;
+ }
+
+ public void writeRequest(OutputStream output) throws IOException {
+ output.write(postRequestBody.getBytes());
+ }
+
+ public long getContentLength() {
+ return this.postRequestBody.getBytes().length;
+ }
+
+ public String getContentType() {
+ return this.contentType;
+ }
+
+ public boolean isRepeatable() {
+ return true;
+ }
+ }
+
private class RequestData {
private String bodyRequest;
- private String urlRequest;
}
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java?view=diff&rev=503585&r1=503584&r2=503585
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java Mon Feb 5 00:21:12 2007
@@ -16,10 +16,6 @@
package org.apache.axis2.transport.http;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-
import org.apache.axiom.om.OMElement;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
@@ -35,6 +31,10 @@
import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.httpclient.methods.PostMethod;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
public class SOAPOverHTTPSender extends AbstractHTTPSender {
@@ -44,10 +44,6 @@
// execute the HtttpMethodBase - a connection manager can be given for
// handle multiple
HttpClient httpClient = getHttpClient(msgContext);
- PostMethod postMethod = new PostMethod(url.toString());
- if (isAuthenticationEnabled(msgContext)) {
- postMethod.setDoAuthentication(true);
- }
String charEncoding =
(String) msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
@@ -56,22 +52,40 @@
charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
- MessageFormatter messageFormatter = TransportUtils.getMessageFormatter(
- msgContext);
- url = messageFormatter.getTargetAddress(msgContext,format,url);
- postMethod.setPath(url.getPath());
- postMethod.setRequestEntity(new AxisRequestEntity(messageFormatter,
- msgContext,format,soapActionString, chunked, isAllowedRetry));
-
- if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) {
- postMethod.setContentChunked(true);
- }
-
- String soapAction = messageFormatter.formatSOAPAction(msgContext,format,soapActionString);
- if (soapAction!=null) {
- postMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction);
- }
-
+ MessageFormatter messageFormatter = TransportUtils.getMessageFormatter(
+ msgContext);
+ url = messageFormatter.getTargetAddress(msgContext, format, url);
+ // Check whther the url has httpLocation
+ String urlString = url.toString();
+ int separator = urlString.indexOf('{');
+ if (separator > 0) {
+ String path = urlString.substring(0, separator - 1);
+ String query = urlString.substring(separator - 1);
+ String replacedQuery;
+ replacedQuery = applyURITemplating(msgContext, query, false);
+ url = new URL(path + replacedQuery);
+ }
+ PostMethod postMethod = new PostMethod();
+ postMethod.setPath(url.getPath());
+ postMethod.setQueryString(url.getQuery());
+ postMethod.setPath(url.getPath());
+
+ if (isAuthenticationEnabled(msgContext)) {
+ postMethod.setDoAuthentication(true);
+ }
+
+ postMethod.setRequestEntity(new AxisRequestEntity(messageFormatter,
+ msgContext, format, soapActionString,
+ chunked, isAllowedRetry));
+ if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) {
+ postMethod.setContentChunked(true);
+ }
+
+ String soapAction = messageFormatter.formatSOAPAction(msgContext, format, soapActionString);
+ if (soapAction != null) {
+ postMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction);
+ }
+
//setting the cookie in the out path
Object cookieString = msgContext.getProperty(HTTPConstants.COOKIE_STRING);
if (cookieString != null) {
@@ -89,14 +103,14 @@
httpClient.getParams().setVersion(HttpVersion.HTTP_1_0);
} else {
postMethod.setRequestHeader(HTTPConstants.HEADER_EXPECT,
- HTTPConstants.HEADER_EXPECT_100_Continue);
+ HTTPConstants.HEADER_EXPECT_100_Continue);
}
}
// set timeout in client
long timeout = msgContext.getOptions().getTimeOutInMilliSeconds();
if (timeout != 0) {
- httpClient.getParams().setSoTimeout((int)timeout);
+ httpClient.getParams().setSoTimeout((int) timeout);
}
/*
@@ -128,10 +142,13 @@
}
} else {
throw new AxisFault(Messages.getMessage("httpTransportError",
- String.valueOf(postMethod.getStatusCode()), postMethod.getStatusText()), SOAP12Constants.FAULT_CODE_SENDER);
+ String.valueOf(postMethod.getStatusCode()),
+ postMethod.getStatusText()),
+ SOAP12Constants.FAULT_CODE_SENDER);
}
throw new AxisFault(Messages.getMessage("transportError",
- String.valueOf(postMethod.getStatusCode()), postMethod.getResponseBodyAsString()));
+ String.valueOf(postMethod.getStatusCode()),
+ postMethod.getResponseBodyAsString()));
}
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ServletBasedOutTransportInfo.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ServletBasedOutTransportInfo.java?view=diff&rev=503585&r1=503584&r2=503585
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ServletBasedOutTransportInfo.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ServletBasedOutTransportInfo.java Mon Feb 5 00:21:12 2007
@@ -31,4 +31,8 @@
public void setContentType(String contentType) {
response.setContentType(contentType);
}
+
+ public void addHeader(String headerName, String headerValue) {
+ response.addHeader(headerName, headerValue);
+ }
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/HttpUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/HttpUtils.java?view=diff&rev=503585&r1=503584&r2=503585
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/HttpUtils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/server/HttpUtils.java Mon Feb 5 00:21:12 2007
@@ -37,7 +37,7 @@
import org.apache.http.HttpRequest;
public class HttpUtils {
-
+
private HttpUtils() {
}
@@ -90,5 +90,4 @@
private static boolean isIP(String hostAddress) {
return hostAddress.split("[.]").length == 4;
}
-
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java?view=diff&rev=503585&r1=503584&r2=503585
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java Mon Feb 5 00:21:12 2007
@@ -15,16 +15,10 @@
*/
package org.apache.axis2.transport.http.util;
-import java.io.IOException;
-
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.impl.OMNodeEx;
import org.apache.axiom.om.impl.builder.OMBuilder;
-import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.util.StAXUtils;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFactory;
@@ -32,17 +26,29 @@
import org.apache.axis2.Constants;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisBindingOperation;
+import org.apache.axis2.description.AxisEndpoint;
import org.apache.axis2.description.AxisMessage;
import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.WSDL2Constants;
import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.engine.HTTPLocationBasedDispatcher;
import org.apache.axis2.engine.RequestURIBasedDispatcher;
-import org.apache.axis2.engine.RequestURIOperationDispatcher ;
+import org.apache.axis2.engine.RequestURIOperationDispatcher;
+import org.apache.axis2.engine.SOAPActionBasedDispatcher;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.util.Builder;
import org.apache.axis2.util.SchemaUtil;
import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.ws.commons.schema.XmlSchemaElement;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.stream.XMLStreamReader;
+import java.io.IOException;
+
/**
*
*/
@@ -68,10 +74,12 @@
throw new AxisFault("ContentType should be given to proceed," +
" according to WSDL 2.0 HTTP binding rules");
} else if (contentType.indexOf(HTTPConstants.MEDIA_TYPE_TEXT_XML) > -1 ||
- contentType.indexOf(HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED) > -1) {
+ contentType.indexOf(HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED) > -1 ||
+ contentType.indexOf(HTTPConstants.MEDIA_TYPE_APPLICATION_XML) > -1) {
soapEnvelope = handleNonURLEncodedContentTypes(msgContext, request,
- OMAbstractFactory.getSOAP11Factory());
- } else if (contentType.indexOf(HTTPConstants.MEDIA_TYPE_X_WWW_FORM) > -1) {
+ OMAbstractFactory.getSOAP12Factory());
+ } else if (contentType.indexOf(HTTPConstants.MEDIA_TYPE_X_WWW_FORM) > -1 ||
+ contentType.indexOf(HTTPConstants.MEDIA_TYPE_MULTIPART_FORM_DATA) > -1) {
// 2. Else, Dispatch and find out the operation and the service.
// Dispatching can only be done using the RequestURI, as others can not be run in the REST case
dispatchAndVerify(msgContext);
@@ -86,17 +94,21 @@
soapEnvelope = SchemaUtil.handleMediaTypeURLEncoded(msgContext,
request,
xmlSchemaElement,
- OMAbstractFactory.getSOAP11Factory());
+ OMAbstractFactory.getSOAP12Factory());
} else {
- throw new AxisFault("Content type should be one of /n " + HTTPConstants.MEDIA_TYPE_TEXT_XML +
- "/n " + HTTPConstants.MEDIA_TYPE_X_WWW_FORM +
+ throw new AxisFault(
+ "Content type should be one of /n " + HTTPConstants.MEDIA_TYPE_TEXT_XML +
+ "/n " + HTTPConstants.MEDIA_TYPE_X_WWW_FORM +
+ "/n " + HTTPConstants.MEDIA_TYPE_APPLICATION_XML +
"/n " + HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED);
}
msgContext.setEnvelope(soapEnvelope);
- msgContext.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD, org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD_POST);
- msgContext.setProperty(org.apache.axis2.transport.http.HTTPConstants.CONTENT_TYPE, contentType);
+ msgContext.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD,
+ org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD_POST);
+ msgContext.setProperty(org.apache.axis2.transport.http.HTTPConstants.CONTENT_TYPE,
+ contentType);
msgContext.setDoingREST(true);
msgContext.setProperty(MessageContext.TRANSPORT_OUT, response.getOutputStream());
@@ -116,9 +128,37 @@
// here, only the parameters in the URI are supported. Others will be discarded.
try {
+ // when using the wsdl2 soap response MEP it can contain soap action. We better look for it here,
+ // if its there put it into msgContext so that we can use it later for dispatching purposes.
+
+ String contentType = request.getContentType();
+
+ if (contentType != null) {
+
+ //Check for action header and set it in as soapAction in MessageContext
+ int index = contentType.indexOf("action");
+ if (index > -1) {
+ String transientString = contentType.substring(index, contentType.length());
+ int equal = transientString.indexOf("=");
+ int firstSemiColon = transientString.indexOf(";");
+ String soapAction; // This will contain "" in the string
+ if (firstSemiColon > -1) {
+ soapAction = transientString.substring(equal + 1, firstSemiColon);
+ } else {
+ soapAction = transientString.substring(equal + 1, transientString.length());
+ }
+ if ((soapAction != null) && soapAction.startsWith("\"")
+ && soapAction.endsWith("\"")) {
+ soapAction = soapAction
+ .substring(1, soapAction.length() - 1);
+ }
+ msgContext.setSoapAction(soapAction);
+
+ }
+ }
+
// set the required properties so that even if there is an error during the dispatch
// phase the response message will be passed to the client well.
- msgContext.setProperty(org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD, org.apache.axis2.transport.http.HTTPConstants.HTTP_METHOD_GET);
msgContext.setDoingREST(true);
msgContext.setProperty(MessageContext.TRANSPORT_OUT, response.getOutputStream());
@@ -131,14 +171,15 @@
XmlSchemaElement xmlSchemaElement = null;
if (axisOperation != null) {
- AxisMessage axisMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
+ AxisMessage axisMessage =
+ axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
xmlSchemaElement = axisMessage.getSchemaElement();
}
SOAPEnvelope soapEnvelope = SchemaUtil.handleMediaTypeURLEncoded(msgContext,
request,
xmlSchemaElement,
- OMAbstractFactory.getSOAP11Factory());
+ OMAbstractFactory.getSOAP12Factory());
msgContext.setEnvelope(soapEnvelope);
invokeAxisEngine(msgContext);
@@ -161,14 +202,39 @@
private void dispatchAndVerify(MessageContext msgContext) throws AxisFault {
RequestURIBasedDispatcher requestDispatcher = new RequestURIBasedDispatcher();
requestDispatcher.invoke(msgContext);
+ AxisService axisService = msgContext.getAxisService();
+ if (axisService != null) {
+ RequestURIOperationDispatcher requestURIOperationDispatcher =
+ new RequestURIOperationDispatcher();
+ requestURIOperationDispatcher.invoke(msgContext);
+
+ if (msgContext.getAxisOperation() == null) {
+ HTTPLocationBasedDispatcher httpLocationBasedDispatcher =
+ new HTTPLocationBasedDispatcher();
+ httpLocationBasedDispatcher.invoke(msgContext);
+ }
- RequestURIOperationDispatcher opDispatcher = new RequestURIOperationDispatcher();
- opDispatcher.invoke(msgContext);
-
-
+ if (msgContext.getAxisOperation() == null) {
+ SOAPActionBasedDispatcher soapActionBasedDispatcher =
+ new SOAPActionBasedDispatcher();
+ soapActionBasedDispatcher.invoke(msgContext);
+ }
+ AxisOperation axisOperation;
+ if ((axisOperation = msgContext.getAxisOperation()) != null) {
+ AxisEndpoint axisEndpoint =
+ (AxisEndpoint) msgContext.getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME);
+ AxisBindingOperation axisBindingOperation = (AxisBindingOperation) axisEndpoint
+ .getBinding().getChild(axisOperation.getName());
+ msgContext.setProperty(Constants.AXIS_BINDING_OPERATION, axisBindingOperation);
+ msgContext.setAxisOperation(axisOperation);
+ }
- // check for the dispatching result
- if (msgContext.getAxisService() == null || msgContext.getAxisOperation() == null) {
+ // check for the dispatching result
+ if (msgContext.getAxisOperation() == null) {
+ throw new AxisFault("I can not find a service for this request to be serviced." +
+ " Check the WSDL and the request URI");
+ }
+ } else {
throw new AxisFault("I can not find a service for this request to be serviced." +
" Check the WSDL and the request URI");
}
@@ -188,28 +254,39 @@
// irrespective of the schema, if the media type is text/xml, all the information
// should be in the body.
// I'm assuming here that the user is sending this data according to the schema.
- if (checkContentType(org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED, contentType)) {
+ if (checkContentType(
+ org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_MULTIPART_RELATED,
+ contentType)) {
body.addChild(Builder.getAttachmentsBuilder(msgCtxt,
- inputStream,
- contentType, false).getDocumentElement());
- }else if (checkContentType(org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_TEXT_XML, contentType)) {
-
- String charSetEnc;
- if (Builder.getCharSetEncoding(contentType) == null) {
+ inputStream,
+ contentType,
+ false).getDocumentElement());
+ } else if (checkContentType(
+ org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_TEXT_XML,
+ contentType) ||
+ checkContentType(
+ org.apache.axis2.transport.http.HTTPConstants.MEDIA_TYPE_APPLICATION_XML,
+ contentType)) {
+
+ String charSetEnc = Builder.getCharSetEncoding(contentType);
+ XMLStreamReader xmlreader;
+ if (charSetEnc == null) {
// If charset is not specified
charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
- } else {
- // get the type of char encoding
- charSetEnc = Builder.getCharSetEncoding(contentType);
}
// Setting the value in msgCtx
msgCtxt.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
- OMBuilder builder = Builder.getBuilder(inputStream, charSetEnc, null);
- OMNodeEx documentElement = (OMNodeEx) builder.getDocumentElement();
- documentElement.setParent(null);
- body.addChild(documentElement);
- }
+ // Create documentElement only if the content length is greator than 0
+ if (request.getContentLength() != 0) {
+ xmlreader = StAXUtils.createXMLStreamReader(inputStream,
+ charSetEnc);
+ OMBuilder builder = Builder.getBuilder(inputStream, charSetEnc, null);
+ OMNodeEx documentElement = (OMNodeEx) builder.getDocumentElement();
+ documentElement.setParent(null);
+ body.addChild(documentElement);
+ }
+ }
return soapEnvelope;
@@ -227,4 +304,18 @@
}
return contentTypeStringFromRequest.indexOf(contentType) > -1;
}
+
+ public static String getConstantFromHTTPLocation(String httpLocation) {
+ if (httpLocation.charAt(0) != '?') {
+ httpLocation = "/" + httpLocation;
+ }
+ int index = httpLocation.indexOf("{");
+ if (index > -1) {
+ httpLocation = httpLocation.substring(0, index);
+ }
+ return httpLocation;
+ }
+
}
+
+
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java?view=diff&rev=503585&r1=503584&r2=503585
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java Mon Feb 5 00:21:12 2007
@@ -16,18 +16,13 @@
package org.apache.axis2.util;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Map;
-
-import javax.xml.namespace.QName;
-
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.util.UUIDGenerator;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPConstants;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axiom.soap.SOAPFault;
import org.apache.axiom.soap.SOAPFaultCode;
@@ -35,14 +30,16 @@
import org.apache.axiom.soap.SOAPFaultNode;
import org.apache.axiom.soap.SOAPFaultReason;
import org.apache.axiom.soap.SOAPFaultRole;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axiom.soap.SOAPProcessingException;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.AddressingConstants.Final;
import org.apache.axis2.addressing.AddressingHelper;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.addressing.RelatesTo;
-import org.apache.axis2.addressing.AddressingConstants.Final;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.OperationContext;
@@ -51,11 +48,20 @@
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.description.WSDL2Constants;
import org.apache.axis2.i18n.Messages;
+import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.wsdl.WSDLConstants;
+import javax.xml.namespace.QName;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
public class MessageContextBuilder {
-
+
/**
* Creates a new 'response' message context based on a 'request' message context
* Only deals with properties/fields that are the same for both 'normal' and fault responses.
@@ -70,12 +76,16 @@
newmsgCtx.setMessageID(UUIDGenerator.getUUID());
newmsgCtx.setServerSide(inMessageContext.isServerSide());
newmsgCtx.addRelatesTo(new RelatesTo(inMessageContext.getOptions().getMessageId()));
-
+
newmsgCtx.setProperty(AddressingConstants.WS_ADDRESSING_VERSION,
inMessageContext.getProperty(AddressingConstants.WS_ADDRESSING_VERSION));
newmsgCtx.setProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES,
inMessageContext.getProperty(AddressingConstants.DISABLE_ADDRESSING_FOR_OUT_MESSAGES));
+ newmsgCtx.setProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME,
+ inMessageContext.getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME));
+ newmsgCtx.setProperty(Constants.AXIS_BINDING_OPERATION,inMessageContext.getProperty(Constants.AXIS_BINDING_OPERATION));
+
// Setting the charater set encoding
newmsgCtx.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
inMessageContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING));
@@ -85,28 +95,28 @@
newmsgCtx.setDoingREST(inMessageContext.isDoingREST());
newmsgCtx.setOperationContext(inMessageContext.getOperationContext());
-
+
ServiceContext serviceContext = inMessageContext.getServiceContext();
if (serviceContext != null) {
newmsgCtx.setServiceContext(serviceContext);
}
-
+
newmsgCtx.setProperty(MessageContext.TRANSPORT_OUT,
inMessageContext.getProperty(MessageContext.TRANSPORT_OUT));
newmsgCtx.setProperty(Constants.OUT_TRANSPORT_INFO,
inMessageContext.getProperty(Constants.OUT_TRANSPORT_INFO));
-
+
return newmsgCtx;
}
-
+
/**
* Creates a MessageContext for use with a non-fault response based on an request MessageContext
*/
public static MessageContext createOutMessageContext(MessageContext inMessageContext) throws AxisFault {
-
+
// Create a basic response MessageContext with basic fields copied
- MessageContext newmsgCtx = createResponseMessageContext(inMessageContext);
-
+ MessageContext newmsgCtx = createResponseMessageContext(inMessageContext);
+
// Simple response so set To to value of inbound ReplyTo
newmsgCtx.setTo(inMessageContext.getReplyTo());
if(newmsgCtx.getTo() == null){
@@ -137,18 +147,18 @@
Constants.SERVICE_GROUP_ID, Constants.AXIS2_NAMESPACE_PREFIX), serviceGroupContextId);
}
} else {
- newmsgCtx.setReplyTo(new EndpointReference(AddressingConstants.Final.WSA_NONE_URI));
+ newmsgCtx.setReplyTo(new EndpointReference(AddressingConstants.Final.WSA_NONE_URI));
}
-
+
// Set wsa:Action for response message
// Use specified value if available
AxisOperation ao = inMessageContext.getAxisOperation();
- if ((ao!=null) && (ao.getOutputAction() != null)) {
+ if ((ao != null) && (ao.getOutputAction() != null)) {
newmsgCtx.setWSAAction(ao.getOutputAction());
} else { // If not, simply copy the request value. Almost always invalid.
newmsgCtx.setWSAAction(inMessageContext.getWSAAction());
}
-
+
newmsgCtx.setAxisMessage(ao.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE));
newmsgCtx.setDoingMTOM(inMessageContext.isDoingMTOM());
@@ -156,7 +166,7 @@
// Ensure transport settings match the scheme for the To EPR
setupCorrectTransportOut(newmsgCtx);
-
+
return newmsgCtx;
}
@@ -197,26 +207,32 @@
// Create a basic response MessageContext with basic fields copied
MessageContext faultContext = createResponseMessageContext(processingContext);
-
+
+ String contentType = (String)processingContext.getProperty(Constants.Configuration.CONTENT_TYPE_OF_FAULT);
+ if (contentType != null) {
+ faultContext.setProperty(Constants.Configuration.CONTENT_TYPE,contentType);
+ }
+
// Register the fault message context
- if (processingContext.getAxisOperation() != null && processingContext.getOperationContext() != null) {
+ if (processingContext.getAxisOperation() != null && processingContext.getOperationContext() != null)
+ {
processingContext.getAxisOperation().addFaultMessageContext(faultContext, processingContext.getOperationContext());
}
faultContext.setProcessingFault(true);
-
+
// Not worth setting up the session information on a fault flow
faultContext.setReplyTo(new EndpointReference(AddressingConstants.Final.WSA_NONE_URI));
// Set wsa:Action for response message
// Use specified value if available
AxisOperation op = processingContext.getAxisOperation();
- if(op != null && op.getFaultAction()!=null){
+ if (op != null && op.getFaultAction() != null) {
faultContext.setWSAAction(op.getFaultAction());
- }else{ //If, for some reason there is no value set, should use a sensible action.
+ } else { //If, for some reason there is no value set, should use a sensible action.
faultContext.setWSAAction(Final.WSA_SOAP_FAULT_ACTION);
}
-
+
// there are some information that the fault thrower wants to pass to the fault path.
// Means that the fault is a ws-addressing one hence use the ws-addressing fault action.
Object faultInfoForHeaders = processingContext.getProperty(Constants.FAULT_INFORMATION_FOR_HEADERS);
@@ -250,14 +266,27 @@
SOAPEnvelope envelope = createFaultEnvelope(processingContext, e);
faultContext.setEnvelope(envelope);
+ //get the SOAP headers, user is trying to send in the fault
+ List soapHeadersList = (List) processingContext.getProperty(SOAPConstants.HEADER_LOCAL_NAME);
+ if (soapHeadersList != null) {
+ SOAPHeader soapHeaderElement = envelope.getHeader();
+ for (int i = 0; i < soapHeadersList.size(); i++) {
+ OMElement soapHeaderBlock = (OMElement) soapHeadersList.get(i);
+ soapHeaderElement.addChild(soapHeaderBlock);
+ }
+ }
+
+ // now add HTTP Headers
+ faultContext.setProperty(HTTPConstants.HTTP_HEADERS, processingContext.getProperty(HTTPConstants.HTTP_HEADERS));
+
return faultContext;
}
-
+
/**
* Ensure that if the scheme of the To EPR for the response is different than the
* transport used for the request that the correct TransportOut is available
*/
- private static void setupCorrectTransportOut(MessageContext context) throws AxisFault{
+ private static void setupCorrectTransportOut(MessageContext context) throws AxisFault {
// Determine that we have the correct transport available.
TransportOutDescription transportOut = context.getTransportOut();
@@ -286,7 +315,7 @@
throw new AxisFault(urise);
}
}
-
+
/**
* Information to create the SOAPFault can be extracted from different places.
* 1. Those information may have been put in to the message context by some handler. When someone
@@ -316,7 +345,6 @@
* -- EC
*
* @param context
- * @param fault
* @param e
*/
private static SOAPEnvelope createFaultEnvelope(MessageContext context, Throwable e) {
@@ -329,7 +357,7 @@
envelope = OMAbstractFactory.getSOAP12Factory().getDefaultFaultEnvelope();
}
SOAPFault fault = envelope.getBody().getFault();
-
+
SOAPProcessingException soapException = null;
AxisFault axisFault = null;
@@ -341,6 +369,14 @@
}
}
+ if (axisFault != null) {
+ Iterator iter = axisFault.headerIterator();
+ while (iter.hasNext()) {
+ SOAPHeaderBlock header = (SOAPHeaderBlock)iter.next();
+ envelope.getHeader().addChild(header);
+ }
+ }
+
if (e instanceof SOAPProcessingException) {
soapException = (SOAPProcessingException) e;
} else if (axisFault != null) {
@@ -365,7 +401,8 @@
} else if (axisFault != null) {
Map faultElementsMap = axisFault.getFaultElements();
- if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME) != null) {
+ if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME) != null)
+ {
fault.setCode((SOAPFaultCode) faultElementsMap.get(SOAP12Constants.SOAP_FAULT_CODE_LOCAL_NAME));
} else {
QName faultCodeQName = axisFault.getFaultCode();
@@ -402,7 +439,8 @@
message = soapException.getMessage();
} else if (axisFault != null) {
Map faultElementsMap = axisFault.getFaultElements();
- if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME) != null) {
+ if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME) != null)
+ {
fault.setReason((SOAPFaultReason) faultElementsMap.get(SOAP12Constants.SOAP_FAULT_REASON_LOCAL_NAME));
} else {
message = axisFault.getReason();
@@ -427,7 +465,8 @@
fault.getRole().setText((String) faultRole);
} else if (axisFault != null) {
Map faultElementsMap = axisFault.getFaultElements();
- if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME) != null) {
+ if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME) != null)
+ {
fault.setRole((SOAPFaultRole) faultElementsMap.get(SOAP12Constants.SOAP_FAULT_ROLE_LOCAL_NAME));
}
}
@@ -437,7 +476,8 @@
fault.getNode().setText((String) faultNode);
} else if (axisFault != null) {
Map faultElementsMap = axisFault.getFaultElements();
- if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME) != null) {
+ if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME) != null)
+ {
fault.setNode((SOAPFaultNode) faultElementsMap.get(SOAP12Constants.SOAP_FAULT_NODE_LOCAL_NAME));
}
}
@@ -447,12 +487,12 @@
boolean sendStacktraceDetailsWithFaults = false;
OperationContext oc = context.getOperationContext();
Object flagFromContext = null;
- if(oc!=null){
+ if (oc != null) {
flagFromContext = context.getOperationContext().getProperty(Constants.Configuration.SEND_STACKTRACE_DETAILS_WITH_FAULTS);
}
- if(flagFromContext!=null){
+ if (flagFromContext != null) {
sendStacktraceDetailsWithFaults = JavaUtils.isTrue(flagFromContext);
- }else{
+ } else {
Parameter param = context.getParameter(Constants.Configuration.SEND_STACKTRACE_DETAILS_WITH_FAULTS);
if(param != null) {
sendStacktraceDetailsWithFaults = JavaUtils.isTrue(param.getValue());
@@ -464,7 +504,8 @@
fault.setDetail((SOAPFaultDetail) faultDetail);
} else if (axisFault != null) {
Map faultElementsMap = axisFault.getFaultElements();
- if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME) != null) {
+ if (faultElementsMap != null && faultElementsMap.get(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME) != null)
+ {
fault.setDetail((SOAPFaultDetail) faultElementsMap.get(SOAP12Constants.SOAP_FAULT_DETAIL_LOCAL_NAME));
} else {
OMElement detail = axisFault.getDetail();
@@ -484,7 +525,7 @@
return envelope;
}
-
+
/**
* By the time the exception comes here it can be wrapped by so many levels. This will crip down
* to the root cause and get the initial error depending on the property
@@ -502,7 +543,7 @@
}
return throwable.getMessage();
}
-
+
private static String getSenderFaultCode(OMNamespace soapNamespace) {
return SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(soapNamespace.getNamespaceURI())
? SOAP12Constants.SOAP_DEFAULT_NAMESPACE_PREFIX + ":"
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org