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/07/28 15:36:21 UTC
svn commit: r225767 - in /webservices/axis/trunk/java/modules:
samples/src/sample/mtom/interop/client/ samples/test/org/apache/axis2/mtom/
samples/test/org/apache/axis2/swa/ xml/src/org/apache/axis2/attachments/
xml/test-resources/mtom/img/ xml/test/or...
Author: thilina
Date: Thu Jul 28 06:35:54 2005
New Revision: 225767
URL: http://svn.apache.org/viewcvs?rev=225767&view=rev
Log:
Commiting the temporary File storage for attachments & Whitemesa intertop service
Added:
webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/swa/
webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/swa/EchoRawSwATest.java
webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/swa/EchoSwA.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/Part.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/PartOnMemory.java
Modified:
webservices/axis/trunk/java/modules/samples/src/sample/mtom/interop/client/InteropClient.java
webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java
webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMLoadTest.java
webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMTest.java
webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMToBase64Test.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/MIMEHelper.java
webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/PartOnFile.java
webservices/axis/trunk/java/modules/xml/test-resources/mtom/img/test.jpg
webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/attachments/ImageSampleTest.java
Modified: webservices/axis/trunk/java/modules/samples/src/sample/mtom/interop/client/InteropClient.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/sample/mtom/interop/client/InteropClient.java?rev=225767&r1=225766&r2=225767&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/sample/mtom/interop/client/InteropClient.java (original)
+++ webservices/axis/trunk/java/modules/samples/src/sample/mtom/interop/client/InteropClient.java Thu Jul 28 06:35:54 2005
@@ -1,4 +1,4 @@
- /*
+/*
* Copyright 2004,2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
Modified: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java?rev=225767&r1=225766&r2=225767&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java (original)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMCommonsChunkingTest.java Thu Jul 28 06:35:54 2005
@@ -62,17 +62,6 @@
private QName operationName = new QName("echoOMElement");
- private QName transportName = new QName("http://localhost/my",
- "NullTransport");
-
- private String imageInFileName = "img/test.jpg";
-
- private String imageOutFileName = "mtom/img/testOut.jpg";
-
- private AxisConfiguration engineRegistry;
-
- private MessageContext mc;
-
private ServiceContext serviceContext;
private ServiceDescription service;
Modified: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMLoadTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMLoadTest.java?rev=225767&r1=225766&r2=225767&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMLoadTest.java (original)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMLoadTest.java Thu Jul 28 06:35:54 2005
@@ -61,18 +61,12 @@
private QName operationName = new QName("echoOMElement");
- private QName transportName = new QName("http://localhost/my",
- "NullTransport");
-
- private AxisConfiguration engineRegistry;
-
- private MessageContext mc;
-
private ServiceContext serviceContext;
private ServiceDescription service;
+
+ private OMText textData;
- private boolean finish = false;
byte[] expectedByteArray;
@@ -110,11 +104,10 @@
OMElement subData = fac.createOMElement("subData", omNs);
DataHandler dataHandler = new DataHandler(
new ByteArrayDataSource(expectedByteArray));
- OMText textData = new OMTextImpl(dataHandler, true);
- //OMText textData = new OMTextImpl("Thilina Gunarathne");
+ textData = new OMTextImpl(dataHandler, true);
subData.addChild(textData);
data.addChild(subData);
- //System.out.println("Creating blobs "+i);
+
}
rpcWrapEle.addChild(data);
@@ -141,14 +134,13 @@
OMElement ele = (OMElement) result.getFirstChild();
OMElement ele1 = (OMElement) ele.getFirstChild();
OMText binaryNode = (OMText) ele1.getFirstChild();
- DataHandler actualDataHandler = binaryNode.getDataHandler();
- ByteArrayInputStream inStream = (ByteArrayInputStream)actualDataHandler.getContent();
- byte[] actualByteArray = new byte[11];
- inStream.read(actualByteArray);
- assertEquals(expectedByteArray[0],actualByteArray[0]);
- assertEquals(expectedByteArray[0],actualByteArray[0]);
+ compareWithActualOMText(binaryNode);
System.out.println(i);
}
+ }
+ private void compareWithActualOMText(OMText binaryNode)
+ {
+ assertEquals(textData.getText(),binaryNode.getText());
}
}
Modified: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMTest.java?rev=225767&r1=225766&r2=225767&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMTest.java (original)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMTest.java Thu Jul 28 06:35:54 2005
@@ -62,23 +62,10 @@
private QName operationName = new QName("echoOMElement");
- private QName transportName = new QName("http://localhost/my",
- "NullTransport");
-
- private String imageInFileName = "img/test.jpg";
-
- private String imageOutFileName = "mtom/img/testOut.jpg";
-
- private AxisConfiguration engineRegistry;
-
- private MessageContext mc;
-
private ServiceContext serviceContext;
private ServiceDescription service;
- private boolean finish = false;
-
private OMTextImpl expectedTextData;
public EchoRawMTOMTest() {
@@ -152,7 +139,7 @@
actualDH = binaryNode.getDataHandler();
Image actualObject = new JDK13IO().loadImage(actualDH.getDataSource()
.getInputStream());
- FileOutputStream imageOutStream = new FileOutputStream("testout.jpg");
+ FileOutputStream imageOutStream = new FileOutputStream("target/testout.jpg");
new JDK13IO().saveImage("image/jpeg", actualObject, imageOutStream);
}
Modified: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMToBase64Test.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMToBase64Test.java?rev=225767&r1=225766&r2=225767&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMToBase64Test.java (original)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/mtom/EchoRawMTOMToBase64Test.java Thu Jul 28 06:35:54 2005
@@ -58,20 +58,11 @@
private QName operationName = new QName("echoMTOMtoBase64");
- private QName transportName = new QName("http://localhost/my",
- "NullTransport");
-
- private AxisConfiguration engineRegistry;
-
- private MessageContext mc;
-
private ServiceContext serviceContext;
private ServiceDescription service;
OMText expectedTextData;
-
- private boolean finish = false;
public EchoRawMTOMToBase64Test() {
super(EchoRawMTOMToBase64Test.class.getName());
Added: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/swa/EchoRawSwATest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/swa/EchoRawSwATest.java?rev=225767&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/swa/EchoRawSwATest.java (added)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/swa/EchoRawSwATest.java Thu Jul 28 06:35:54 2005
@@ -0,0 +1,124 @@
+/*
+ * 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.swa;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
+ */
+
+import junit.framework.TestCase;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.attachments.utils.ImageDataSource;
+import org.apache.axis2.attachments.utils.JDK13IO;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.description.ServiceDescription;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.Echo;
+import org.apache.axis2.integration.UtilServer;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMText;
+import org.apache.axis2.om.impl.llom.OMTextImpl;
+import org.apache.axis2.soap.SOAPFactory;
+import org.apache.axis2.transport.http.HTTPTransportSender;
+import org.apache.axis2.util.Utils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+import java.awt.*;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.Socket;
+
+public class EchoRawSwATest extends TestCase {
+ private EndpointReference targetEPR = new EndpointReference(
+ AddressingConstants.WSA_TO,
+ "http://127.0.0.1:"
+ + (UtilServer.TESTING_PORT)
+ + "/axis/services/EchoSwAService/echoAttachment");
+
+ private Log log = LogFactory.getLog(getClass());
+
+ private QName serviceName = new QName("EchoSwAService");
+
+ private QName operationName = new QName("echoAttachment");
+
+ private QName transportName = new QName("http://localhost/my",
+ "NullTransport");
+
+ private String imageInFileName = "img/test.jpg";
+
+ private String imageOutFileName = "mtom/img/testOut.jpg";
+
+ private AxisConfiguration engineRegistry;
+
+ private MessageContext mc;
+
+ private ServiceContext serviceContext;
+
+ private ServiceDescription service;
+
+ private boolean finish = false;
+
+ private OMTextImpl expectedTextData;
+
+ public EchoRawSwATest() {
+ super(EchoRawSwATest.class.getName());
+ }
+
+ public EchoRawSwATest(String testName) {
+ super(testName);
+ }
+
+ protected void setUp() throws Exception {
+ UtilServer.start(Constants.TESTING_PATH + "MTOM-enabledRepository");
+ service = Utils.createSimpleService(serviceName, EchoSwA.class.getName(),
+ operationName);
+ UtilServer.deployService(service);
+ serviceContext = UtilServer.getConfigurationContext()
+ .createServiceContext(service.getName());
+ }
+
+ protected void tearDown() throws Exception {
+ UtilServer.unDeployService(serviceName);
+ UtilServer.stop();
+ }
+
+
+ public void testEchoXMLSync() throws Exception {
+ Socket socket = new Socket("127.0.0.1",5555);
+
+ }
+
+ private InputStream getResourceAsStream(String path) {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ return cl.getResourceAsStream(path);
+ }
+ private void compareWithCreatedOMText(OMText actualTextData) {
+ String originalTextValue = expectedTextData.getText();
+ String returnedTextValue = actualTextData.getText();
+ TestCase.assertEquals(returnedTextValue, originalTextValue);
+ }
+}
\ No newline at end of file
Added: webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/swa/EchoSwA.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/swa/EchoSwA.java?rev=225767&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/swa/EchoSwA.java (added)
+++ webservices/axis/trunk/java/modules/samples/test/org/apache/axis2/swa/EchoSwA.java Thu Jul 28 06:35:54 2005
@@ -0,0 +1,60 @@
+/*
+ * 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.swa;
+
+import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
+
+import org.apache.axis2.attachments.MIMEHelper;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.om.OMAttribute;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMText;
+import org.apache.axis2.om.impl.llom.OMTextImpl;
+
+/**
+ * @version $Rev: $ $Date: $
+ */
+
+public class EchoSwA {
+ private MessageContext msgcts;
+ public EchoSwA() {
+ }
+
+ public void init(MessageContext msgcts) {
+ this.msgcts = msgcts;
+
+ }
+
+ public OMElement echoAttachment(OMElement omEle) {
+ OMElement child = (OMElement)omEle.getFirstChild();
+ OMAttribute attr = (OMAttribute)child.getAttributes(new QName("href")).next();
+ String contentID = attr.getValue();
+ MIMEHelper attachment = (MIMEHelper)msgcts.getProperty(MIMEHelper.ATTACHMENTS);
+ contentID = contentID.trim();
+
+ if (contentID.substring(0, 3).equalsIgnoreCase("cid")) {
+ contentID = contentID.substring(4);
+ }
+ DataHandler dataHandler = attachment.getDataHandler(contentID);
+ OMText textNode = new OMTextImpl(dataHandler);
+ omEle.build();
+ child.detach();
+ omEle.addChild(textNode);
+ return omEle;
+ }
+}
\ No newline at end of file
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=225767&r1=225766&r2=225767&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 Thu Jul 28 06:35:54 2005
@@ -17,9 +17,7 @@
import javax.activation.DataHandler;
import javax.mail.MessagingException;
-import javax.mail.Part;
import javax.mail.internet.ContentType;
-import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.ParseException;
import org.apache.axis2.om.OMException;
@@ -32,66 +30,79 @@
* if the Message is MTOM optimised then <code>MTOM_TYPE</code>
*/
public static final String MTOM_TYPE = "application/xop+xml";
-
+
/**
* If the message is Soap with Attachments <code>SwA_TYPE</code>
*/
public static final String SWA_TYPE = "text/xml";
-
+
/**
* <code>rootPart</code> is used as the key for the root BodyPart in the
* Parts HashMap
*/
public static final String ROOT_PART = "SoapPart";
-
+
public static final String ATTACHMENTS = "Attachments";
-
+
/**
* <code>ContentType</code> of the MIME message
*/
ContentType contentType;
-
+
/**
* Mime <code>boundary</code> which seperates mime parts
*/
byte[] boundary;
-
+
/**
* <code>applicationType</code> used to distinguish between MTOM & SWA If
* the message is MTOM optimised type is application/xop+xml If the message
* is SWA, type is ??have to find out
*/
String applicationType = null;
-
+
/**
* <code>pushbackInStream</code> stores the reference to the incoming
* stream A PushbackStream has the ability to "push back" or "unread" one
* byte.
*/
PushbackInputStream pushbackInStream;
-
+
/**
* <code>mimeBodyPartsMap</code> stores the already parsed Mime Body
* Parts. This Map will be keyed using the content-ID's
*/
HashMap bodyPartsMap;
-
+
/**
* <code>partIndex</code>- Number of Mime parts parsed
*/
int partIndex = 0;
-
+
+ /**
+ * <code>endOfStreamReached</code> flag which is to be set by
+ * MIMEBodyPartStream when MIME message terminator is found.
+ */
boolean endOfStreamReached = false;
-
+
String firstPartId = null;
-
+
boolean fileCacheEnable = false;
-
+
String attachmentRepoDir = null;
-
+
+ /**
+ * @param inStream
+ * @param contentTypeString
+ * @param fileCacheEnable
+ * @param attachmentRepoDir
+ * @throws OMException
+ * @see Will move the pointer to the begining of the first MIME part. Will
+ * read till first MIME boundary is found or end of stream reached.
+ */
public MIMEHelper(InputStream inStream, String contentTypeString,
boolean fileCacheEnable, String attachmentRepoDir)
- throws OMException {
+ throws OMException {
this.attachmentRepoDir = attachmentRepoDir;
this.fileCacheEnable = fileCacheEnable;
bodyPartsMap = new HashMap();
@@ -100,17 +111,17 @@
} catch (ParseException e) {
throw new OMException(
"Invalid Content Type Field in the Mime Message"
- + e.toString());
+ + e.toString());
}
// Boundary always have the prefix "--".
this.boundary = ("--" + contentType.getParameter("boundary"))
- .getBytes();
-
- //TODO do we need to wrap InputStream from a BufferedInputStream before
+ .getBytes();
+
+ // do we need to wrap InputStream from a BufferedInputStream before
// wrapping from PushbackStream
pushbackInStream = new PushbackInputStream(inStream,
(this.boundary.length + 2));
-
+
// Move the read pointer to the begining of the first part
// read till the end of first boundary
while (true) {
@@ -124,7 +135,7 @@
value = pushbackInStream.read();
if (value == -1)
throw new OMException(
- "Unexpected End of Stream while searching for first Mime Boundary");
+ "Unexpected End of Stream while searching for first Mime Boundary");
boundaryIndex++;
}
if (boundaryIndex == boundary.length) { // boundary found
@@ -133,19 +144,25 @@
}
} else if ((byte) value == -1) {
throw new OMException(
- "Mime parts not found. Stream ended while searching for the boundary");
+ "Mime parts not found. Stream ended while searching for the boundary");
}
} catch (IOException e1) {
throw new OMException("Stream Error" + e1.toString());
}
}
}
-
+
+ /**
+ * @param inStream
+ * @param contentTypeString
+ * @throws OMException
+ * @see Will set file cache to false
+ */
public MIMEHelper(InputStream inStream, String contentTypeString)
- throws OMException {
+ throws OMException {
this(inStream, contentTypeString, false, null);
}
-
+
/**
* @return whether Message Type is SOAP with Attachments or MTOM optimised
* by checking the application type parameter in the Contant Type
@@ -159,12 +176,12 @@
this.applicationType = SWA_TYPE;
} else {
throw new OMException(
- "Invalid Application type. Support available for MTOM/SOAP 1.2 & SwA/SOAP 1.l only.");
+ "Invalid Application type. Support available for MTOM/SOAP 1.2 & SwA/SOAP 1.l only.");
}
}
return this.applicationType;
}
-
+
/**
* @return the InputStream which includes the SOAP Envelope We assumes that
* the root mime part is always pointed by "start" parameter in
@@ -172,7 +189,7 @@
*/
public InputStream getSOAPPartInputStream() throws OMException {
String rootContentID = contentType.getParameter("start");
-
+
// to handle the Start parameter not mentioned situation
if (rootContentID == null) {
if (partIndex == 0) {
@@ -181,8 +198,7 @@
rootContentID = firstPartId;
} else {
rootContentID.trim();
- // Keep it here till we make sure the two angle brackets are
- // required or not
+
if ((rootContentID.indexOf("<") > -1)
& (rootContentID.indexOf(">") > -1))
rootContentID = rootContentID.substring(1, (rootContentID
@@ -197,7 +213,7 @@
dh = getDataHandler(rootContentID);
if (dh == null) {
throw new OMException(
- "Mandatory Root MIME part containing the SOAP Envelope is missing");
+ "Mandatory Root MIME part containing the SOAP Envelope is missing");
}
return dh.getInputStream();
} catch (IOException e) {
@@ -205,20 +221,20 @@
"Problem with DataHandler of the Root Mime Part. " + e);
}
}
-
+
/**
* @param blobContentID
* @return The DataHandler of the mime part refered by the content-Id
* @throws OMException
- * 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.
+ * @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 {
-
+
Part bodyPart;
boolean attachmentFound = false;
-
+
if (bodyPartsMap.containsKey(blobContentID)) {
bodyPart = (Part) bodyPartsMap.get(blobContentID);
attachmentFound = true;
@@ -246,114 +262,110 @@
} catch (MessagingException e) {
throw new OMException("Invalid Mime Message " + e);
}
- }
+ }
}
-
- protected void setEndOfStream(boolean value)
- {
+
+ protected void setEndOfStream(boolean value) {
this.endOfStreamReached = value;
-
+
}
-
+
/**
- * @return The next MIME Body part in the stream Uses the MimeBodyPartStream
- * to obtain streams delimited by boundaries.
+ * @return This will return the next available MIME part in the stream.
* @throws OMException
+ * if Stream ends while reading the next part...
*/
- private MimeBodyPart getMimeBodyPart() throws OMException {
- // endOfStreamReached will be set to true if the message ended in MIME Style
- // having "--" suffix with the last mime boundary
+ 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.");
-
- MimeBodyPart mimeBodyPart = null;
+ "Referenced MIME part not found.End of Stream reached.");
+
+ Part part = null;
MIMEBodyPartInputStream partStream;
partStream = new MIMEBodyPartInputStream(pushbackInStream, boundary,
this);
try {
- mimeBodyPart = new MimeBodyPart(partStream);
-
- // This will take care if stream ended without having MIME message terminator
- if (mimeBodyPart.getSize() <= 0) {
+ 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.");
+ "Referenced MIME part not found.End of Stream reached.");
}
} catch (MessagingException e) {
- throw new OMException("Problem reading Mime Part No "
- + (partIndex + 1) + ". " + e);
+ throw new OMException("Error creating Mime Part." + e);
}
partIndex++;
- return mimeBodyPart;
+ return part;
}
-
+
/**
- * @return
+ * @return the Root MIME part which contains the SOAP envelope
* @throws OMException
*/
- private MimeBodyPart getRootMimeBodyPart() throws OMException {
- MimeBodyPart rootMimeBodyPart;
+ private Part getRootMimeBodyPart() throws OMException {
+ Part rootPart;
if (bodyPartsMap.isEmpty()) {
- rootMimeBodyPart = getMimeBodyPart();
- bodyPartsMap.put(ROOT_PART, rootMimeBodyPart);
+ rootPart = getPart();
+ bodyPartsMap.put(ROOT_PART, rootPart);
} else {
- rootMimeBodyPart = (MimeBodyPart) bodyPartsMap.get(ROOT_PART);
+ rootPart = (Part) bodyPartsMap.get(ROOT_PART);
}
- return rootMimeBodyPart;
+ 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()
+ */
private Part getNextPart() throws OMException {
- MimeBodyPart nextMimeBodyPart;
- nextMimeBodyPart = getMimeBodyPart();
- if (nextMimeBodyPart != null) {
+ Part nextPart;
+ nextPart = getPart();
+ if (nextPart != null) {
String partContentID;
try {
- partContentID = nextMimeBodyPart.getContentID();
-
+ partContentID = nextPart.getContentID();
+
if (partContentID == null & partIndex == 1) {
- bodyPartsMap.put("firstPart", nextMimeBodyPart);
+ bodyPartsMap.put("firstPart", nextPart);
firstPartId = "firstPart";
- return nextMimeBodyPart;
+ return nextPart;
}
if (partContentID == null) {
throw new OMException(
- "Part content ID cannot be blank for non root MIME parts");
+ "Part content ID cannot be blank for non root MIME parts");
}
if ((partContentID.indexOf("<") > -1)
& (partContentID.indexOf(">") > -1)) {
partContentID = partContentID.substring(1, (partContentID
.length() - 1));
-
+
} else if (partIndex == 1) {
firstPartId = partContentID;
}
- if (bodyPartsMap.containsKey(partContentID))
- {
- throw new OMException("Two MIME parts with the same Content-ID not allowed.");
+ if (bodyPartsMap.containsKey(partContentID)) {
+ throw new OMException(
+ "Two MIME parts with the same Content-ID not allowed.");
}
- /*
- * Temporary File storage support is deffered till 1.0
- */
- // if (fileCacheEnable) {
- // PartOnFile part = new PartOnFile(nextMimeBodyPart,
- // partContentID,
- // attachmentRepoDir);
- // return part;
- // } else {
- bodyPartsMap.put(partContentID, nextMimeBodyPart);
- return nextMimeBodyPart;
- // }
+ bodyPartsMap.put(partContentID, nextPart);
+ return nextPart;
} catch (MessagingException e) {
- throw new OMException(
- "Error Reading Content-ID from Mime Part No "
- + partIndex + ". " + e);
+ throw new OMException("Error reading Content-ID from the Part."
+ + e);
}
- // } catch (Exception e) {
- // throw new OMException("Error Creating File Storage Part"
- // + partIndex + ". " + e);
- // }
} else
return null;
}
-
}
Added: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/Part.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/Part.java?rev=225767&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/Part.java (added)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/Part.java Thu Jul 28 06:35:54 2005
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2004 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.attachments;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+
+import javax.activation.DataHandler;
+import javax.mail.MessagingException;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
+ */
+public interface Part{
+
+
+ public int getSize() throws MessagingException ;
+
+ public String getContentType() throws MessagingException;
+
+ public String getContentID() throws MessagingException;
+
+ public String getFileName() throws MessagingException;
+
+ public InputStream getInputStream() throws IOException, MessagingException ;
+
+ public DataHandler getDataHandler() throws MessagingException ;
+
+ public String getHeader(String arg0) throws MessagingException ;
+
+ public Enumeration getAllHeaders() throws MessagingException ;
+
+}
Modified: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/PartOnFile.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/PartOnFile.java?rev=225767&r1=225766&r2=225767&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/PartOnFile.java (original)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/PartOnFile.java Thu Jul 28 06:35:54 2005
@@ -16,313 +16,179 @@
*/
package org.apache.axis2.attachments;
-import org.apache.axis2.om.OMException;
-
-import javax.activation.DataHandler;
-import javax.mail.MessagingException;
-import javax.mail.Multipart;
-import javax.mail.Part;
-import javax.mail.internet.MimeBodyPart;
+import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
-import java.util.Date;
import java.util.Enumeration;
+import java.util.HashMap;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.mail.MessagingException;
+
+import org.apache.axis2.om.OMException;
public class PartOnFile implements Part {
- String fileName;
+ File cacheFile;
Part bodyPart;
- int size;
-
String contentType;
- Enumeration headers;
-
String contentID;
- public PartOnFile(Part bodyPart, String contentID, String repoDir) throws Exception {
+ HashMap headers;
+
+ public PartOnFile(MIMEBodyPartInputStream inStream, String repoDir)
+ {
super();
- size = bodyPart.getSize();
- contentType = bodyPart.getContentType();
- headers = bodyPart.getAllHeaders();
- // TODO Find a better naming algorithm
+
+ headers = new HashMap();
+
if (repoDir == null) {
repoDir = ".";
}
- fileName = repoDir + (new Date()).getTime() + ".tmp";
- FileOutputStream outFileStream;
- outFileStream = new FileOutputStream(fileName);
- bodyPart.writeTo(outFileStream);
- outFileStream.close();
- }
-
- private Part getPartOnFile() {
- FileInputStream inFileStream;
- Part part = null;
try {
- inFileStream = new FileInputStream(fileName);
-
- part = new MimeBodyPart(inFileStream);
- } catch (FileNotFoundException e) {
- throw new OMException("File Not Found" + e.toString());
- } catch (MessagingException e1) {
- throw new OMException(
- "Cannot create MimePart from the Part read from file" +
- e1.toString());
+ cacheFile = java.io.File.createTempFile("Axis2", ".att",
+ (repoDir == null) ? null : new File(repoDir));
+
+ FileOutputStream fileOutStream = new FileOutputStream(cacheFile);
+ int value;
+ value = parseTheHeaders(inStream);
+
+ if(value!=-1)
+ {
+ do {
+ fileOutStream.write(value);
+ }while ((value = inStream.read()) != -1);
+ }
+ fileOutStream.flush();
+ fileOutStream.close();
+ } catch (IOException e) {
+ throw new OMException("Error creating temporary File."+e);
}
- return part;
- }
-
- public String getContentID() {
- return contentID;
- }
-
- public int getSize() throws MessagingException {
- return size;
}
-
-
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#getLineCount()
- */
- public int getLineCount() throws MessagingException {
- throw new UnsupportedOperationException();
+
+ private int parseTheHeaders(InputStream inStream) throws IOException
+ {
+ int value;
+ boolean readingHeaders = true;
+ StringBuffer header = new StringBuffer();
+ while (readingHeaders & (value = inStream.read()) != -1) {
+ if (value == 13) {
+ if ((value = inStream.read()) == 10) {
+ if ((value = inStream.read()) == 13) {
+ if ((value = inStream.read()) == 10) {
+ putToMap(header);
+ readingHeaders = false;
+ }
+ } else {
+ putToMap(header);
+ header = new StringBuffer();
+ header.append((char) value);
+ }
+ } else {
+ header.append(13);
+ header.append(value);
+ }
+ } else {
+ header.append((char) value);
+ }
+ }
+ return value;
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#getContentType()
- */
- public String getContentType() throws MessagingException {
- // TODO Auto-generated method stub
- return contentType;
+ private void putToMap(StringBuffer header) {
+ String headerString = header.toString();
+ int delimiter = headerString.indexOf(":");
+ headers.put(headerString.substring(0, delimiter).trim(),
+ headerString.substring(delimiter + 1, headerString.length())
+ .trim());
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#isMimeType(java.lang.String)
- */
- public boolean isMimeType(String arg0) throws MessagingException {
- throw new UnsupportedOperationException();
+ public String getContentID() {
+ String cID = (String)headers.get("Content-ID");;
+ if (cID==null)
+ {
+ cID= (String)headers.get("Content-Id");
+ if (cID==null)
+ {
+ cID= (String)headers.get("Content-id");
+ if (cID==null)
+ {
+ cID= (String)headers.get("content-id");
+ }
+ }
+
+ }
+ return cID;
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#getDisposition()
- */
- public String getDisposition() throws MessagingException {
- throw new UnsupportedOperationException();
+ public int getSize() throws MessagingException {
+ return (int)cacheFile.length();
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#setDisposition(java.lang.String)
- */
- public void setDisposition(String arg0) throws MessagingException {
+ public int getLineCount() throws MessagingException {
throw new UnsupportedOperationException();
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#getDescription()
- */
public String getDescription() throws MessagingException {
throw new UnsupportedOperationException();
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#setDescription(java.lang.String)
- */
public void setDescription(String arg0) throws MessagingException {
throw new UnsupportedOperationException();
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#getFileName()
- */
public String getFileName() throws MessagingException {
- throw new UnsupportedOperationException();
+ return cacheFile.getAbsolutePath();
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#setFileName(java.lang.String)
- */
- public void setFileName(String arg0) throws MessagingException {
- throw new UnsupportedOperationException();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#getInputStream()
- */
public InputStream getInputStream() throws IOException, MessagingException {
- Part part = getPartOnFile();
- return part.getInputStream();
+ FileInputStream inStream = new FileInputStream(cacheFile);
+ return inStream;
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#getDataHandler()
- */
public DataHandler getDataHandler() throws MessagingException {
- Part part = getPartOnFile();
- return part.getDataHandler();
+ return new DataHandler(new FileDataSource(cacheFile));
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#getContent()
- */
public Object getContent() throws IOException, MessagingException {
- Part part = getPartOnFile();
- return part.getContent();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#setDataHandler(javax.activation.DataHandler)
- */
- public void setDataHandler(DataHandler arg0) throws MessagingException {
- throw new UnsupportedOperationException();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#setContent(java.lang.Object, java.lang.String)
- */
- public void setContent(Object arg0, String arg1) throws MessagingException {
- throw new UnsupportedOperationException();
+ return getDataHandler().getContent();
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#setText(java.lang.String)
- */
- public void setText(String arg0) throws MessagingException {
- throw new UnsupportedOperationException();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#setContent(javax.mail.Multipart)
- */
- public void setContent(Multipart arg0) throws MessagingException {
- throw new UnsupportedOperationException();
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#writeTo(java.io.OutputStream)
- */
public void writeTo(OutputStream outStream) throws IOException,
MessagingException {
- Part part = getPartOnFile();
- part.writeTo(outStream);
+ getDataHandler().writeTo(outStream);
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#getHeader(java.lang.String)
- */
- public String[] getHeader(String arg0) throws MessagingException {
+ public String getHeader(String arg0) throws MessagingException {
ArrayList selectedHeader = null;
- while (headers.hasMoreElements()) {
- String header = (String) headers.nextElement();
- if (arg0.equals(header)) {
- selectedHeader.add(header);
- }
- }
- String[] headerStrings = (String[]) selectedHeader.toArray();
- return headerStrings;
+ String header;
+ header = (String) headers.get(arg0);
+ return header;
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#setHeader(java.lang.String, java.lang.String)
- */
- public void setHeader(String arg0, String arg1) throws MessagingException {
- throw new UnsupportedOperationException();
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#addHeader(java.lang.String, java.lang.String)
- */
- public void addHeader(String arg0, String arg1) throws MessagingException {
- throw new UnsupportedOperationException();
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#removeHeader(java.lang.String)
- */
- public void removeHeader(String arg0) throws MessagingException {
- throw new UnsupportedOperationException();
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#getAllHeaders()
- */
public Enumeration getAllHeaders() throws MessagingException {
- return headers;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#getMatchingHeaders(java.lang.String[])
- */
- public Enumeration getMatchingHeaders(String[] arg0)
- throws MessagingException {
- throw new UnsupportedOperationException();
+ return null;
}
- /*
- * (non-Javadoc)
- *
- * @see javax.mail.Part#getNonMatchingHeaders(java.lang.String[])
- */
- public Enumeration getNonMatchingHeaders(String[] arg0)
- throws MessagingException {
- throw new UnsupportedOperationException();
+ public String getContentType() throws MessagingException {
+ String cType= (String)headers.get("Content-Type");
+ if (cType==null)
+ {
+ cType= (String)headers.get("Content-type");
+ if (cType==null)
+ {
+ cType= (String)headers.get("content-type");
+ }
+ }
+ return cType;
}
}
Added: webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/PartOnMemory.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/PartOnMemory.java?rev=225767&view=auto
==============================================================================
--- webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/PartOnMemory.java (added)
+++ webservices/axis/trunk/java/modules/xml/src/org/apache/axis2/attachments/PartOnMemory.java Thu Jul 28 06:35:54 2005
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2004 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.attachments;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+
+import javax.activation.DataHandler;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeBodyPart;
+
+/**
+ * @author <a href="mailto:thilina@opensource.lk"> Thilina Gunarathne </a>
+ */
+public class PartOnMemory implements Part{
+
+ MimeBodyPart part;
+ public PartOnMemory(MIMEBodyPartInputStream partInStream) throws MessagingException
+ {
+ part = new MimeBodyPart(partInStream);
+ }
+
+ public int getSize() throws MessagingException {
+ return part.getSize();
+ }
+
+ public String getContentType() throws MessagingException {
+ return part.getContentType();
+ }
+
+ public String getFileName() throws MessagingException {
+ return part.getFileName();
+ }
+
+ public InputStream getInputStream() throws IOException, MessagingException {
+ return part.getInputStream();
+ }
+
+ public DataHandler getDataHandler() throws MessagingException {
+ return part.getDataHandler();
+ }
+
+ public String getHeader(String arg0) throws MessagingException {
+ return part.getHeader(arg0)[0];
+ }
+
+ public Enumeration getAllHeaders() throws MessagingException {
+ return part.getAllHeaders();
+ }
+
+
+ public String getContentID() throws MessagingException {
+ return part.getContentID();
+ }
+}
Modified: webservices/axis/trunk/java/modules/xml/test-resources/mtom/img/test.jpg
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test-resources/mtom/img/test.jpg?rev=225767&r1=225766&r2=225767&view=diff
==============================================================================
Binary files - no diff available.
Modified: webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/attachments/ImageSampleTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/attachments/ImageSampleTest.java?rev=225767&r1=225766&r2=225767&view=diff
==============================================================================
--- webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/attachments/ImageSampleTest.java (original)
+++ webservices/axis/trunk/java/modules/xml/test/org/apache/axis2/attachments/ImageSampleTest.java Thu Jul 28 06:35:54 2005
@@ -61,13 +61,13 @@
File outBase64File;
- String outFileName = "mtom/ActualImageMTOMOut.bin";
+ String outFileName = "target/ActualImageMTOMOut.bin";
- String outBase64FileName = "mtom/OMSerializeBase64Out.xml";
+ String outBase64FileName = "target/OMSerializeBase64Out.xml";
String imageInFileName = "mtom/img/test.jpg";
- String imageOutFileName = "mtom/img/testOut.jpg";
+ String imageOutFileName = "target/testOut.jpg";
String inMimeFileName = "mtom/ImageMTOMOut.bin";
@@ -84,8 +84,8 @@
public void testImageSampleSerialize() throws Exception {
- outMTOMFile = getTestResourceFile(outFileName);
- outBase64File = getTestResourceFile(outBase64FileName);
+ outMTOMFile = new File(outFileName);
+ outBase64File = new File(outBase64FileName);
org.apache.axis2.om.impl.OMOutputImpl mtomOutput = new OMOutputImpl(new FileOutputStream(outMTOMFile),
true);
org.apache.axis2.om.impl.OMOutputImpl baseOutput = new OMOutputImpl(new FileOutputStream(outBase64File),
@@ -147,7 +147,7 @@
Image actualObject = new JDK13IO().loadImage(actualDH.getDataSource()
.getInputStream());
FileOutputStream imageOutStream = new FileOutputStream(
- getTestResourceFile(imageOutFileName));
+ new File(imageOutFileName));
new JDK13IO().saveImage("image/jpeg", actualObject, imageOutStream);
}