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 di...@apache.org on 2002/10/19 17:37:34 UTC
cvs commit: xml-axis/java/test/saaj TestAttachmentSerialization.java
dims 2002/10/19 08:37:34
Modified: java/src/org/apache/axis/attachments
BoundaryDelimitedStream.java
MultiPartRelatedInputStream.java
java/src/org/apache/axis/message MessageElement.java
java/test/saaj TestAttachmentSerialization.java
Log:
- Fix for Bug 13135 - saxparse error in deserialzing mime file to soap message while getting envelope
- Updated test case (got rid of temp file as well)
Revision Changes Path
1.23 +2 -0 xml-axis/java/src/org/apache/axis/attachments/BoundaryDelimitedStream.java
Index: BoundaryDelimitedStream.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/BoundaryDelimitedStream.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- BoundaryDelimitedStream.java 18 Sep 2002 16:10:38 -0000 1.22
+++ BoundaryDelimitedStream.java 19 Oct 2002 15:37:34 -0000 1.23
@@ -533,6 +533,8 @@
// If there really was no crlf at then end then this is not a boundary.
foundAt = BOUNDARY_NOT_FOUND;
+ } else {
+ foundAt -= 2;
}
}
}
1.32 +8 -3 xml-axis/java/src/org/apache/axis/attachments/MultiPartRelatedInputStream.java
Index: MultiPartRelatedInputStream.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/attachments/MultiPartRelatedInputStream.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- MultiPartRelatedInputStream.java 18 Sep 2002 16:10:38 -0000 1.31
+++ MultiPartRelatedInputStream.java 19 Oct 2002 15:37:34 -0000 1.32
@@ -66,6 +66,7 @@
import javax.mail.internet.MimeUtility;
import java.io.InputStream;
import java.io.IOException;
+import java.io.PushbackInputStream;
/**
* This simulates the multipart stream
@@ -137,13 +138,14 @@
* @throws org.apache.axis.AxisFault
*/
public MultiPartRelatedInputStream(
- String contentType, java.io.InputStream is)
+ String contentType, java.io.InputStream stream)
throws org.apache.axis.AxisFault {
super(null); // don't cache this stream.
try {
-
+ PushbackInputStream is = new PushbackInputStream(stream);
+
// First find the start and boundary parameters. There are real weird rules regard what
// can be in real headers what needs to be escaped etc let mail parse it.
javax.mail.internet.ContentType ct =
@@ -385,7 +387,7 @@
}
}
- public final String readLine(InputStream is) throws IOException {
+ public final String readLine(PushbackInputStream is) throws IOException {
StringBuffer input = new StringBuffer();
int c = -1;
@@ -398,6 +400,9 @@
eol = true;
break;
case '\r':
+ int next = is.read();
+ if(next != '\n' && next != -1)
+ is.unread(next);
eol = true;
break;
default:
1.131 +5 -1 xml-axis/java/src/org/apache/axis/message/MessageElement.java
Index: MessageElement.java
===================================================================
RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/MessageElement.java,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -r1.130 -r1.131
--- MessageElement.java 8 Oct 2002 03:31:33 -0000 1.130
+++ MessageElement.java 19 Oct 2002 15:37:34 -0000 1.131
@@ -252,7 +252,11 @@
// Set the encoding style to the attribute value. If null,
// we just automatically use our parent's (see getEncodingStyle)
- SOAPConstants sc = context.getMessageContext().getSOAPConstants();
+ MessageContext mc = context.getMessageContext();
+ SOAPConstants sc = (mc != null) ?
+ mc.getSOAPConstants() :
+ SOAPConstants.SOAP11_CONSTANTS;
+
encodingStyle =
attributes.getValue(sc.getEncodingURI(),
Constants.ATTR_ENCODING_STYLE);
1.2 +15 -12 xml-axis/java/test/saaj/TestAttachmentSerialization.java
Index: TestAttachmentSerialization.java
===================================================================
RCS file: /home/cvs/xml-axis/java/test/saaj/TestAttachmentSerialization.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestAttachmentSerialization.java 6 Sep 2002 20:09:26 -0000 1.1
+++ TestAttachmentSerialization.java 19 Oct 2002 15:37:34 -0000 1.2
@@ -74,6 +74,9 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
/** Test the attachments load/save sample code.
@@ -91,16 +94,14 @@
}
public void testAttachments() throws Exception {
- File f = File.createTempFile("mime",".txt");
try {
- int count1 = saveMsgWithAttachments(f.getAbsolutePath());
- int count2 = loadMsgWithAttachments(f.getAbsolutePath());
- assertTrue(count1 == count2);
+ ByteArrayOutputStream bais = new ByteArrayOutputStream();
+ int count1 = saveMsgWithAttachments(bais);
+ int count2 = loadMsgWithAttachments(new ByteArrayInputStream(bais.toByteArray()));
+ assertEquals(count1, count2);
} catch (Exception e) {
e.printStackTrace();
throw new Exception("Fault returned from test: " + e);
- } finally {
- f.delete();
}
}
@@ -109,7 +110,7 @@
public static final String NS_PREFIX = "jaxmtst";
public static final String NS_URI = "http://www.jcommerce.net/soap/jaxm/TestJaxm";
- public int saveMsgWithAttachments(String filename) throws Exception {
+ public int saveMsgWithAttachments(OutputStream os) throws Exception {
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = mf.createMessage();
@@ -141,18 +142,20 @@
ap2.setContentType("image/jpg");
msg.addAttachmentPart(ap2);
- FileOutputStream fout = new FileOutputStream(filename);
- msg.writeTo(fout);
- fout.close();
+ msg.writeTo(os);
+ os.flush();
return msg.countAttachments();
}
- public int loadMsgWithAttachments(String filename) throws Exception {
+ public int loadMsgWithAttachments(InputStream is) throws Exception {
MimeHeaders headers = new MimeHeaders();
headers.setHeader("Content-Type", MIME_MULTIPART_RELATED);
- InputStream is = new FileInputStream(filename);
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = mf.createMessage(headers, is);
+ SOAPPart sp = msg.getSOAPPart();
+ SOAPEnvelope envelope = sp.getEnvelope();
+ assertTrue(sp != null);
+ assertTrue(envelope != null);
return msg.countAttachments();
}
}