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 di...@apache.org on 2006/12/27 03:59:30 UTC
svn commit: r490432 - in /webservices/axis2/trunk/java/modules/kernel:
src/org/apache/axis2/transport/http/ test/org/apache/axis2/transport/
Author: dims
Date: Tue Dec 26 18:59:29 2006
New Revision: 490432
URL: http://svn.apache.org/viewvc?view=rev&rev=490432
Log:
Move all the inner classes that implement RequestEntity into separate classes. cleanup unused/unnecessary code
Added:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity2.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPRequestEntity.java
Removed:
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/HTTPTransportHeaderParsingTest.java
Modified:
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/HTTPTransportReceiver.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTSender.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPOverHTTPSender.java
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=490432&r1=490431&r2=490432
==============================================================================
--- 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 Tue Dec 26 18:59:29 2006
@@ -344,8 +344,4 @@
throw new AxisFault(e);
}
}
-
- public void writeMessageWithToOutPutStream(MessageContext msgContext,
- OutputStream out) {
- }
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportReceiver.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportReceiver.java?view=diff&rev=490432&r1=490431&r2=490432
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportReceiver.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportReceiver.java Tue Dec 26 18:59:29 2006
@@ -37,243 +37,6 @@
* Class HTTPTransportReceiver
*/
public class HTTPTransportReceiver {
-
- /**
- * Field BEFORE_SEPARATOR
- */
- private static final int BEFORE_SEPARATOR = 3;
-
- /**
- * Field AFTER_SEPARATOR
- */
- private static final int AFTER_SEPARATOR = 4;
-
- /**
- * Field lastRead
- */
- private int lastRead = -1;
-
- /**
- * Field index
- */
- int index = 0;
-
- /**
- * Field buf
- */
- private byte[] buf = new byte[1024];
-
- /**
- * Field length
- */
- int length = 0;
-
- /**
- * Field done
- */
- private boolean done = false;
-
- /**
- * Parses following two styles of HTTP stuff
- * Server Side
- * POST /axis2/services/echo HTTP/1.0
- * Content-Type: text/xml; charset=utf-8
- * Accept: application/soap+xml, application/dime, multipart/related, text
- * User-Agent: Axis/1.2RC1
- * Host: 127.0.0.1:8081
- * Cache-Control: no-cache
- * Pragma: no-cache
- * SOAPAction: ""
- * Content-Length: 73507
- * HTTP/1.1 200 OK
- * Content-Type: text/xml;charset=utf-8
- * Date: Sat, 12 Feb 2005 10:39:39 GMT
- * Server: Apache-Coyote/1.1
- * Connection: close
- *
- * @param in
- * @param serverSide
- * @return Returns HashMap.
- * @throws AxisFault
- */
- public HashMap parseTheHeaders(InputStream in, boolean serverSide) throws AxisFault {
- HashMap map = new HashMap();
-
- try {
- StringBuffer str = new StringBuffer();
- int state = BEFORE_SEPARATOR;
- String key = null;
- String value = null;
-
- length = readLine(in, buf);
-
- if (serverSide) {
- if ((buf[0] == 'P') && (buf[1] == 'O') && (buf[2] == 'S') && (buf[3] == 'T')) {
- map.put(HTTPConstants.HTTP_REQ_TYPE, HTTPConstants.HEADER_POST);
- index = 5;
- } else if ((buf[0] == 'G') && (buf[1] == 'E') && (buf[2] == 'T')) {
- map.put(HTTPConstants.HTTP_REQ_TYPE, HTTPConstants.HEADER_GET);
- index = 4;
- } else {
- throw new AxisFault(
- "Unsupported HTTP request type: Only GET and POST is supported");
- }
-
- value = readFirstLineArg(' ');
- map.put(HTTPConstants.REQUEST_URI, value);
- value = readFirstLineArg('\n');
- map.put(HTTPConstants.PROTOCOL_VERSION, value);
- } else {
- index = 0;
- value = readFirstLineArg(' ');
-
- if ((value != null) && (value.indexOf("HTTP") >= 0)) {
- map.put(HTTPConstants.PROTOCOL_VERSION, value);
- value = readFirstLineArg(' ');
- map.put(HTTPConstants.RESPONSE_CODE, value);
- } else {
- map.put(HTTPConstants.RESPONSE_CODE, value);
- }
-
- value = readFirstLineArg('\n');
- map.put(HTTPConstants.RESPONSE_WORD, value);
- }
-
- state = BEFORE_SEPARATOR;
-
- while (!done) {
- length = readLine(in, buf);
-
- if (length <= 0) {
- throw new AxisFault(Messages.getMessage("preatureEOS"));
- }
-
- for (int i = 0; i < length; i++) {
- switch (state) {
- case BEFORE_SEPARATOR :
- if (buf[i] == ':') {
- key = str.toString();
- str = new StringBuffer();
- state = AFTER_SEPARATOR;
-
- if (buf[i + 1] == ' ') {
- i++; // ignore next space
- }
- } else {
- str.append((char) buf[i]);
- }
-
- break;
-
- case AFTER_SEPARATOR :
- if (buf[i] == '\n') {
- value = str.toString();
- map.put(key, value);
- str = new StringBuffer();
- i = length;
- } else {
- str.append((char) buf[i]);
- }
-
- break;
-
- default :
- throw new AxisFault("Error Occured Unknown state " + state);
- }
- }
-
- state = BEFORE_SEPARATOR;
- }
- } catch (IOException e) {
- throw new AxisFault(e.getMessage(), e);
- }
-
- return map;
- }
-
- /**
- * Method readFirstLineArg.
- *
- * @param terminal
- * @return Returns String.
- * @throws org.apache.axis2.AxisFault
- */
- private String readFirstLineArg(char terminal) throws AxisFault {
- StringBuffer str = new StringBuffer();
-
- try {
- while ((buf[index] != terminal) && (index < length)) {
- str.append((char) buf[index]);
- index++;
- }
-
- index++;
-
- return str.toString();
- } catch (Exception e) {
- throw new AxisFault(e.getMessage(), e);
- }
- }
-
- /**
- * Reads a single line from the input stream.
- *
- * @param is inputstream to read from
- * @param b byte array to read into
- * @return Returns int.
- * @throws java.io.IOException
- */
- protected int readLine(InputStream is, byte[] b) throws java.io.IOException {
- int count = 0, c;
-
- if (lastRead == -1) {
- c = is.read();
- } else {
- c = lastRead;
- }
-
- int off = 0;
-
- while (c != -1) {
- if ((c != '\n') && (c != '\r')) {
- b[off++] = (byte) c;
- count++;
- c = is.read();
- } else {
- if ('\n' == c) {
- c = is.read();
-
- if (c == '\r') {
- c = is.read();
- }
-
- // If the next line begins with tab or space then this is a continuation.
- if ((c != ' ') && (c != '\t')) {
- if (c == '\n') {
- done = true;
- }
-
- lastRead = c;
- b[off++] = '\n';
- count++;
-
- break;
- }
- } else {
- c = is.read();
- }
- }
- }
-
- if (c == -1) {
- throw new AxisFault("Every line should ends with the \\n, unexpected End of stream");
- } else {
- return (count > 0)
- ? count
- : -1;
- }
- }
-
public static Map getGetRequestParameters(String requestURI) {
Map map = new HashMap();
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java?view=diff&rev=490432&r1=490431&r2=490432
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/HTTPTransportUtils.java Tue Dec 26 18:59:29 2006
@@ -72,10 +72,8 @@
String operation = values[1];
SOAPFactory soapFactory = new SOAP11Factory();
SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
-// OMNamespace omNs = soapFactory.createOMNamespace(values[0], "services");
OMNamespace omNs = soapFactory.createOMNamespace(service.getSchematargetNamespace(),
service.getSchematargetNamespacePrefix());
- //OMNamespace defualtNs = new OMNamespaceImpl("", null, soapFactory);
soapFactory.createOMNamespace(service.getSchematargetNamespace(),
service.getSchematargetNamespacePrefix());
OMElement opElement = soapFactory.createOMElement(operation, omNs);
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity.java?view=auto&rev=490432
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity.java Tue Dec 26 18:59:29 2006
@@ -0,0 +1,137 @@
+/*
+* 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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.commons.httpclient.methods.RequestEntity;
+
+public class RESTRequestEntity 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 OMOutputFormat format;
+
+ public RESTRequestEntity(OMElement element, boolean chunked,
+ MessageContext msgCtxt,
+ String charSetEncoding,
+ String soapActionString,
+ OMOutputFormat format) {
+ this.element = element;
+ this.chunked = chunked;
+ this.msgCtxt = msgCtxt;
+ this.doingMTOM = msgCtxt.isDoingMTOM();
+ this.charSetEnc = charSetEncoding;
+ this.soapActionString = soapActionString;
+ this.format = format;
+ }
+
+ 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 (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 (bytes == null) {
+ bytes = writeBytes();
+ }
+ return bytes.length;
+ }
+ } catch (AxisFault e) {
+ return -1;
+ }
+ }
+
+ public String getContentType() {
+ String encoding = format.getCharSetEncoding();
+ String contentType = format.getContentType();
+ 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;
+ }
+}
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity2.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity2.java?view=auto&rev=490432
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity2.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/RESTRequestEntity2.java Tue Dec 26 18:59:29 2006
@@ -0,0 +1,48 @@
+/*
+* 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 java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.commons.httpclient.methods.RequestEntity;
+
+public class RESTRequestEntity2 implements RequestEntity {
+ private String contentType;
+ private String postRequestBody;
+
+ public RESTRequestEntity2(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;
+ }
+}
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=490432&r1=490431&r2=490432
==============================================================================
--- 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 Tue Dec 26 18:59:29 2006
@@ -18,7 +18,6 @@
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;
@@ -31,15 +30,10 @@
import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.FactoryConfigurationError;
import java.io.IOException;
-import java.io.OutputStream;
-import java.io.ByteArrayOutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
@@ -235,12 +229,12 @@
if (reqData.bodyRequest == null) {
reqData.bodyRequest = "0";
}
- postMethod.setRequestEntity(new AxisRESTRequestEntity(reqData.bodyRequest,httpContentType));
+ postMethod.setRequestEntity(new RESTRequestEntity2(reqData.bodyRequest,httpContentType));
} else {
postMethod.setPath(url.getPath());
- postMethod.setRequestEntity(new AxisRequestEntity(dataout, chunked, msgContext,
- charEncoding, soapActionString));
+ postMethod.setRequestEntity(new RESTRequestEntity(dataout, chunked, msgContext,
+ charEncoding, soapActionString, format));
}
if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) {
@@ -325,149 +319,6 @@
}
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;
-
- public AxisRequestEntity(OMElement element, boolean chunked,
- MessageContext msgCtxt,
- String charSetEncoding,
- String soapActionString) {
- this.element = element;
- this.chunked = chunked;
- this.msgCtxt = msgCtxt;
- this.doingMTOM = msgCtxt.isDoingMTOM();
- this.charSetEnc = charSetEncoding;
- this.soapActionString = soapActionString;
- }
-
- 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 (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 (bytes == null) {
- bytes = writeBytes();
- }
-
- return bytes.length;
- }
- }
- } catch (AxisFault e) {
- return -1;
- }
- }
-
- public String getContentType() {
- String encoding = format.getCharSetEncoding();
- String contentType = format.getContentType();
-
- 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 {
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=490432&r1=490431&r2=490432
==============================================================================
--- 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 Tue Dec 26 18:59:29 2006
@@ -16,33 +16,22 @@
package org.apache.axis2.transport.http;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
-import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.zip.GZIPOutputStream;
-
-import javax.xml.stream.FactoryConfigurationError;
-import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.impl.MIMEOutputUtils;
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.i18n.Messages;
-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.PostMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
public class SOAPOverHTTPSender extends AbstractHTTPSender {
@@ -66,8 +55,8 @@
}
postMethod.setPath(url.getPath());
- postMethod.setRequestEntity(new AxisSOAPRequestEntity(dataout, chunked, msgContext,
- charEncoding, soapActionString));
+ postMethod.setRequestEntity(new SOAPRequestEntity(dataout, chunked, msgContext,
+ charEncoding, soapActionString, format, isAllowedRetry));
if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chunked) {
postMethod.setContentChunked(true);
@@ -147,144 +136,5 @@
throw new AxisFault(Messages.getMessage("transportError",
String.valueOf(postMethod.getStatusCode()), postMethod.getResponseBodyAsString()));
- }
-
- public class AxisSOAPRequestEntity implements RequestEntity {
- private boolean doingMTOM = false;
- private boolean doingSWA = false;
- private byte[] bytes;
- private String charSetEnc;
- private boolean chunked;
- private OMElement element;
- private MessageContext msgCtxt;
- private String soapActionString;
-
- public AxisSOAPRequestEntity(OMElement element, boolean chunked, MessageContext msgCtxt,
- String charSetEncoding, String soapActionString) {
- this.element = element;
- this.chunked = chunked;
- this.msgCtxt = msgCtxt;
- this.doingMTOM = msgCtxt.isDoingMTOM();
- this.doingSWA = msgCtxt.isDoingSwA();
- this.charSetEnc = charSetEncoding;
- this.soapActionString = soapActionString;
- }
-
- private void handleOMOutput(OutputStream out, boolean doingMTOM)
- throws XMLStreamException {
- format.setDoOptimize(doingMTOM);
- format.setDoingSWA(doingSWA);
-
- if (!doingMTOM & doingSWA) {
- StringWriter bufferedSOAPBody = new StringWriter();
- if (isAllowedRetry) {
- element.serialize(bufferedSOAPBody, format);
- } else {
- element.serializeAndConsume(bufferedSOAPBody, format);
- }
- MIMEOutputUtils.writeSOAPWithAttachmentsMessage(bufferedSOAPBody,out,msgCtxt.getAttachmentMap(), format);
- } else {
- if (isAllowedRetry) {
- element.serialize(out, format);
- } else {
- element.serializeAndConsume(out, format);
- }
- }
- }
-
- public byte[] writeBytes() throws AxisFault {
- try {
- ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
-
- if (!doingMTOM) {
- // why are we creating a new OMOutputFormat
- OMOutputFormat format2 = new OMOutputFormat();
- format2.setCharSetEncoding(charSetEnc);
- if (doingSWA) {
- StringWriter bufferedSOAPBody = new StringWriter();
- element.serializeAndConsume(bufferedSOAPBody,format2);
- MIMEOutputUtils.writeSOAPWithAttachmentsMessage(bufferedSOAPBody,bytesOut,msgCtxt.getAttachmentMap(), format2);
- } else {
- 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 {
- Object gzip = msgCtxt.getOptions().getProperty(HTTPConstants.MC_GZIP_REQUEST);
- if(gzip != null && JavaUtils.isTrueExplicitly(gzip) && chunked) {
- out = new GZIPOutputStream(out);
- }
- try {
- if (chunked) {
- this.handleOMOutput(out, doingMTOM);
- } else {
- if (bytes == null) {
- bytes = writeBytes();
- }
-
- out.write(bytes);
- }
-
- if(out instanceof GZIPOutputStream){
- ((GZIPOutputStream)out).finish();
- }
- 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 (bytes == null) {
- bytes = writeBytes();
- }
-
- return bytes.length;
- }
- } catch (AxisFault e) {
- return -1;
- }
- }
-
- public String getContentType() {
- String encoding = format.getCharSetEncoding();
- String contentType = format.getContentType();
-
- 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;
- }
}
}
Added: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPRequestEntity.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPRequestEntity.java?view=auto&rev=490432
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPRequestEntity.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPRequestEntity.java Tue Dec 26 18:59:29 2006
@@ -0,0 +1,172 @@
+/*
+* 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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.util.zip.GZIPOutputStream;
+
+import javax.xml.stream.FactoryConfigurationError;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.impl.MIMEOutputUtils;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.util.JavaUtils;
+import org.apache.commons.httpclient.methods.RequestEntity;
+
+public class SOAPRequestEntity implements RequestEntity {
+ private boolean doingMTOM = false;
+ private boolean doingSWA = false;
+ private byte[] bytes;
+ private String charSetEnc;
+ private boolean chunked;
+ private OMElement element;
+ private MessageContext msgCtxt;
+ private String soapActionString;
+ private OMOutputFormat format;
+ private boolean isAllowedRetry;
+
+ public SOAPRequestEntity(OMElement element, boolean chunked, MessageContext msgCtxt,
+ String charSetEncoding, String soapActionString,
+ OMOutputFormat format,
+ boolean isAllowedRetry) {
+ this.element = element;
+ this.chunked = chunked;
+ this.msgCtxt = msgCtxt;
+ this.doingMTOM = msgCtxt.isDoingMTOM();
+ this.doingSWA = msgCtxt.isDoingSwA();
+ this.charSetEnc = charSetEncoding;
+ this.soapActionString = soapActionString;
+ this.format = format;
+ this.isAllowedRetry = isAllowedRetry;
+ }
+
+ private void handleOMOutput(OutputStream out, boolean doingMTOM)
+ throws XMLStreamException {
+ format.setDoOptimize(doingMTOM);
+ format.setDoingSWA(doingSWA);
+ if (!doingMTOM & doingSWA) {
+ StringWriter bufferedSOAPBody = new StringWriter();
+ if (isAllowedRetry) {
+ element.serialize(bufferedSOAPBody, format);
+ } else {
+ element.serializeAndConsume(bufferedSOAPBody, format);
+ }
+ MIMEOutputUtils.writeSOAPWithAttachmentsMessage(bufferedSOAPBody, out, msgCtxt.getAttachmentMap(), format);
+ } else {
+ if (isAllowedRetry) {
+ element.serialize(out, format);
+ } else {
+ element.serializeAndConsume(out, format);
+ }
+ }
+ }
+
+ public byte[] writeBytes() throws AxisFault {
+ try {
+ ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
+ if (!doingMTOM) {
+ // why are we creating a new OMOutputFormat
+ OMOutputFormat format2 = new OMOutputFormat();
+ format2.setCharSetEncoding(charSetEnc);
+ if (doingSWA) {
+ StringWriter bufferedSOAPBody = new StringWriter();
+ element.serializeAndConsume(bufferedSOAPBody, format2);
+ MIMEOutputUtils.writeSOAPWithAttachmentsMessage(bufferedSOAPBody, bytesOut, msgCtxt.getAttachmentMap(), format2);
+ } else {
+ 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 {
+ Object gzip = msgCtxt.getOptions().getProperty(HTTPConstants.MC_GZIP_REQUEST);
+ if (gzip != null && JavaUtils.isTrueExplicitly(gzip) && chunked) {
+ out = new GZIPOutputStream(out);
+ }
+ try {
+ if (chunked) {
+ this.handleOMOutput(out, doingMTOM);
+ } else {
+ if (bytes == null) {
+ bytes = writeBytes();
+ }
+ out.write(bytes);
+ }
+ if (out instanceof GZIPOutputStream) {
+ ((GZIPOutputStream) out).finish();
+ }
+ 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 (bytes == null) {
+ bytes = writeBytes();
+ }
+ return bytes.length;
+ }
+ } catch (AxisFault e) {
+ return -1;
+ }
+ }
+
+ public String getContentType() {
+ String encoding = format.getCharSetEncoding();
+ String contentType = format.getContentType();
+ 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;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org