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 th...@apache.org on 2005/08/06 10:38:18 UTC
svn commit: r230539 - in /webservices/axis/trunk/java/modules:
core/src/org/apache/axis2/transport/http/ integration/
integration/test/org/apache/axis2/swa/
xml/src/org/apache/axis2/attachments/ xml/src/org/apache/axis2/om/impl/
Author: thilina
Date: Sat Aug 6 01:37:46 2005
New Revision: 230539
URL: http://svn.apache.org/viewcvs?rev=230539&view=rev
Log:
Provided Character Encoding support for MTOM & SwA...
Included the MTOM test cases again...
(Pls give bit more care about MTOM & SwA when providing new features, rather than excluding the test cases...)
Fixed a bug in content-type handling for Character encoding
Added:
webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/swa/swainput.bin
Removed:
webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/swa/swainput.txt
Modified:
webservices/axis/trunk/java/modules/core/src/org/apache/axis2/transport/http/HTTPTransportUtils.java
webservices/axis/trunk/java/modules/integration/project.xml
webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/swa/EchoRawSwATest.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/om/impl/MIMEOutputUtils.java
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=230539&r1=230538&r2=230539&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 Sat Aug 6 01:37:46 2005
@@ -224,8 +224,15 @@
//If there are spaces around the '=' sign
int indexOfEq = contentType.indexOf("=", index);
- String value =
- (contentType.substring(indexOfEq + 1, contentType.length())).trim();
+ //There can be situations where "charset" is not the last parameter of the Content-Type header
+ int indexOfSemiColon = contentType.indexOf(";", indexOfEq);
+ String value;
+ if (indexOfSemiColon > 0) {
+ value = (contentType.substring(indexOfEq + 1, indexOfSemiColon));
+ } else {
+ value = (contentType.substring(indexOfEq + 1, contentType.length()))
+ .trim();
+ }
//There might be "" around the value - if so remove them
value = value.replaceAll("\"", "");
@@ -319,24 +326,19 @@
Constants.Configuration.CACHE_ATTACHMENTS)));
String attachmentRepoDir = null;
if (fileCacheForAttachments) {
- attachmentRepoDir =
- (String) msgContext.getProperty(
- Constants.Configuration.ATTACHMENT_TEMP_DIR);
+ attachmentRepoDir = (String) msgContext
+ .getProperty(Constants.Configuration.ATTACHMENT_TEMP_DIR);
}
- MIMEHelper mimeHelper =
- new MIMEHelper(
- inStream,
- contentTypeString,
- fileCacheForAttachments,
- attachmentRepoDir);
-
- String charSetEnc = getCharSetEncoding(contentTypeString);
-
+ MIMEHelper mimeHelper = new MIMEHelper(inStream, contentTypeString,
+ fileCacheForAttachments, attachmentRepoDir);
+
XMLStreamReader reader = XMLInputFactory.newInstance()
- .createXMLStreamReader(
- new BufferedReader(new InputStreamReader(mimeHelper
- .getSOAPPartInputStream(), charSetEnc)));
+ .createXMLStreamReader(
+ new BufferedReader(new InputStreamReader(mimeHelper
+ .getSOAPPartInputStream(),
+ getCharSetEncoding(mimeHelper
+ .getSOAPPartContentType()))));
/*
* put a reference to Attachments in to the message context
@@ -396,4 +398,4 @@
msgContext.setDoingMTOM(doMTOM);
return doMTOM;
}
-}
\ No newline at end of file
+}
Modified: webservices/axis/trunk/java/modules/integration/project.xml
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/integration/project.xml?rev=230539&r1=230538&r2=230539&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/integration/project.xml (original)
+++ webservices/axis/trunk/java/modules/integration/project.xml Sat Aug 6 01:37:46 2005
@@ -174,34 +174,9 @@
<!-- <exclude>**/*EchoRawXMLChunckedTest.java</exclude> -->
<exclude>**org/apache/axis2/mail/*.java</exclude>
<exclude>**/*EchoRawSwATest.java</exclude>
- <exclude>**/*EchoRawMTOMTest.java</exclude>
- <exclude>**/*EchoRawMTOMCommonsChunkingTest.java</exclude>
+
<!-- <exclude>**/*GroovyServiceTest.java</exclude>-->
-
- <!--
- <exclude>**/*EchoRawMTOMTest.java</exclude>
- <exclude>**/*EchoRawMTOMLoadTest.java</exclude>
- <exclude>**/*EchoRawMTOMToBase64Test.java</exclude>
-
- <exclude>**/*MTOMCommonsChunkingTest.java</exclude>
- <exclude>**/OneWayRawXMLTest.java</exclude>
-
- -->
-
- <!--
- <exclude>**/*SOAP12Test.java</exclude>
- <exclude>**/*SOAP12TestWithFaults.java</exclude>
- <exclude>**/*FaultHandlingTest.java</exclude>
-
-
- <exclude>**/*MailEchoRawXMLTest.java</exclude>
- <exclude>**/*MailOneWayRawXMLTest.java</exclude>
- <exclude>**/*MailRequestResponseRawXMLTest.java</exclude>
- <exclude>**/*CommonsHTTPEchoRawXMLTest.java</exclude>
- <exclude>**/*EchoRawMTOMTest.java</exclude>
- <exclude>**/*EchoRawMTOMLoadTest.java</exclude>
- <exclude>**/*EchoRawMTOMToBase64Test.java</exclude> -->
</excludes>
<includes>
<include>**/*Test.java</include>
Modified: webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/swa/EchoRawSwATest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/swa/EchoRawSwATest.java?rev=230539&r1=230538&r2=230539&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/swa/EchoRawSwATest.java (original)
+++ webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/swa/EchoRawSwATest.java Sat Aug 6 01:37:46 2005
@@ -20,7 +20,10 @@
* @author <a href="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
*/
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
@@ -44,9 +47,6 @@
import org.apache.wsdl.WSDLService;
public class EchoRawSwATest extends TestCase {
- private EndpointReference targetEPR = new EndpointReference(
- "http://127.0.0.1:" + (UtilServer.TESTING_PORT)
- + "/axis/services/EchoSwAService/echoAttachment");
private Log log = LogFactory.getLog(getClass());
@@ -98,21 +98,31 @@
Socket socket = new Socket("127.0.0.1", 5555);
OutputStream outStream = socket.getOutputStream();
InputStream inStream = socket.getInputStream();
- InputStream requestMsgInStream = getResourceAsStream("org/apache/axis2/swa/swainput.txt");
+ InputStream requestMsgInStream = getResourceAsStream("org/apache/axis2/swa/swainput.bin");
int data;
while ((data = requestMsgInStream.read())!=-1) {
outStream.write(data);
}
outStream.flush();
socket.shutdownOutput();
- byte[] i = new byte[1];
- StringBuffer stringBuffer = new StringBuffer();
- while ((i[0] = (byte)inStream.read()) != -1) {
- stringBuffer.append(new String(i));
+ BufferedReader reader = new BufferedReader( new InputStreamReader(socket.getInputStream()));
+ StringBuffer sb = new StringBuffer();
+ String response = reader.readLine();
+ while( null != response ) {
+ sb.append(response.trim());
+ response = reader.readLine();
}
- socket.close();
- assertTrue(stringBuffer.toString().indexOf("Apache Axis2 - The NExt Generation Web Services Engine")>0);
- assertTrue(stringBuffer.toString().indexOf("multipart/related")>0);
+// int x=0;
+// BufferedInputStream buffredStream = new BufferedInputStream(inStream);
+// socket.setKeepAlive(true);
+// while ((i[0] = (byte)buffredStream.read()) > -1) {
+// stringBuffer.append(new String(i));
+// System.out.println(x);
+// x++;
+// }
+ // socket.close();
+ assertTrue(sb.toString().indexOf("Apache Axis2 - The NExt Generation Web Services Engine")>0);
+ assertTrue(sb.toString().indexOf("multipart/related")>0);
}
private InputStream getResourceAsStream(String path) {
Added: webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/swa/swainput.bin
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/swa/swainput.bin?rev=230539&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/swa/swainput.bin (added)
+++ webservices/axis/trunk/java/modules/integration/test/org/apache/axis2/swa/swainput.bin Sat Aug 6 01:37:46 2005
@@ -0,0 +1,24 @@
+POST /axis/services/EchoSwAService/echoAttachment HTTP/1.0
+Content-Type: multipart/related; type="text/xml"; start="<9D645C8EBB837CE54ABD027A3659535D>"; boundary="----=_Part_0_1977511.1123163571138"
+Accept: application/soap+xml, application/dime, multipart/related, text/*
+User-Agent: Axis/1.2.1
+Host: 127.0.0.1:8081
+Cache-Control: no-cache
+Pragma: no-cache
+SOAPAction: ""
+
+
+------=_Part_0_1977511.1123163571138
+Content-Type: text/xml; charset=UTF-8
+Content-Transfer-Encoding: binary
+Content-Id: <9D645C8EBB837CE54ABD027A3659535D>
+
+<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><echoAttachment xmlns=""><source href="cid:3936AE19FBED55AE4620B81C73BDD76E" xmlns=""/></echoAttachment></soapenv:Body></soapenv:Envelope>
+------=_Part_0_1977511.1123163571138
+Content-Type: text/plain
+Content-Transfer-Encoding: binary
+Content-Id: <3936AE19FBED55AE4620B81C73BDD76E>
+
+Apache Axis2 - The NExt Generation Web Services Engine
+
+------=_Part_0_1977511.1123163571138--
Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java?rev=230539&r1=230538&r2=230539&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java Sat Aug 6 01:37:46 2005
@@ -188,6 +188,27 @@
* content-type
*/
public InputStream getSOAPPartInputStream() throws OMException {
+ DataHandler dh;
+ try {
+ dh = getDataHandler(getSOAPPartContentID());
+ if (dh == null) {
+ throw new OMException(
+ "Mandatory Root MIME part containing the SOAP Envelope is missing");
+ }
+ return dh.getInputStream();
+ } catch (IOException e) {
+ throw new OMException(
+ "Problem with DataHandler of the Root Mime Part. " + e);
+ }
+ }
+
+ /**
+ * @return the Content-ID of the SOAP part It'll be the value Start
+ * Parameter of Content-Type header if given in the Content type of
+ * the MIME message. Else it'll be the content-id of the first MIME
+ * part of the MIME message
+ */
+ private String getSOAPPartContentID() {
String rootContentID = contentType.getParameter("start");
// to handle the Start parameter not mentioned situation
@@ -208,59 +229,61 @@
if (rootContentID.substring(0, 3).equalsIgnoreCase("cid")) {
rootContentID = rootContentID.substring(4);
}
- DataHandler dh;
+ return rootContentID;
+ }
+
+ public String getSOAPPartContentType() {
+ Part soapPart = getPart(getSOAPPartContentID());
try {
- dh = getDataHandler(rootContentID);
- if (dh == null) {
- throw new OMException(
- "Mandatory Root MIME part containing the SOAP Envelope is missing");
- }
- return dh.getInputStream();
- } catch (IOException e) {
- throw new OMException(
- "Problem with DataHandler of the Root Mime Part. " + e);
+ return soapPart.getContentType();
+ } catch (MessagingException e) {
+ throw new OMException(e);
}
}
/**
* @param blobContentID
+ * (without the surrounding angle brackets and "cid:" prefix)
* @return The DataHandler of the mime part refered by the content-Id
* @throws OMException
+ */
+ public DataHandler getDataHandler(String blobContentID) throws OMException {
+
+ try {
+ return getPart(blobContentID).getDataHandler();
+ } catch (MessagingException e) {
+ throw new OMException("Problem with Mime Body Part No " + partIndex
+ + ". ", e);
+ }
+
+ }
+
+ /**
+ * @param blobContentID
+ * @return The Part refered by the content-Id
+ * @throws OMException
* @see First checks whether the MIME part is already parsed by checking the
* parts HashMap. If it is not parsed yet then call the getNextPart()
* till we find the required part.
*/
- public DataHandler getDataHandler(String blobContentID) throws OMException {
-
+ public Part getPart(String blobContentID) {
Part bodyPart;
boolean attachmentFound = false;
-
if (bodyPartsMap.containsKey(blobContentID)) {
bodyPart = (Part) bodyPartsMap.get(blobContentID);
- attachmentFound = true;
- DataHandler dh;
- try {
- dh = bodyPart.getDataHandler();
- } catch (MessagingException e) {
- throw new OMException("Problem with Mime Body Part No "
- + partIndex + ". " + e);
- }
- return dh;
+ return bodyPart;
} else {
- try {
- while (true) {
- bodyPart = this.getNextPart();
- if (bodyPart == null) {
- return null;
- }
- if (bodyPartsMap.containsKey(blobContentID)) {
- bodyPart = (Part) bodyPartsMap.get(blobContentID);
- DataHandler dh = bodyPart.getDataHandler();
- return dh;
- }
+ //This loop will be terminated by the Exceptions thrown if the Mime
+ // part searching was not found
+ while (true) {
+ bodyPart = this.getNextPart();
+ if (bodyPart == null) {
+ return null;
+ }
+ if (bodyPartsMap.containsKey(blobContentID)) {
+ bodyPart = (Part) bodyPartsMap.get(blobContentID);
+ return bodyPart;
}
- } catch (MessagingException e) {
- throw new OMException("Invalid Mime Message " + e);
}
}
}
@@ -271,64 +294,10 @@
}
/**
- * @return This will return the next available MIME part in the stream.
- * @throws OMException
- * if Stream ends while reading the next part...
- */
- private Part getPart() throws OMException {
- // endOfStreamReached will be set to true if the message ended in MIME
- // Style having "--" suffix with the last mime boundary
- if (endOfStreamReached)
- throw new OMException(
- "Referenced MIME part not found.End of Stream reached.");
-
- Part part = null;
- MIMEBodyPartInputStream partStream;
- partStream = new MIMEBodyPartInputStream(pushbackInStream, boundary,
- this);
- try {
- if (fileCacheEnable) {
- try {
- part = new PartOnFile(partStream, attachmentRepoDir);
- } catch (Exception e) {
- throw new OMException("Error creating temporary File." + e);
- }
- } else {
- part = new PartOnMemory(partStream);
- }
- // This will take care if stream ended without having MIME
- // message terminator
- if (part.getSize() <= 0) {
- throw new OMException(
- "Referenced MIME part not found.End of Stream reached.");
- }
- } catch (MessagingException e) {
- throw new OMException(e);
- }
- partIndex++;
- return part;
- }
-
- /**
- * @return the Root MIME part which contains the SOAP envelope
- * @throws OMException
- */
- private Part getRootMimeBodyPart() throws OMException {
- Part rootPart;
- if (bodyPartsMap.isEmpty()) {
- rootPart = getPart();
- bodyPartsMap.put(ROOT_PART, rootPart);
- } else {
- rootPart = (Part) bodyPartsMap.get(ROOT_PART);
- }
- return rootPart;
- }
-
- /**
* @return the Next valid MIME part + store the Part in the Parts List
* @throws OMException
- * throw if cotent id is null or if two MIME parts contain the same
- * content-ID & the exceptions throws by getPart()
+ * throw if cotent id is null or if two MIME parts contain the
+ * same content-ID & the exceptions throws by getPart()
*/
private Part getNextPart() throws OMException {
Part nextPart;
@@ -367,5 +336,44 @@
}
} else
return null;
+ }
+
+ /**
+ * @return This will return the next available MIME part in the stream.
+ * @throws OMException
+ * if Stream ends while reading the next part...
+ */
+ private Part getPart() throws OMException {
+ // endOfStreamReached will be set to true if the message ended in MIME
+ // Style having "--" suffix with the last mime boundary
+ if (endOfStreamReached)
+ throw new OMException(
+ "Referenced MIME part not found.End of Stream reached.");
+
+ Part part = null;
+ MIMEBodyPartInputStream partStream;
+ partStream = new MIMEBodyPartInputStream(pushbackInStream, boundary,
+ this);
+ try {
+ if (fileCacheEnable) {
+ try {
+ part = new PartOnFile(partStream, attachmentRepoDir);
+ } catch (Exception e) {
+ throw new OMException("Error creating temporary File." + e);
+ }
+ } else {
+ part = new PartOnMemory(partStream);
+ }
+ // This will take care if stream ended without having MIME
+ // message terminator
+ if (part.getSize() <= 0) {
+ throw new OMException(
+ "Referenced MIME part not found.End of Stream reached.");
+ }
+ } catch (MessagingException e) {
+ throw new OMException(e);
+ }
+ partIndex++;
+ return part;
}
}
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=230539&r1=230538&r2=230539&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 Sat Aug 6 01:37:46 2005
@@ -50,12 +50,10 @@
"text/xml");
MimeBodyPart rootMimeBodyPart = new MimeBodyPart();
rootMimeBodyPart.setDataHandler(dh);
-
-
rootMimeBodyPart.addHeader("content-type",
"application/xop+xml; charset=" + charSetEncoding +
- "; type=\"text/xml; charset=" + charSetEncoding + "\"");
+ "; type=\"application/soap+xml;\"");
rootMimeBodyPart.addHeader("content-transfer-encoding", "binary");
rootMimeBodyPart.addHeader("content-id","<"+contentId+">");