You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ke...@apache.org on 2007/02/15 09:48:33 UTC
svn commit: r507855 - in /webservices/axis2/trunk/java/modules/kernel: conf/
src/org/apache/axis2/deployment/ src/org/apache/axis2/engine/
src/org/apache/axis2/transport/ src/org/apache/axis2/transport/http/
src/org/apache/axis2/transport/http/util/ te...
Author: keithc
Date: Thu Feb 15 00:48:32 2007
New Revision: 507855
URL: http://svn.apache.org/viewvc?view=rev&rev=507855
Log:
Adding formatters for rest and removing RESTSender as explained in AXIS2-2184
Added:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/XFormURLEncodedFormatter.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/URLTemplatingUtil.java
Removed:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/http/RestSenderTest.java
Modified:
webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/HTTPLocationBasedDispatcher.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPSender.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/RESTUtil.java
Modified: webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml?view=diff&rev=507855&r1=507854&r2=507855
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml (original)
+++ webservices/axis2/trunk/java/modules/kernel/conf/axis2.xml Thu Feb 15 00:48:32 2007
@@ -93,6 +93,23 @@
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.receivers.RawXMLINOutMessageReceiver"/>
</messageReceivers>
+
+ <!-- ================================================= -->
+ <!-- Message Formatter -->
+ <!-- ================================================= -->
+ <!--Following content type to message formatter mapping can be used to implement support for different message -->
+ <!--format serialization in Axis2. These message formats are expected to be resolved based on the content type. -->
+ <messageFormatters>
+ <messageFormatter contentType="application/x-www-form-urlencoded"
+ class="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/>
+ <messageFormatter contentType="application/xml"
+ class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
+ <messageFormatter contentType="text/xml"
+ class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
+ <messageFormatter contentType="application/echo+xml"
+ class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
+ </messageFormatters>
+
<!-- ================================================= -->
<!-- Transport Ins -->
<!-- ================================================= -->
@@ -173,11 +190,11 @@
<transportSender name="http"
class="org.apache.axis2.transport.http.CommonsHTTPTransportSender">
<parameter name="PROTOCOL" locked="false">HTTP/1.1</parameter>
- <parameter name="Transfer-Encoding" locked="false">chunked</parameter>
-
- <!-- If following is set to 'true', optional action part of the Content-Type will not be added to the SOAP 1.2 messages -->
+ <parameter name="Transfer-Encoding" locked="false">chunked</parameter>
+
+ <!-- If following is set to 'true', optional action part of the Content-Type will not be added to the SOAP 1.2 messages -->
<!-- <parameter name="OmitSOAP12Action" locked="false">true</parameter> -->
- </transportSender>
+ </transportSender>
<transportSender name="https"
class="org.apache.axis2.transport.http.CommonsHTTPTransportSender">
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml?view=diff&rev=507855&r1=507854&r2=507855
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/deployment/axis2_default.xml Thu Feb 15 00:48:32 2007
@@ -54,6 +54,22 @@
</messageReceivers>
<!-- ================================================= -->
+ <!-- Message Formatter -->
+ <!-- ================================================= -->
+ <!--Following content type to message formatter mapping can be used to implement support for different message -->
+ <!--format serialization in Axis2. These message formats are expected to be resolved based on the content type. -->
+ <messageFormatters>
+ <messageFormatter contentType="application/x-www-form-urlencoded"
+ class="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/>
+ <messageFormatter contentType="application/xml"
+ class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
+ <messageFormatter contentType="text/xml"
+ class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
+ <messageFormatter contentType="application/echo+xml"
+ class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
+ </messageFormatters>
+
+ <!-- ================================================= -->
<!-- Target Resolvers -->
<!-- ================================================= -->
<!-- Uncomment the following and specify the class name for your TargetResolver to add -->
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/HTTPLocationBasedDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/HTTPLocationBasedDispatcher.java?view=diff&rev=507855&r1=507854&r2=507855
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/HTTPLocationBasedDispatcher.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/engine/HTTPLocationBasedDispatcher.java Thu Feb 15 00:48:32 2007
@@ -66,8 +66,8 @@
String httpLocation = parseRequestURL(uri);
if (httpLocation != null) {
- AxisEndpoint axisEndpoint = axisService.getEndpoint((String) messageContext
- .getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME));
+ AxisEndpoint axisEndpoint = (AxisEndpoint) messageContext
+ .getProperty(WSDL2Constants.ENDPOINT_LOCAL_NAME);
if (axisEndpoint != null) {
Map httpLocationTable = (Map) axisEndpoint.getBinding()
.getProperty(WSDL2Constants.HTTP_LOCATION_TABLE);
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java?view=diff&rev=507855&r1=507854&r2=507855
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/TransportUtils.java Thu Feb 15 00:48:32 2007
@@ -40,6 +40,7 @@
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.SOAPMessageFormatter;
+import org.apache.axis2.transport.http.ApplicationXMLFormatter;
import org.apache.axis2.util.Builder;
import org.apache.axis2.util.JavaUtils;
import org.apache.commons.logging.Log;
@@ -266,12 +267,18 @@
.getAxisConfiguration().getMessageFormatter(messageFormatString);
}
- if (messageFormatter == null) {
- // Lets default to SOAP formatter
- //TODO need to improve this to use the stateless nature
- messageFormatter = new SOAPMessageFormatter();
- }
- return messageFormatter;
+ if (messageFormatter == null) {
+
+ // If we are doing rest better default to Application/xml formatter
+ if (msgContext.isDoingREST()) {
+ messageFormatter = new ApplicationXMLFormatter();
+ } else {
+ // Lets default to SOAP formatter
+ //TODO need to improve this to use the stateless nature
+ messageFormatter = new SOAPMessageFormatter();
+ }
+ }
+ return messageFormatter;
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java?view=diff&rev=507855&r1=507854&r2=507855
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AbstractHTTPSender.java Thu Feb 15 00:48:32 2007
@@ -292,9 +292,7 @@
}
}
- public abstract void send(MessageContext msgContext, OMElement dataout,
- URL url,
- String soapActionString)
+ public abstract void send(MessageContext msgContext, URL url, String soapActionString)
throws AxisFault, IOException;
/**
@@ -596,85 +594,5 @@
}
return userAgentString;
- }
-
- protected String applyURITemplating(MessageContext messageContext, String query,
- boolean detach) throws AxisFault {
-
- OMElement firstElement;
- if (detach) {
- firstElement = messageContext.getEnvelope().getBody().getFirstElement();
- } else {
- firstElement =
- messageContext.getEnvelope().getBody().getFirstElement().cloneOMElement();
- }
-
-
- HTTPLocation httpLocation = new HTTPLocation(query);
-
- String[] localNames = httpLocation.getLocalNames();
- String[] values = new String[localNames.length];
- int i;
- for (i = 0; i < localNames.length; i++) {
- String localName = localNames[i];
-
- try {
- values[i] = URLEncoder.encode(getOMElementValue(localName, firstElement), "UTF-8");
- } catch (UnsupportedEncodingException e) {
- log.error("Unable to encode Query String");
- throw new AxisFault("Unable to encode Query String");
- }
- }
-
-
- httpLocation.substitute(values);
-
- return httpLocation.toString();
- }
-
- protected String appendQueryParameters(MessageContext messageContext, String query) {
-
-
- OMElement firstElement;
- String queryParameterSeparator = (String) messageContext
- .getProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
- // In case queryParameterSeparator is null we better use the default value
- if (queryParameterSeparator == null) {
- queryParameterSeparator = WSDL20DefaultValueHolder
- .getDefaultValue(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
- }
- firstElement = messageContext.getEnvelope().getBody().getFirstElement();
- ArrayList values = new ArrayList();
- if (firstElement != null) {
- Iterator iter = firstElement.getChildElements();
- while (iter.hasNext()) {
- OMElement element = (OMElement) iter.next();
- values.add(element.getLocalName() + "=" + element.getText());
- }
- }
- if (values.size() > 0) {
- if (query == null) {
-
- query = (String) values.get(0);
- }
-
- for (int i = 1; i < values.size(); i++) {
- query = query + queryParameterSeparator + values.get(i);
- }
- }
- return query;
- }
-
- private String getOMElementValue(String elementName, OMElement parentElement) {
- OMElement httpURLParam = parentElement.getFirstChildWithName(new QName(elementName));
-
- if (httpURLParam != null) {
- httpURLParam.detach();
- if (parentElement.getFirstOMChild() == null) {
- parentElement.detach();
- }
- }
- return httpURLParam.getText();
-
}
}
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java?view=auto&rev=507855
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java Thu Feb 15 00:48:32 2007
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.transport.http;
+
+import org.apache.axis2.transport.MessageFormatter;
+import org.apache.axis2.transport.http.util.URLTemplatingUtil;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPFault;
+import org.apache.axiom.soap.SOAPFaultDetail;
+
+import javax.xml.stream.XMLStreamException;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+import java.net.URL;
+
+/**
+ * Formates the request message as application/xml
+ */
+public class ApplicationXMLFormatter implements MessageFormatter {
+
+ public byte[] getBytes(MessageContext messageContext, OMOutputFormat format) throws AxisFault {
+
+ OMElement omElement;
+
+ if (messageContext.getFLOW() == MessageContext.OUT_FAULT_FLOW) {
+ SOAPFault fault = messageContext.getEnvelope().getBody().getFault();
+ SOAPFaultDetail soapFaultDetail = fault.getDetail();
+ omElement = soapFaultDetail.getFirstElement();
+
+ if (omElement == null) {
+ omElement = fault.getReason();
+ }
+
+ } else {
+ omElement = messageContext.getEnvelope().getBody().getFirstElement();
+ }
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+
+ if (omElement != null) {
+
+ try {
+ omElement.serializeAndConsume(bytesOut, format);
+ } catch (XMLStreamException e) {
+ throw new AxisFault(e);
+ }
+
+ return bytesOut.toByteArray();
+ }
+
+ return new byte[0];
+ }
+
+ public void writeTo(MessageContext messageContext, OMOutputFormat format,
+ OutputStream outputStream, boolean preserve) throws AxisFault {
+
+ try {
+ byte[] b = getBytes(messageContext, format);
+
+ if (b != null && b.length > 0) {
+ outputStream.write(b);
+ } else {
+ outputStream.flush();
+ }
+ } catch (IOException e) {
+ throw new AxisFault("An error occured while writing the request");
+ }
+ }
+
+ public String getContentType(MessageContext messageContext, OMOutputFormat format,
+ String soapAction) {
+
+ String encoding = format.getCharSetEncoding();
+ String contentType;
+ contentType = (String) messageContext.getProperty(Constants.Configuration.CONTENT_TYPE);
+
+ if (contentType == null) {
+ contentType = HTTPConstants.MEDIA_TYPE_APPLICATION_XML;
+ }
+
+ if (encoding != null) {
+ contentType += "; charset=" + encoding;
+ }
+
+ // if soap action is there (can be there is soap response MEP is used) add it.
+ if ((soapAction != null)
+ && !"".equals(soapAction.trim())
+ && !"\"\"".equals(soapAction.trim())) {
+ contentType = contentType + ";action=\"" + soapAction + "\";";
+ }
+
+ return contentType;
+ }
+
+ public URL getTargetAddress(MessageContext messageContext, OMOutputFormat format, URL targetURL)
+ throws AxisFault {
+
+ // Check whether there is a template in the URL, if so we have to replace then with data
+ // values and create a new target URL.
+ targetURL = URLTemplatingUtil.getTemplatedURL(targetURL, messageContext, false);
+
+ return targetURL;
+ }
+
+ public String formatSOAPAction(MessageContext messageContext, OMOutputFormat format,
+ String soapAction) {
+ return soapAction;
+ }
+}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java?view=diff&rev=507855&r1=507854&r2=507855
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java Thu Feb 15 00:48:32 2007
@@ -242,7 +242,8 @@
if (!disableREST && isRESTRequest(contentType)) {
msgContext = createMessageContext(req, res);
try {
-
+ msgContext.setProperty(MessageContext.TRANSPORT_HEADERS,
+ getTransportHeaders(req));
new RESTUtil(configContext).processPostRequest(msgContext,
req,
res);
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java?view=diff&rev=507855&r1=507854&r2=507855
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java Thu Feb 15 00:48:32 2007
@@ -200,34 +200,14 @@
// Change this place to change the wsa:toepr
// epr = something
// ######################################################
- OMElement dataOut;
-
- /**
- * Figuringout the REST properties/parameters
- */
- if (msgContext.isDoingREST()) {
- if (msgContext.getFLOW() == MessageContext.OUT_FAULT_FLOW) {
- SOAPFault fault = msgContext.getEnvelope().getBody().getFault();
- SOAPFaultDetail soapFaultDetail = fault.getDetail();
- dataOut = soapFaultDetail.getFirstElement();
- if (dataOut == null) {
- dataOut = fault.getReason();
- }
-
- } else {
- dataOut = msgContext.getEnvelope().getBody().getFirstElement();
- }
- } else {
- dataOut = msgContext.getEnvelope();
- }
if (epr != null) {
if (!epr.hasNoneAddress()) {
- writeMessageWithCommons(msgContext, epr, dataOut, format);
+ writeMessageWithCommons(msgContext, epr, format);
}
} else {
if (msgContext.getProperty(MessageContext.TRANSPORT_OUT) != null) {
- sendUsingOutputStream(msgContext, format, dataOut);
+ sendUsingOutputStream(msgContext, format);
} else {
throw new AxisFault(
"Both the TO and MessageContext.TRANSPORT_OUT property are Null, No where to send");
@@ -251,9 +231,9 @@
}
private void sendUsingOutputStream(MessageContext msgContext,
- OMOutputFormat format, OMElement dataOut) throws AxisFault,
- XMLStreamException {
- OutputStream out = (OutputStream) msgContext
+ OMOutputFormat format) throws AxisFault, XMLStreamException {
+
+ OutputStream out = (OutputStream) msgContext
.getProperty(MessageContext.TRANSPORT_OUT);
// I Don't thinik we need this check.. Content type needs to be set in
@@ -262,81 +242,50 @@
OutTransportInfo transportInfo = (OutTransportInfo) msgContext
.getProperty(Constants.OUT_TRANSPORT_INFO);
- if (transportInfo != null) {
- String contentType = null;
- // FIXME when rest formatter is done
- Object contentTypeObject = msgContext
- .getProperty(Constants.Configuration.CONTENT_TYPE);
- if (contentTypeObject != null) {
- contentType = (String) contentTypeObject;
- } else if (msgContext.isDoingREST() && !(format.isOptimized())) {
- contentType = HTTPConstants.MEDIA_TYPE_APPLICATION_XML;
- }
- if (contentType != null) {
- contentType = contentType + "; charset="
- + format.getCharSetEncoding();
- transportInfo.setContentType(contentType);
- }
- } else {
- throw new AxisFault(Constants.OUT_TRANSPORT_INFO
- + " has not been set");
- }
- format.setAutoCloseWriter(true);
- if (!msgContext.isDoingREST()) {
- MessageFormatter messageFormatter = TransportUtils
- .getMessageFormatter(msgContext);
- transportInfo.setContentType(messageFormatter.getContentType(
- msgContext, format, findSOAPAction(msgContext)));
- messageFormatter.writeTo(msgContext, format, out, false);
- } else {
- // to handle the rest case
- // FIXME when the RESTFormatter is done
- if (!(msgContext.isDoingMTOM()) & (msgContext.isDoingSwA())
- & !(msgContext.isDoingREST())) {
- StringWriter bufferedSOAPBody = new StringWriter();
- dataOut.serializeAndConsume(bufferedSOAPBody, format);
- MIMEOutputUtils.writeSOAPWithAttachmentsMessage(
- bufferedSOAPBody, out, msgContext.getAttachmentMap(),
- format);
- } else {
- ServletBasedOutTransportInfo servletBasedOutTransportInfo =
- (ServletBasedOutTransportInfo) transportInfo;
- List customHheaders = (List) msgContext.getProperty(HTTPConstants.HTTP_HEADERS);
- if (customHheaders != null) {
- Iterator iter = customHheaders.iterator();
- while (iter.hasNext()) {
- Header header = (Header) iter.next();
- if (header != null) {
- servletBasedOutTransportInfo
- .addHeader(header.getName(), header.getValue());
- }
- }
- }
- Object gzip = msgContext.getOptions().getProperty(HTTPConstants.MC_GZIP_RESPONSE);
- if (gzip != null && JavaUtils.isTrueExplicitly(gzip)) {
- servletBasedOutTransportInfo.addHeader(HTTPConstants.HEADER_CONTENT_ENCODING,
- HTTPConstants.COMPRESSION_GZIP);
- GZIPOutputStream gzout = null;
- ByteArrayOutputStream compressed = new ByteArrayOutputStream();
- try {
- gzout = new GZIPOutputStream(compressed);
- dataOut.serializeAndConsume(gzout, format);
- gzout.flush();
- gzout.close();
- out.write(compressed.toByteArray());
- } catch (IOException e) {
- throw new AxisFault("Could not compress response");
+ ServletBasedOutTransportInfo servletBasedOutTransportInfo = null;
+ if (transportInfo != null && transportInfo instanceof ServletBasedOutTransportInfo) {
+ servletBasedOutTransportInfo =
+ (ServletBasedOutTransportInfo) transportInfo;
+ List customHheaders = (List) msgContext.getProperty(HTTPConstants.HTTP_HEADERS);
+ if (customHheaders != null) {
+ Iterator iter = customHheaders.iterator();
+ while (iter.hasNext()) {
+ Header header = (Header) iter.next();
+ if (header != null) {
+ servletBasedOutTransportInfo
+ .addHeader(header.getName(), header.getValue());
}
- } else {
- dataOut.serializeAndConsume(out, format);
}
- }
+ }
+ }
+
+ format.setAutoCloseWriter(true);
+
+ MessageFormatter messageFormatter = TransportUtils
+ .getMessageFormatter(msgContext);
+ transportInfo.setContentType(
+ messageFormatter.getContentType(msgContext, format, findSOAPAction(msgContext)));
+
+ Object gzip = msgContext.getOptions().getProperty(HTTPConstants.MC_GZIP_RESPONSE);
+ if (gzip != null && JavaUtils.isTrueExplicitly(gzip)) {
+ servletBasedOutTransportInfo.addHeader(HTTPConstants.HEADER_CONTENT_ENCODING,
+ HTTPConstants.COMPRESSION_GZIP);
+ try {
+ out = new GZIPOutputStream(out);
+ out.write(messageFormatter.getBytes(msgContext, format));
+ ((GZIPOutputStream) out).finish();
+ out.flush();
+ } catch (IOException e) {
+ throw new AxisFault("Could not compress response");
+ }
+ } else {
+ messageFormatter.writeTo(msgContext, format, out, false);
+ }
- }
}
- public void writeMessageWithCommons(MessageContext messageContext,
- EndpointReference toEPR, OMElement dataout, OMOutputFormat format)
+ private void writeMessageWithCommons(MessageContext messageContext,
+ EndpointReference toEPR, OMOutputFormat format)
throws AxisFault {
try {
URL url = new URL(toEPR.getAddress());
@@ -344,11 +293,8 @@
// select the Message Sender depending on the REST status
AbstractHTTPSender sender;
- if (!messageContext.isDoingREST()) {
- sender = new HTTPSender();
- } else {
- sender = new RESTSender();
- }
+ sender = new SOAPOverHTTPSender();
+
if (messageContext.getProperty(HTTPConstants.CHUNKED) != null) {
chunked = JavaUtils.isTrueExplicitly(messageContext
.getProperty(HTTPConstants.CHUNKED));
@@ -364,8 +310,7 @@
sender.setHttpVersion(httpVersion);
sender.setFormat(format);
- sender.send(messageContext, dataout, url,
- findSOAPAction(messageContext));
+ sender.send(messageContext, url, findSOAPAction(messageContext));
} catch (MalformedURLException e) {
log.debug(e);
throw new AxisFault(e);
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPSender.java?view=diff&rev=507855&r1=507854&r2=507855
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPSender.java Thu Feb 15 00:48:32 2007
@@ -30,8 +30,11 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
import java.io.IOException;
import java.net.MalformedURLException;
@@ -40,66 +43,102 @@
public class HTTPSender extends AbstractHTTPSender {
- public void send(MessageContext msgContext, OMElement dataout, URL url, String soapActionString)
+ public void send(MessageContext msgContext,URL url, String soapActionString)
throws MalformedURLException, AxisFault, IOException {
+
// execute the HtttpMethodBase - a connection manager can be given for
// handle multiple
String httpMethod =
(String) msgContext.getProperty(Constants.Configuration.HTTP_METHOD);
- if ((httpMethod != null)
- && Constants.Configuration.HTTP_METHOD_GET.equalsIgnoreCase(httpMethod)) {
- this.sendViaGet(msgContext, url, soapActionString);
+ if ((httpMethod != null)) {
+
+ if (Constants.Configuration.HTTP_METHOD_GET.equalsIgnoreCase(httpMethod)) {
+ this.sendViaGet(msgContext, url, soapActionString);
+
+ return;
+ } else if (Constants.Configuration.HTTP_METHOD_DELETE.equalsIgnoreCase(httpMethod)) {
+ this.sendViaDelete(msgContext, url, soapActionString);
+
+ return;
+ } else if (Constants.Configuration.HTTP_METHOD_PUT.equalsIgnoreCase(httpMethod)) {
+ this.sendViaPut(msgContext, url, soapActionString);
- return;
+ return;
+ }
}
- this.sendViaPost(msgContext, dataout, url, soapActionString);
+
+ this.sendViaPost(msgContext, url, soapActionString);
}
- private void sendViaGet(MessageContext msgContext, URL url, String soapActiionString) throws IOException {
+ /**
+ * Used to send a request via HTTP Get method
+ *
+ * @param msgContext - The MessageContext of the message
+ * @param url - The target URL
+ * @param soapActiionString - The soapAction string of the request
+ * @throws AxisFault - Thrown in case an exception occurs
+ */
+ private void sendViaGet(MessageContext msgContext, URL url, String soapActiionString)
+ throws AxisFault {
GetMethod getMethod = new GetMethod();
- if (isAuthenticationEnabled(msgContext)) {
- getMethod.setDoAuthentication(true);
- }
-
- MessageFormatter messageFormatter = TransportUtils.getMessageFormatter(
- msgContext);
+ HttpClient httpClient = getHttpClient(msgContext);
+ MessageFormatter messageFormatter =
+ populateCommonProperties(msgContext, url, getMethod, httpClient, soapActiionString);
- url = messageFormatter.getTargetAddress(msgContext, format, url);
+ // Need to have this here because we can have soap action when using the soap response MEP
+ String soapAction =
+ messageFormatter.formatSOAPAction(msgContext, format, soapActiionString);
- getMethod.setPath((url).getFile());
+ if (soapAction != null) {
+ getMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction);
+ }
+ try {
+ executeMethod(httpClient, msgContext, url, getMethod);
+ handleResponse(msgContext, getMethod);
+ } catch (IOException e) {
+ throw new AxisFault(e);
+ }
- getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE, messageFormatter.getContentType(msgContext, format, soapActiionString));
- HttpClient httpClient = getHttpClient(msgContext);
+ }
- executeMethod(httpClient, msgContext, url, getMethod);
+ /**
+ * Used to send a request via HTTP Delete Method
+ *
+ * @param msgContext - The MessageContext of the message
+ * @param url - The target URL
+ * @param soapActiionString - The soapAction string of the request
+ * @throws AxisFault - Thrown in case an exception occurs
+ */
+ private void sendViaDelete(MessageContext msgContext, URL url, String soapActiionString)
+ throws AxisFault {
- if (getMethod.getStatusCode() == HttpStatus.SC_OK) {
- processResponse(getMethod, msgContext);
- } else if (getMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
- } else if (getMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
- Header contenttypeHheader =
- getMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
- String value = contenttypeHheader.getValue();
+ DeleteMethod deleteMethod = new DeleteMethod();
+ HttpClient httpClient = getHttpClient(msgContext);
+ populateCommonProperties(msgContext, url, deleteMethod, httpClient, soapActiionString);
- if (value != null) {
- if ((value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0)
- || (value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >= 0)) {
- processResponse(getMethod, msgContext);
- }
- }
- } else {
- throw new AxisFault(Messages.getMessage("transportError",
- String.valueOf(getMethod.getStatusCode()),
- getMethod.getResponseBodyAsString()));
+ try {
+ executeMethod(httpClient, msgContext, url, deleteMethod);
+ handleResponse(msgContext, deleteMethod);
+ } catch (IOException e) {
+ throw new AxisFault(e);
}
}
- private void sendViaPost(MessageContext msgContext, OMElement dataout, URL url, String soapActionString) throws IOException {
+ /**
+ * Used to send a request via HTTP Post Method
+ *
+ * @param msgContext - The MessageContext of the message
+ * @param url - The target URL
+ * @param soapActionString - The soapAction string of the request
+ * @throws AxisFault - Thrown in case an exception occurs
+ */
+ private void sendViaPost(MessageContext msgContext, URL url,
+ String soapActionString) throws AxisFault {
HttpClient httpClient = getHttpClient(msgContext);
@@ -111,103 +150,175 @@
charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
}
- 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());
-
- if (isAuthenticationEnabled(msgContext)) {
- postMethod.setDoAuthentication(true);
- }
+ MessageFormatter messageFormatter =
+ populateCommonProperties(msgContext, url, postMethod, httpClient, soapActionString);
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);
}
+ /*
+ * main excecution takes place..
+ */
+ try {
+ executeMethod(httpClient, msgContext, url, postMethod);
+ handleResponse(msgContext, postMethod);
+ } catch (IOException e) {
+ throw new AxisFault(e);
+ }
+
+ }
+
+ /**
+ * Used to send a request via HTTP Put Method
+ *
+ * @param msgContext - The MessageContext of the message
+ * @param url - The target URL
+ * @param soapActionString - The soapAction string of the request
+ * @throws AxisFault - Thrown in case an exception occurs
+ */
+ private void sendViaPut(MessageContext msgContext, URL url,
+ String soapActionString) throws AxisFault {
+
+
+ HttpClient httpClient = getHttpClient(msgContext);
+
+ String charEncoding =
+ (String) msgContext.getProperty(Constants.Configuration.CHARACTER_SET_ENCODING);
+
+ if (charEncoding == null) {
+ charEncoding = MessageContext.DEFAULT_CHAR_SET_ENCODING;
+ }
+
+ PutMethod putMethod = new PutMethod();
+ MessageFormatter messageFormatter =
+ populateCommonProperties(msgContext, url, putMethod, httpClient, soapActionString);
+
+ putMethod.setRequestEntity(new AxisRequestEntity(messageFormatter,
+ msgContext, format, soapActionString,
+ chunked, isAllowedRetry));
+
+ if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) {
+ putMethod.setContentChunked(true);
+ }
+
+ String soapAction = messageFormatter.formatSOAPAction(msgContext, format, soapActionString);
+ if (soapAction != null) {
+ putMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction);
+ }
+
+ /*
+ * main excecution takes place..
+ */
+ try {
+ executeMethod(httpClient, msgContext, url, putMethod);
+ handleResponse(msgContext, putMethod);
+ } catch (IOException e) {
+ throw new AxisFault(e);
+ }
+ }
+
+ /**
+ * Method used to copy all the common properties
+ *
+ * @param msgContext - The messageContext of the request message
+ * @param url - The target URL
+ * @param httpMethod - The http method used to send the request
+ * @param httpClient - The httpclient used to send the request
+ * @param soapActionString - The soap action atring of the request message
+ * @return MessageFormatter - The messageFormatter for the relavent request message
+ * @throws AxisFault - Thrown in case an exception occurs
+ */
+ private MessageFormatter populateCommonProperties(MessageContext msgContext, URL url,
+ HttpMethodBase httpMethod,
+ HttpClient httpClient,
+ String soapActionString)
+ throws AxisFault {
+
+ if (isAuthenticationEnabled(msgContext)) {
+ httpMethod.setDoAuthentication(true);
+ }
+
+ MessageFormatter messageFormatter = TransportUtils.getMessageFormatter(
+ msgContext);
+
+ url = messageFormatter.getTargetAddress(msgContext, format, url);
+
+ httpMethod.setPath(url.getPath());
+
+ httpMethod.setQueryString(url.getQuery());
+
+ httpMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
+ messageFormatter.getContentType(msgContext, format,
+ soapActionString));
+
+ httpMethod.setRequestHeader(HTTPConstants.HEADER_HOST, url.getHost());
+
//setting the cookie in the out path
Object cookieString = msgContext.getProperty(HTTPConstants.COOKIE_STRING);
+
if (cookieString != null) {
StringBuffer buffer = new StringBuffer();
buffer.append(Constants.SESSION_COOKIE_JSESSIONID);
buffer.append("=");
buffer.append(cookieString);
- postMethod.setRequestHeader(HTTPConstants.HEADER_COOKIE, buffer.toString());
+ httpMethod.setRequestHeader(HTTPConstants.HEADER_COOKIE, buffer.toString());
}
- postMethod.setRequestHeader(HTTPConstants.HEADER_HOST, url.getHost());
-
- if (httpVersion != null) {
- if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) {
- httpClient.getParams().setVersion(HttpVersion.HTTP_1_0);
- } else {
- postMethod.setRequestHeader(HTTPConstants.HEADER_EXPECT,
- HTTPConstants.HEADER_EXPECT_100_Continue);
- }
+ if (httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10)) {
+ httpClient.getParams().setVersion(HttpVersion.HTTP_1_0);
}
// set timeout in client
long timeout = msgContext.getOptions().getTimeOutInMilliSeconds();
+
if (timeout != 0) {
httpClient.getParams().setSoTimeout((int) timeout);
}
- /*
- * main excecution takes place..
- */
- executeMethod(httpClient, msgContext, url, postMethod);
+ return messageFormatter;
+ }
- /*
- * Execution is over
- */
- if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
- processResponse(postMethod, msgContext);
- return;
- } else if (postMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
- return;
- } else if (postMethod.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
- Header contentTypeHeader =
- postMethod.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
+ /**
+ * Used to handle the HTTP Response
+ *
+ * @param msgContext - The MessageContext of the message
+ * @param method - The HTTP method used
+ * @throws IOException - Thrown in case an exception occurs
+ */
+ private void handleResponse(MessageContext msgContext,
+ HttpMethodBase method) throws IOException {
+
+ if (method.getStatusCode() == HttpStatus.SC_OK) {
+ processResponse(method, msgContext);
+ } else if (method.getStatusCode() == HttpStatus.SC_ACCEPTED) {
+ } else if (method.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
+ Header contenttypeHheader =
+ method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
+ String value = contenttypeHheader.getValue();
- if (contentTypeHeader != null) {
- String value = contentTypeHeader.getValue();
+ if (value != null) {
if ((value.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) >= 0)
|| (value.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >= 0)) {
- processResponse(postMethod, msgContext);
-
- return;
+ processResponse(method, msgContext);
}
}
} else {
- throw new AxisFault(Messages.getMessage("httpTransportError",
- String.valueOf(postMethod.getStatusCode()),
- postMethod.getStatusText()),
- SOAP12Constants.FAULT_CODE_SENDER);
+ throw new AxisFault(Messages.getMessage("transportError",
+ String.valueOf(method.getStatusCode()),
+ method.getStatusText()));
}
-
- throw new AxisFault(Messages.getMessage("transportError",
- String.valueOf(postMethod.getStatusCode()),
- postMethod.getResponseBodyAsString()));
}
-
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java?view=diff&rev=507855&r1=507854&r2=507855
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java Thu Feb 15 00:48:32 2007
@@ -20,6 +20,7 @@
import java.io.OutputStream;
import java.io.StringWriter;
import java.net.URL;
+import java.net.MalformedURLException;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLStreamException;
@@ -32,6 +33,7 @@
import org.apache.axis2.Constants;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.transport.MessageFormatter;
+import org.apache.axis2.transport.http.util.URLTemplatingUtil;
import org.apache.axis2.util.JavaUtils;
public class SOAPMessageFormatter implements MessageFormatter{
@@ -127,7 +129,10 @@
public URL getTargetAddress(MessageContext msgCtxt, OMOutputFormat format,
URL targetURL) throws AxisFault{
- // SOAP do not want to alter the target URL
+
+ // Check whether there is a template in the URL, if so we have to replace then with data
+ // values and create a new target URL.
+ targetURL = URLTemplatingUtil.getTemplatedURL(targetURL,msgCtxt,false);
return targetURL;
}
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/XFormURLEncodedFormatter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/XFormURLEncodedFormatter.java?view=auto&rev=507855
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/XFormURLEncodedFormatter.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/XFormURLEncodedFormatter.java Thu Feb 15 00:48:32 2007
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.transport.http;
+
+import org.apache.axis2.transport.MessageFormatter;
+import org.apache.axis2.transport.http.util.URLTemplatingUtil;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.description.WSDL2Constants;
+import org.apache.axis2.util.JavaUtils;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMElement;
+
+import java.io.OutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.util.Iterator;
+
+/**
+ * Formates the request message as application/x-www-form-urlencoded
+ */
+public class XFormURLEncodedFormatter implements MessageFormatter {
+
+ public byte[] getBytes(MessageContext messageContext, OMOutputFormat format) throws AxisFault {
+
+ OMElement omElement = messageContext.getEnvelope().getBody().getFirstElement();
+
+ if (omElement != null) {
+ Iterator it = omElement.getChildElements();
+ String paraString = "";
+
+ while (it.hasNext()) {
+ OMElement ele1 = (OMElement) it.next();
+ String parameter;
+
+ parameter = ele1.getLocalName() + "=" + ele1.getText();
+ paraString = "".equals(paraString) ? parameter : (paraString + "&" + parameter);
+ }
+
+ return paraString.getBytes();
+ }
+
+ return new byte[0];
+ }
+
+ public void writeTo(MessageContext messageContext, OMOutputFormat format,
+ OutputStream outputStream, boolean preserve) throws AxisFault {
+
+ try {
+ outputStream.write(getBytes(messageContext, format));
+ } catch (IOException e) {
+ throw new AxisFault("An error occured while writing the request");
+ }
+ }
+
+ public String getContentType(MessageContext messageContext, OMOutputFormat format,
+ String soapAction) {
+
+ String encoding = format.getCharSetEncoding();
+ String contentType = HTTPConstants.MEDIA_TYPE_X_WWW_FORM;
+
+ if (encoding != null) {
+ contentType += "; charset=" + encoding;
+ }
+
+ // if soap action is there (can be there is soap response MEP is used) add it.
+ if ((soapAction != null)
+ && !"".equals(soapAction.trim())
+ && !"\"\"".equals(soapAction.trim())) {
+ contentType = contentType + ";action=\"" + soapAction + "\";";
+ }
+
+ return contentType;
+ }
+
+ public URL getTargetAddress(MessageContext messageContext, OMOutputFormat format, URL targetURL)
+ throws AxisFault {
+
+ // Check whether there is a template in the URL, if so we have to replace then with data
+ // values and create a new target URL.
+ targetURL = URLTemplatingUtil.getTemplatedURL(targetURL, messageContext, true);
+ targetURL = URLTemplatingUtil.appendParametersToURL(messageContext, targetURL);
+
+ return targetURL;
+ }
+
+ public String formatSOAPAction(MessageContext messageContext, OMOutputFormat format,
+ String soapAction) {
+ return soapAction;
+ }
+}
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=507855&r1=507854&r2=507855
==============================================================================
--- 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 Thu Feb 15 00:48:32 2007
@@ -49,6 +49,10 @@
import javax.servlet.http.HttpServletResponse;
import javax.xml.stream.XMLStreamReader;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.BufferedInputStream;
+import java.util.zip.GZIPInputStream;
+import java.util.Map;
/**
*
@@ -251,7 +255,15 @@
SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
SOAPBody body = soapEnvelope.getBody();
- ServletInputStream inputStream = request.getInputStream();
+ InputStream inputStream = new BufferedInputStream(request.getInputStream());
+ Map headers = (Map) msgCtxt.getProperty(MessageContext.TRANSPORT_HEADERS);
+ if (headers != null) {
+ if (HTTPConstants.COMPRESSION_GZIP.equals(headers.get(HTTPConstants.HEADER_CONTENT_ENCODING)) ||
+ HTTPConstants.COMPRESSION_GZIP.equals(headers.get(HTTPConstants.HEADER_CONTENT_ENCODING_LOWERCASE)))
+ {
+ inputStream = new GZIPInputStream(inputStream);
+ }
+ }
String contentType = request.getContentType();
// irrespective of the schema, if the media type is text/xml, all the information
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/URLTemplatingUtil.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/URLTemplatingUtil.java?view=auto&rev=507855
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/URLTemplatingUtil.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/util/URLTemplatingUtil.java Thu Feb 15 00:48:32 2007
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.transport.http.util;
+
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.util.JavaUtils;
+import org.apache.axis2.description.WSDL2Constants;
+import org.apache.axis2.description.WSDL20DefaultValueHolder;
+import org.apache.axiom.om.OMElement;
+import org.apache.woden.wsdl20.extensions.http.HTTPLocation;
+
+import javax.xml.namespace.QName;
+import java.net.URLEncoder;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+
+/**
+ * This util is used on the client side for creating the URL's for all request (WSDL 2.0 allws to
+ * change the URL's of SOAP messages too). It resolves WSDL 2.0 httplocation property and also
+ * append parameters to URL's when needed.
+ */
+public class URLTemplatingUtil {
+
+ /**
+ * This method is used to resolve httplocation property. It changes the URL as stipulated by
+ * the httplocation property.
+ *
+ * @param messageContext - The MessageContext of the request
+ * @param rawURLString - The raw URL containing httplocation templates
+ * @param detach - Boolean value specifying whether the element should be detached from the
+ * envelop. When serializing data as application/x-form-urlencoded what goes in the body is the
+ * remainder and therefore we should detach the element from the envelop.
+ * @return - String with templated values replaced
+ * @throws AxisFault - Thrown in case an exception occurs
+ */
+ private static String applyURITemplating(MessageContext messageContext, String rawURLString,
+ boolean detach) throws AxisFault {
+
+ OMElement firstElement;
+ if (detach) {
+ firstElement = messageContext.getEnvelope().getBody().getFirstElement();
+ } else {
+ firstElement =
+ messageContext.getEnvelope().getBody().getFirstElement().cloneOMElement();
+ }
+
+ HTTPLocation httpLocation = new HTTPLocation(rawURLString);
+ String[] localNames = httpLocation.getLocalNames();
+ String[] values = new String[localNames.length];
+
+ for (int i = 0; i < localNames.length; i++) {
+ String localName = localNames[i];
+ try {
+ values[i] = URLEncoder.encode(getOMElementValue(localName, firstElement), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new AxisFault("Unable to encode Query String");
+ }
+ }
+
+ httpLocation.substitute(values);
+
+ return httpLocation.toString();
+ }
+
+ /**
+ * Appends Query parameters to the URL
+ *
+ * @param messageContext - The MessageContext of the request
+ * @param query - Original query string
+ * @return String containing the appended query parameters
+ */
+ private static String appendQueryParameters(MessageContext messageContext, String query) {
+
+ OMElement firstElement;
+ String queryParameterSeparator = (String) messageContext
+ .getProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
+ // In case queryParameterSeparator is null we better use the default value
+
+ if (queryParameterSeparator == null) {
+ queryParameterSeparator = WSDL20DefaultValueHolder
+ .getDefaultValue(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
+ }
+
+ firstElement = messageContext.getEnvelope().getBody().getFirstElement();
+ ArrayList values = new ArrayList();
+
+ if (firstElement != null) {
+ Iterator iter = firstElement.getChildElements();
+
+ while (iter.hasNext()) {
+ OMElement element = (OMElement) iter.next();
+ values.add(element.getLocalName() + "=" + element.getText());
+ }
+ }
+
+ if (values.size() > 0) {
+
+ if (query.indexOf("?") == query.length() - 1) {
+ query = query + values.get(0);
+ } else {
+ query = query + "?" + values.get(0);
+ }
+
+ for (int i = 1; i < values.size(); i++) {
+ query = query + queryParameterSeparator + values.get(i);
+ }
+ }
+ return query;
+ }
+
+ /**
+ * This method is used to retrive elements from the soap envelop
+ *
+ * @param elementName - The name of the required element
+ * @param parentElement - The parent element that the required element should be retrived from
+ * @return - The value of the element as a string
+ */
+ private static String getOMElementValue(String elementName, OMElement parentElement) {
+
+ OMElement httpURLParam = parentElement.getFirstChildWithName(new QName(elementName));
+
+ if (httpURLParam != null) {
+ httpURLParam.detach();
+
+ if (parentElement.getFirstOMChild() == null) {
+ parentElement.detach();
+ }
+ }
+
+ return httpURLParam.getText();
+
+ }
+
+ /**
+ * Returns the templated URL given the original URL
+ *
+ * @param targetURL - The original URL
+ * @param messageContext - The MessageContext of the request
+ * @param detach - Boolean value specifying whether the element should be detached from the
+ * envelop. When serializing data as application/x-form-urlencoded what goes in the body is the
+ * remainder and therefore we should detach the element from the envelop.
+ * @return The templated URL
+ * @throws AxisFault - Thrown in case an exception occurs
+ */
+ public static URL getTemplatedURL(URL targetURL, MessageContext messageContext, boolean detach)
+ throws AxisFault {
+
+ String urlString = targetURL.toString();
+ String replacedQuery = "";
+ String path = "";
+ int separator = urlString.indexOf('{');
+
+ if (separator > 0) {
+ path = urlString.substring(0, separator - 1);
+ String query = urlString.substring(separator - 1);
+
+ replacedQuery = URLTemplatingUtil.applyURITemplating(messageContext, query, detach);
+ try {
+ targetURL = new URL(path + replacedQuery);
+ } catch (MalformedURLException e) {
+ throw new AxisFault("An error occured while trying to create request URL");
+ }
+ }
+
+ return targetURL;
+ }
+
+ /**
+ * Methos used to append parameters to URL. First checks whether the parameters should be
+ * appended to the URL based on the WSDL 2.0 property whttp:ignoreUncited
+ *
+ * @param messageContext - The MessageContext of the request
+ * @param targetURL - The original URL
+ * @return returns an URL with the query parameters appended to it
+ * @throws AxisFault - Thrown in case an exception occurs
+ */
+ public static URL appendParametersToURL(MessageContext messageContext, URL targetURL)
+ throws AxisFault {
+
+ String url = targetURL.toString();
+ String ignoreUncited =
+ (String) messageContext.getProperty(WSDL2Constants.ATTR_WHTTP_IGNORE_UNCITED);
+
+ if (ignoreUncited == null || !JavaUtils.isTrueExplicitly(ignoreUncited)) {
+ url = appendQueryParameters(messageContext, url);
+ try {
+ targetURL = new URL(url);
+ } catch (MalformedURLException e) {
+ throw new AxisFault("Unable to create target URL from template");
+ }
+ } else if (Constants.Configuration.HTTP_METHOD_GET
+ .equalsIgnoreCase((String) messageContext.getProperty(
+ Constants.Configuration.HTTP_METHOD))) {
+ messageContext.getEnvelope().getBody().getFirstElement().detach();
+ }
+
+ return targetURL;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org