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 ru...@apache.org on 2005/07/29 04:59:54 UTC
svn commit: r226327 - in /webservices/axis/trunk/java/modules:
core/src/org/apache/axis2/context/ core/src/org/apache/axis2/transport/
core/src/org/apache/axis2/transport/http/ xml/src/org/apache/axis2/om/impl/
xml/test/org/apache/axis2/om/
Author: ruchithf
Date: Thu Jul 28 19:57:52 2005
New Revision: 226327
URL: http://svn.apache.org/viewcvs?rev=226327&view=rev
Log:
Changes to provide differnt character encoding schmes and removed hard coding
Modified:
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/AbstractTransportSender.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/AxisServlet.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportSender.java
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java?rev=226327&r1=226326&r2=226327&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/context/MessageContext.java Thu Jul 28 19:57:52 2005
@@ -52,6 +52,24 @@
* Field CHARACTER_SET_ENCODING
*/
public static final String CHARACTER_SET_ENCODING = "CHARACTER_SET_ENCODING";
+
+ /**
+ * Field UTF_8
+ * This is the 'utf-8' value for CHARACTER_SET_ENCODING property
+ */
+ public static final String UTF_8 = "utf-8";
+
+ /**
+ * Field UTF_8
+ * This is the 'utf-8' value for CHARACTER_SET_ENCODING property
+ */
+ public static final String UTF_16 = "utf-16";
+
+ /**
+ * Field DEFAULT_CHAR_SET_ENCODING
+ * This is the default value for CHARACTER_SET_ENCODING property
+ */
+ public static final String DEFAULT_CHAR_SET_ENCODING = UTF_8;
/**
* Field TRANSPORT_SUCCEED
@@ -385,6 +403,7 @@
public MessageInformationHeaders getMessageInformationHeaders() {
return messageInformationHeaders;
}
+
/**
* @return
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/AbstractTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/AbstractTransportSender.java?rev=226327&r1=226326&r2=226327&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/AbstractTransportSender.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/AbstractTransportSender.java Thu Jul 28 19:57:52 2005
@@ -132,8 +132,12 @@
if (outputMessage != null) {
try {
- omOutput.setOutputStream(out, msgContext.isDoingMTOM());
- outputMessage.serialize(omOutput);
+ //Pick the char set encoding from the msgContext
+ String charSetEnc = (String) msgContext
+ .getProperty(MessageContext.CHARACTER_SET_ENCODING);
+ omOutput.setOutputStream(out, msgContext.isDoingMTOM(),
+ charSetEnc);
+ outputMessage.serialize(omOutput);
omOutput.flush();
out.flush();
} catch (Exception e) {
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/AxisServlet.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/AxisServlet.java?rev=226327&r1=226326&r2=226327&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/AxisServlet.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/AxisServlet.java Thu Jul 28 19:57:52 2005
@@ -80,7 +80,7 @@
protected void doGet(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse)
throws ServletException, IOException {
- httpServletResponse.setContentType("text/xml; charset=utf-8");
+
MessageContext msgContext = null;
OutputStream out = null;
try {
@@ -124,6 +124,9 @@
if (!processed) {
lister.handle(httpServletRequest, httpServletResponse, out);
}
+
+ //TODO: Change this to actual request's value
+ httpServletResponse.setContentType("text/xml; charset=utf-8");
} catch (AxisFault e) {
if (msgContext != null) {
msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
@@ -171,7 +174,7 @@
new ServletBasedOutTransportInfo(res));
msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, getTransportHeaders(req));
- res.setContentType("text/xml; charset=utf-8");
+
HTTPTransportUtils.processHTTPPostRequest(msgContext,
req.getInputStream(),
res.getOutputStream(),
@@ -179,8 +182,15 @@
req.getHeader(HTTPConstants.HEADER_SOAP_ACTION),
req.getRequestURL().toString(),
configContext);
+
Object contextWritten =
msgContext.getOperationContext().getProperty(Constants.RESPONSE_WRITTEN);
+
+ //Getting the
+ res.setContentType("text/xml; charset="+
+ (String) msgContext
+ .getProperty(MessageContext.CHARACTER_SET_ENCODING));
+
if (contextWritten == null
|| !Constants.VALUE_TRUE.equals(contextWritten)) {
res.setStatus(HttpServletResponse.SC_ACCEPTED);
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java?rev=226327&r1=226326&r2=226327&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/CommonsHTTPTransportSender.java Thu Jul 28 19:57:52 2005
@@ -98,7 +98,10 @@
} else {
OutputStream out = (OutputStream) msgContext
.getProperty(MessageContext.TRANSPORT_OUT);
- omOutput.setOutputStream(out, false);
+
+ String charSetEnc = (String)msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
+ omOutput.setOutputStream(out, false,charSetEnc);
+
dataOut.serialize(omOutput);
}
msgContext.getOperationContext().setProperty(
@@ -160,6 +163,9 @@
//get the contentLength...
public class AxisRequestEntity implements RequestEntity {
+
+ private String charSetEnc;
+
private OMElement element;
private boolean chuncked;
@@ -169,11 +175,12 @@
private boolean doingMTOM = false;
public AxisRequestEntity(OMElement element, boolean chuncked,
- boolean doingMTOM) {
- this.element = element;
- this.chuncked = chuncked;
- this.doingMTOM = doingMTOM;
- }
+ boolean doingMTOM, String charSetEncoding) {
+ this.element = element;
+ this.chuncked = chuncked;
+ this.doingMTOM = doingMTOM;
+ this.charSetEnc = charSetEncoding;
+ }
public boolean isRepeatable() {
return false;
@@ -183,7 +190,7 @@
try {
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
XMLStreamWriter outputWriter = XMLOutputFactory.newInstance()
- .createXMLStreamWriter(bytesOut);
+ .createXMLStreamWriter(bytesOut, charSetEnc);
element.serialize(outputWriter);
outputWriter.flush();
return bytesOut.toByteArray();
@@ -197,7 +204,7 @@
public void writeRequest(OutputStream out) throws IOException{
try {
if (chuncked || doingMTOM) {
- omOutput.setOutputStream(out, doingMTOM);
+ omOutput.setOutputStream(out, doingMTOM, charSetEnc);
element.serialize(omOutput);
omOutput.flush();
out.flush();
@@ -232,7 +239,7 @@
}
public String getContentType() {
- return "text/xml; charset=utf-8";
+ return "text/xml; charset=" + this.charSetEnc;
}
}
@@ -291,7 +298,11 @@
PostMethod postMethod = new PostMethod();
postMethod.setPath(url.getFile());
msgContext.setProperty(HTTP_METHOD, postMethod);
- postMethod.setRequestEntity(new AxisRequestEntity(dataout, chuncked,msgContext.isDoingMTOM()));
+
+ String charEncoding = (String)msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
+
+ postMethod.setRequestEntity(new AxisRequestEntity(dataout, chuncked,msgContext.isDoingMTOM(), charEncoding));
+
if (!httpVersion.equals(HTTPConstants.HEADER_PROTOCOL_10) && chuncked) {
((PostMethod) postMethod).setContentChunked(true);
}
@@ -305,8 +316,13 @@
postMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
omOutput.getOptimizedContentType());
} else {
- postMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
- "text/xml; charset=utf-8");
+ if(charEncoding == null) //Use default encoding scheme
+ postMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
+ "text/xml; charset=" + MessageContext.DEFAULT_CHAR_SET_ENCODING);
+ else
+ postMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
+ "text/xml; charset=" + charEncoding);
+
}
if (httpVersion != null) {
@@ -353,25 +369,32 @@
}
private void transportConfigurationGET(MessageContext msgContext, URL url) throws MalformedURLException, AxisFault, IOException {
- GetMethod getMehtod = new GetMethod();
- getMehtod.setPath(url.getFile());
- getMehtod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
- "text/xml; charset=utf-8");
+ GetMethod getMethod = new GetMethod();
+ getMethod.setPath(url.getFile());
+
+ String charEncoding = (String)msgContext.getProperty(MessageContext.CHARACTER_SET_ENCODING);
+ if(charEncoding == null) //Default encoding scheme
+ getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
+ "text/xml; charset=" + MessageContext.DEFAULT_CHAR_SET_ENCODING);
+ else
+ getMethod.setRequestHeader(HTTPConstants.HEADER_CONTENT_TYPE,
+ "text/xml; charset=" + charEncoding);
+
this.httpClient = new HttpClient();
HostConfiguration hostConfig = this.getHostConfiguration(msgContext, url);
- this.httpClient.executeMethod(hostConfig, getMehtod);
- if (getMehtod.getStatusCode() == HttpStatus.SC_OK) {
+ this.httpClient.executeMethod(hostConfig, getMethod);
+ if (getMethod.getStatusCode() == HttpStatus.SC_OK) {
- InputStream in = getMehtod.getResponseBodyAsStream();
+ InputStream in = getMethod.getResponseBodyAsStream();
if (in == null) {
throw new AxisFault(Messages.getMessage("canNotBeNull","InputStream"));
}
msgContext.getOperationContext().setProperty(MessageContext.TRANSPORT_IN, in);
- } else if (getMehtod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
+ } else if (getMethod.getStatusCode() == HttpStatus.SC_ACCEPTED) {
return;
} else {
- throw new AxisFault(Messages.getMessage("transportError",String.valueOf(getMehtod.getStatusCode()),getMehtod.getResponseBodyAsString())); }
+ throw new AxisFault(Messages.getMessage("transportError",String.valueOf(getMethod.getStatusCode()),getMethod.getResponseBodyAsString())); }
}
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java?rev=226327&r1=226326&r2=226327&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPConstants.java Thu Jul 28 19:57:52 2005
@@ -1,3 +1,4 @@
+
/*
* Copyright 2004,2005 The Apache Software Foundation.
*
@@ -68,6 +69,11 @@
* Field HEADER_PROTOCOL_V11
*/
public static final String HEADER_PROTOCOL_V11 = "1.1".intern();
+
+ /**
+ * Field CHAR_SET_ENCODING
+ */
+ public static String CHAR_SET_ENCODING = "charset";
/**
* Field HEADER_POST
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportSender.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportSender.java?rev=226327&r1=226326&r2=226327&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportSender.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportSender.java Thu Jul 28 19:57:52 2005
@@ -47,76 +47,81 @@
private String httpVersion = HTTPConstants.HEADER_PROTOCOL_10;
public static final String TRANSPORT_SENDER_INFO = "TRANSPORT_SENDER_INFO";
- protected void writeTransportHeaders(OutputStream out,
- URL url,
- MessageContext msgContext,
- int contentLength)
- throws AxisFault {
- try {
-
- String soapActionString = msgContext.getSoapAction();
- if (soapActionString == null || soapActionString.length() == 0) {
- soapActionString = msgContext.getWSAAction();
- }
- if (soapActionString == null) {
- soapActionString = "";
- }
-
- boolean doMTOM = msgContext.isDoingMTOM();
- StringBuffer buf = new StringBuffer();
- buf.append(HTTPConstants.HEADER_POST).append(" ");
- buf.append(url.getFile()).append(" ").append(httpVersion).append(
- "\n");
- if (doMTOM) {
- buf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(": ")
- .append(omOutput.getOptimizedContentType())
- .append("\n");
- } else {
- String nsURI = msgContext.getEnvelope().getNamespace().getName();
- if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(nsURI)) {
- buf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(": ")
- .append(SOAP12Constants.SOAP_12_CONTENT_TYPE);
- buf.append("; charset=utf-8\n");
- } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(
- nsURI)) {
- buf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(
- ": text/xml; charset=utf-8\n");
- } else {
- throw new AxisFault(
- "Unknown SOAP Version. Current Axis handles only SOAP 1.1 and SOAP 1.2 messages");
- }
-
- }
-
- buf.append(HTTPConstants.HEADER_ACCEPT).append(
- ": application/soap+xml, application/dime, multipart/related, text/*\n");
- buf.append(HTTPConstants.HEADER_HOST).append(": ").append(
- url.getHost())
- .append("\n");
- buf.append(HTTPConstants.HEADER_CACHE_CONTROL).append(
- ": no-cache\n");
- buf.append(HTTPConstants.HEADER_PRAGMA).append(": no-cache\n");
- if (chuncked) {
- buf
- .append(HTTPConstants.HEADER_TRANSFER_ENCODING)
- .append(": ")
- .append(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)
- .append("\n");
- }
- if (!chuncked && !msgContext.isDoingMTOM()) {
- buf.append(HTTPConstants.HEADER_CONTENT_LENGTH).append(
- ": " + contentLength + "\n");
- }
- if (!msgContext.isDoingREST()) {
- buf.append("SOAPAction: \"" + soapActionString + "\"\n");
- }
- buf.append("\n");
- out.write(buf.toString().getBytes());
- } catch (IOException e) {
- throw new AxisFault(e);
- }
- }
+ protected void writeTransportHeaders(OutputStream out, URL url,
+ MessageContext msgContext, int contentLength) throws AxisFault {
+ try {
+ String soapActionString = msgContext.getSoapAction();
+ if (soapActionString == null || soapActionString.length() == 0) {
+ soapActionString = msgContext.getWSAAction();
+ }
+ if (soapActionString == null) {
+ soapActionString = "";
+ }
+
+ boolean doMTOM = msgContext.isDoingMTOM();
+ StringBuffer buf = new StringBuffer();
+ buf.append(HTTPConstants.HEADER_POST).append(" ");
+ buf.append(url.getFile()).append(" ").append(httpVersion).append(
+ "\n");
+
+ //Get the char set encoding if set
+ String charSetEnc = (String) msgContext
+ .getProperty(MessageContext.CHARACTER_SET_ENCODING);
+ if (charSetEnc == null)
+ charSetEnc = MessageContext.DEFAULT_CHAR_SET_ENCODING;
+
+ if (doMTOM) {
+ buf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(": ")
+ .append(omOutput.getOptimizedContentType())
+ .append("\n");
+ } else {
+ String nsURI = msgContext.getEnvelope().getNamespace()
+ .getName();
+
+ if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(nsURI)) {
+ buf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(": ")
+ .append(SOAP12Constants.SOAP_12_CONTENT_TYPE);
+ buf.append("; charset=" + charSetEnc + "\n");
+ } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI
+ .equals(nsURI)) {
+ buf.append(HTTPConstants.HEADER_CONTENT_TYPE).append(
+ ": text/xml; charset=" + charSetEnc + "\n");
+ } else {
+ throw new AxisFault(
+ "Unknown SOAP Version. Current Axis handles only SOAP 1.1 and SOAP 1.2 messages");
+ }
+
+ }
+
+ buf
+ .append(HTTPConstants.HEADER_ACCEPT)
+ .append(
+ ": application/soap+xml, application/dime, multipart/related, text/*\n");
+ buf.append(HTTPConstants.HEADER_HOST).append(": ").append(
+ url.getHost()).append("\n");
+ buf.append(HTTPConstants.HEADER_CACHE_CONTROL).append(
+ ": no-cache\n");
+ buf.append(HTTPConstants.HEADER_PRAGMA).append(": no-cache\n");
+ if (chuncked) {
+ buf.append(HTTPConstants.HEADER_TRANSFER_ENCODING).append(": ")
+ .append(HTTPConstants.HEADER_TRANSFER_ENCODING_CHUNKED)
+ .append("\n");
+ }
+ if (!chuncked && !msgContext.isDoingMTOM()) {
+ buf.append(HTTPConstants.HEADER_CONTENT_LENGTH).append(
+ ": " + contentLength + "\n");
+ }
+ if (!msgContext.isDoingREST()) {
+ buf.append("SOAPAction: \"" + soapActionString + "\"\n");
+ }
+ buf.append("\n");
+ out.write(buf.toString().getBytes());
+ } catch (IOException e) {
+ throw new AxisFault(e);
+ }
+ }
+
public void finalizeSendWithOutputStreamFromIncomingConnection(
MessageContext msgContext,
OutputStream out) {
Modified: webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java?rev=226327&r1=226326&r2=226327&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java (original)
+++ webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java Thu Jul 28 19:57:52 2005
@@ -17,15 +17,31 @@
*/
package org.apache.axis2.transport.http;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
-import org.apache.axis2.addressing.AddressingConstants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.attachments.MIMEHelper;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.engine.AxisEngine;
-import org.apache.axis2.om.*;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMException;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMNode;
+import org.apache.axis2.om.OMText;
import org.apache.axis2.om.impl.llom.OMNamespaceImpl;
import org.apache.axis2.om.impl.llom.builder.StAXBuilder;
import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
@@ -39,94 +55,133 @@
import org.apache.axis2.soap.impl.llom.soap12.SOAP12Constants;
import org.apache.axis2.util.Utils;
-import javax.xml.parsers.FactoryConfigurationError;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import java.io.*;
-import java.util.Iterator;
-import java.util.Map;
-
public class HTTPTransportUtils {
- public static void processHTTPPostRequest(MessageContext msgContext,
- InputStream in,
- OutputStream out,
- String contentType,
- String soapActionHeader,
- String requestURI,
- ConfigurationContext configurationContext)
+ public static void processHTTPPostRequest(
+ MessageContext msgContext,
+ InputStream in,
+ OutputStream out,
+ String contentType,
+ String soapActionHeader,
+ String requestURI,
+ ConfigurationContext configurationContext)
throws AxisFault {
- try {
+ try {
- //remove the starting and trailing " from the SOAP Action
- if (soapActionHeader != null && soapActionHeader.startsWith("\"") && soapActionHeader.endsWith("\"")) {
+ //remove the starting and trailing " from the SOAP Action
+ if (soapActionHeader != null && soapActionHeader.startsWith("\"") && soapActionHeader.endsWith("\"")) {
- soapActionHeader = soapActionHeader.substring(1, soapActionHeader.length() - 1);
- }
- //fill up the Message Contexts
- msgContext.setWSAAction(soapActionHeader);
- msgContext.setSoapAction(soapActionHeader);
- msgContext.setTo(new EndpointReference(requestURI));
- msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
- msgContext.setServerSide(true);
-
- SOAPEnvelope envelope = null;
- StAXBuilder builder = null;
- if (contentType != null) {
- if (contentType.indexOf(HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1) {
- //It is MTOM
- builder = selectBuilderForMIME(msgContext, in, contentType);
- envelope = (SOAPEnvelope) builder.getDocumentElement();
- } else {
- Reader reader = new InputStreamReader(in);
- XMLStreamReader xmlreader =
- XMLInputFactory.newInstance().createXMLStreamReader(reader);
- if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
- //it is SOAP 1.2
- builder = new StAXSOAPModelBuilder(xmlreader, SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ soapActionHeader = soapActionHeader.substring(1, soapActionHeader.length() - 1);
+ }
+ //fill up the Message Contexts
+ msgContext.setWSAAction(soapActionHeader);
+ msgContext.setSoapAction(soapActionHeader);
+ msgContext.setTo(new EndpointReference(requestURI));
+ msgContext.setProperty(MessageContext.TRANSPORT_OUT, out);
+ msgContext.setServerSide(true);
+
+
+ SOAPEnvelope envelope = null;
+ StAXBuilder builder = null;
+ if (contentType != null) {
+ if (contentType.indexOf(HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1) {
+ //It is MTOM
+ builder = selectBuilderForMIME(msgContext, in, contentType);
envelope = (SOAPEnvelope) builder.getDocumentElement();
- } else if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
- //it is SOAP 1.1
- Object enable = msgContext.getProperty(Constants.Configuration.ENABLE_REST);
- if ((soapActionHeader == null || soapActionHeader.length() == 0)
- && Constants.VALUE_TRUE.equals(enable)) {
- //If the content Type is text/xml (BTW which is the SOAP 1.1 Content type ) and
- //the SOAP Action is absent it is rest !!
- msgContext.setDoingREST(true);
- SOAPFactory soapFactory = new SOAP11Factory();
- builder = new StAXOMBuilder(xmlreader);
- builder.setOmbuilderFactory(soapFactory);
- envelope = soapFactory.getDefaultEnvelope();
- envelope.getBody().addChild(builder.getDocumentElement());
+ } else {
+ Reader reader = new InputStreamReader(in);
+
+ XMLStreamReader xmlreader;
+ //Figure out the char set encoding and create the reader
+
+ //If charset is not specified
+ if(contentType.indexOf(HTTPConstants.CHAR_SET_ENCODING) == -1) {
+ xmlreader = XMLInputFactory
+ .newInstance()
+ .createXMLStreamReader(
+ in,
+ MessageContext.DEFAULT_CHAR_SET_ENCODING);
+ //Set the encoding scheme in the message context
+ msgContext.setProperty(
+ MessageContext.CHARACTER_SET_ENCODING,
+ MessageContext.DEFAULT_CHAR_SET_ENCODING);
} else {
- builder = new StAXSOAPModelBuilder(xmlreader, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ //get the type of char encoding
+ String charSetEnc = getCharSetEncoing(contentType);
+ xmlreader = XMLInputFactory.newInstance().createXMLStreamReader(in,charSetEnc);
+
+ //Setting the value in msgCtx
+ msgContext.setProperty(MessageContext.CHARACTER_SET_ENCODING,charSetEnc);
+
+ }
+ if (contentType.indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) > -1) {
+ //it is SOAP 1.2
+ builder = new StAXSOAPModelBuilder(xmlreader, SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
envelope = (SOAPEnvelope) builder.getDocumentElement();
+ } else if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
+ //it is SOAP 1.1
+ Object enable = msgContext.getProperty(Constants.Configuration.ENABLE_REST);
+ if ((soapActionHeader == null || soapActionHeader.length() == 0)
+ && Constants.VALUE_TRUE.equals(enable)) {
+ //If the content Type is text/xml (BTW which is the SOAP 1.1 Content type ) and
+ //the SOAP Action is absent it is rest !!
+ msgContext.setDoingREST(true);
+ SOAPFactory soapFactory = new SOAP11Factory();
+ builder = new StAXOMBuilder(xmlreader);
+ builder.setOmbuilderFactory(soapFactory);
+ envelope = soapFactory.getDefaultEnvelope();
+ envelope.getBody().addChild(builder.getDocumentElement());
+ }else{
+ builder = new StAXSOAPModelBuilder(xmlreader, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ envelope = (SOAPEnvelope) builder.getDocumentElement();
+ }
}
+
}
}
- }
+ msgContext.setEnvelope(envelope);
+ AxisEngine engine = new AxisEngine(configurationContext);
+ if (envelope.getBody().hasFault()) {
+ engine.receiveFault(msgContext);
+ } else {
+ engine.receive(msgContext);
+ }
- msgContext.setEnvelope(envelope);
- AxisEngine engine = new AxisEngine(configurationContext);
- if (envelope.getBody().hasFault()) {
- engine.receiveFault(msgContext);
- } else {
- engine.receive(msgContext);
+ } catch (SOAPProcessingException e) {
+ throw new AxisFault(e);
+ } catch (OMException e) {
+ throw new AxisFault(e);
+ } catch (XMLStreamException e) {
+ throw new AxisFault(e);
}
-
- } catch (SOAPProcessingException e) {
- throw new AxisFault(e);
- } catch (OMException e) {
- throw new AxisFault(e);
- } catch (XMLStreamException e) {
- throw new AxisFault(e);
}
- }
+
+ /**
+ * Extracts and returns the character set encoding from the
+ * Content-type header
+ * Example:
+ * Content-Type: text/xml; charset=utf-8
+ * @param contentType
+ */
+ private static String getCharSetEncoing(String contentType) {
+ int index = contentType.indexOf(HTTPConstants.CHAR_SET_ENCODING);
+ //If there are spaces around the '=' sign
+ int indexOfEq = contentType.indexOf("=", index);
+ String value = (contentType.substring(indexOfEq + 1, contentType
+ .length())).trim();
+
+ //There might be "" around the value - if so remove them
+ value = value.replaceAll("\"", "");
+
+ return value.trim();
+
+ }
+
+
public static boolean processHTTPGetRequest(MessageContext msgContext,
InputStream in,
OutputStream out,
Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java?rev=226327&r1=226326&r2=226327&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java Thu Jul 28 19:57:52 2005
@@ -39,7 +39,7 @@
public static void complete(OutputStream outStream,
OutputStream bufferedSoapOutStream, LinkedList binaryNodeList,
- String boundary, String contentId) {
+ String boundary, String contentId, String charSetEncoding) {
try {
startWritingMime(outStream, boundary);
@@ -48,8 +48,11 @@
MimeBodyPart rootMimeBodyPart = new MimeBodyPart();
rootMimeBodyPart.setDataHandler(dh);
+
+
rootMimeBodyPart.addHeader("content-type",
- "application/xop+xml; charset=utf-8; type=\"text/xml; charset=utf-8\"");
+ "application/xop+xml; charset=" + charSetEncoding +
+ "; type=\"text/xml; charset=" + charSetEncoding + "\"");
rootMimeBodyPart.addHeader("content-transfer-encoding", "binary");
rootMimeBodyPart.addHeader("content-id","<"+contentId+">");
@@ -124,7 +127,7 @@
outStream.write(new byte[]{45, 45});
}
- public static String getContentTypeForMime(String boundary, String contentId) {
+ public static String getContentTypeForMime(String boundary, String contentId, String charSetEncoding) {
StringBuffer sb = new StringBuffer();
sb.append("multipart/related");
sb.append("; ");
@@ -135,7 +138,7 @@
sb.append("; ");
sb.append("start=\"<" + contentId + ">\"");
sb.append("; ");
- sb.append("start-info=\"text/xml; charset=utf-8\"");
+ sb.append("start-info=\"text/xml; charset=" + charSetEncoding + "\"");
return sb.toString();
}
Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java?rev=226327&r1=226326&r2=226327&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/OMOutputImpl.java Thu Jul 28 19:57:52 2005
@@ -40,6 +40,14 @@
private String mimeBoundary = null;
private String rootContentId = null;
private int nextid = 0;
+
+ /**
+ * Field DEFAULT_CHAR_SET_ENCODING specifies the default
+ * character encoding scheme to be used
+ */
+ private static final String DEFAULT_CHAR_SET_ENCODING = "utf-8";
+
+ private String charSetEncoding;
public OMOutputImpl() {
}
@@ -48,33 +56,61 @@
this.xmlWriter = xmlWriter;
}
+ /**
+ * This creates a new OMOutputImpl with default encoding
+ * @see OMOutputImpl#DEFAULT_CHAR_SET_ENCODING
+ * @param outStream
+ * @param doOptimize
+ * @throws XMLStreamException
+ * @throws FactoryConfigurationError
+ */
public OMOutputImpl(OutputStream outStream, boolean doOptimize)
throws XMLStreamException, FactoryConfigurationError {
- setOutputStream(outStream, doOptimize);
- }
-
- public void setOutputStream(OutputStream outStream, boolean doOptimize)
- throws XMLStreamException, FactoryConfigurationError {
- this.doOptimize = doOptimize;
- this.outStream = outStream;
- if (doOptimize) {
- bufferedSoapOutStream = new ByteArrayOutputStream();
- xmlWriter =
- XMLOutputFactory.newInstance().createXMLStreamWriter(
- bufferedSoapOutStream);
- binaryNodeList = new LinkedList();
- } else {
- xmlWriter =
- XMLOutputFactory.newInstance().createXMLStreamWriter(
- outStream);
- }
+ setOutputStream(outStream, doOptimize, DEFAULT_CHAR_SET_ENCODING);
}
+
+ /**
+ *
+ * @param outStream
+ * @param doOptimize
+ * @param charSetEncoding
+ * @throws XMLStreamException
+ * @throws FactoryConfigurationError
+ */
+ public OMOutputImpl(OutputStream outStream, boolean doOptimize, String charSetEncoding)
+ throws XMLStreamException, FactoryConfigurationError {
+ setOutputStream(outStream, doOptimize, charSetEncoding);
+ this.charSetEncoding = charSetEncoding;
+ }
+
+ public void setOutputStream(OutputStream outStream, boolean doOptimize,
+ String charSetEncoding) throws XMLStreamException,
+ FactoryConfigurationError {
+
+ this.charSetEncoding = charSetEncoding;
+ this.doOptimize = doOptimize;
+ this.outStream = outStream;
+
+ if (charSetEncoding == null) //Default encoding is UTF-8
+ this.charSetEncoding = DEFAULT_CHAR_SET_ENCODING;
+
+ if (doOptimize) {
+ bufferedSoapOutStream = new ByteArrayOutputStream();
+ xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(
+ bufferedSoapOutStream, this.charSetEncoding);
+ binaryNodeList = new LinkedList();
+ } else {
+ xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(
+ outStream, this.charSetEncoding);
+ }
+ }
public void flush() throws XMLStreamException {
xmlWriter.flush();
if (doOptimize) {
MIMEOutputUtils.complete(outStream, bufferedSoapOutStream,
- binaryNodeList, getMimeBoundary(), getRootContentId());
+ binaryNodeList, getMimeBoundary(), getRootContentId(),
+ this.charSetEncoding);
}
}
@@ -83,8 +119,9 @@
}
public String getOptimizedContentType() {
- return MIMEOutputUtils.getContentTypeForMime(getMimeBoundary(),getRootContentId());
- }
+ return MIMEOutputUtils.getContentTypeForMime(getMimeBoundary(),
+ getRootContentId(), this.getCharSetEncoding());
+ }
public void writeOptimized(OMText node) {
binaryNodeList.add(node);
@@ -99,21 +136,36 @@
}
public String getMimeBoundary() {
- if(mimeBoundary == null) {
- mimeBoundary = "MIMEBoundary" + MIMEOutputUtils.getRandomStringOf18Characters();
- }
- return mimeBoundary;
- }
-
- public String getRootContentId() {
- if(rootContentId == null) {
- rootContentId = "0." + MIMEOutputUtils.getRandomStringOf18Characters() + "@apache.org";
- }
- return rootContentId;
- }
-
- public String getNextContentId() {
- nextid++;
- return nextid + "." + MIMEOutputUtils.getRandomStringOf18Characters() + "@apache.org";
- }
+ if (mimeBoundary == null) {
+ mimeBoundary = "MIMEBoundary"
+ + MIMEOutputUtils.getRandomStringOf18Characters();
+ }
+ return mimeBoundary;
+ }
+
+ public String getRootContentId() {
+ if (rootContentId == null) {
+ rootContentId = "0."
+ + MIMEOutputUtils.getRandomStringOf18Characters()
+ + "@apache.org";
+ }
+ return rootContentId;
+ }
+
+ public String getNextContentId() {
+ nextid++;
+ return nextid + "." + MIMEOutputUtils.getRandomStringOf18Characters()
+ + "@apache.org";
+ }
+
+ /**
+ * Returns the character set endocing scheme If the value of the
+ * charSetEncoding is not set then the default will be returned
+ *
+ * @return
+ */
+ public String getCharSetEncoding() {
+ return (this.charSetEncoding == null) ? DEFAULT_CHAR_SET_ENCODING
+ : this.charSetEncoding;
+ }
}
Modified: webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java?rev=226327&r1=226326&r2=226327&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java (original)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/om/MIMEOutputUtilsTest.java Thu Jul 28 19:57:52 2005
@@ -15,22 +15,23 @@
*/
package org.apache.axis2.om;
-import junit.framework.TestCase;
-import org.apache.axis2.attachments.ByteArrayDataSource;
-import org.apache.axis2.soap.SOAPFactory;
-import org.apache.axis2.om.impl.MIMEOutputUtils;
-import org.apache.axis2.om.impl.OMOutputImpl;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Properties;
import javax.activation.DataHandler;
import javax.mail.MessagingException;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
-import javax.mail.internet.MimePartDataSource;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.apache.axis2.attachments.ByteArrayDataSource;
+import org.apache.axis2.om.impl.MIMEOutputUtils;
+import org.apache.axis2.om.impl.OMOutputImpl;
+import org.apache.axis2.soap.SOAPFactory;
/**
* @author Thilina
@@ -49,7 +50,9 @@
OMOutputImpl omOutput = new OMOutputImpl(null);
boundary = omOutput.getMimeBoundary();
- String contentType = org.apache.axis2.om.impl.MIMEOutputUtils.getContentTypeForMime(boundary,omOutput.getRootContentId());
+ String contentType = org.apache.axis2.om.impl.MIMEOutputUtils
+ .getContentTypeForMime(boundary, omOutput.getRootContentId(),
+ omOutput.getCharSetEncoding());
DataHandler dataHandler;
dataHandler = new DataHandler(new ByteArrayDataSource(byteArray));
OMText textData = factory.createText(dataHandler, true);