You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2006/12/01 22:19:11 UTC
svn commit: r481398 - in /incubator/cxf/trunk:
api/src/main/java/org/apache/cxf/phase/
rt/core/src/main/java/org/apache/cxf/attachment/
rt/core/src/test/java/org/apache/cxf/attachment/
systests/src/test/java/org/apache/cxf/systest/mtom/
Author: dandiep
Date: Fri Dec 1 13:19:10 2006
New Revision: 481398
URL: http://svn.apache.org/viewvc?view=rev&rev=481398
Log:
Use CRLF when writing attachments. Also make improvements to mime type headers. Things now work correctly with .NET 2.0 + WSE.
Removed:
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/mimedata2
Modified:
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentSerializerTest.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/Data.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/EchoService.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java?view=diff&rev=481398&r1=481397&r2=481398
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java Fri Dec 1 13:19:10 2006
@@ -141,8 +141,8 @@
try {
Interceptor currentInterceptor = iterator.next();
- if (LOG.isLoggable(Level.FINE)) {
- LOG.fine("Invoking handleMessage on interceptor " + currentInterceptor);
+ if (LOG.isLoggable(Level.INFO)) {
+ LOG.info("Invoking handleMessage on interceptor " + currentInterceptor);
}
currentInterceptor.handleMessage(message);
Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java?view=diff&rev=481398&r1=481397&r2=481398
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java Fri Dec 1 13:19:10 2006
@@ -49,18 +49,25 @@
bodyBoundary = AttachmentUtil.getUniqueBoundaryValue(0);
String bodyCt = (String) message.get(Message.CONTENT_TYPE);
+ String enc = (String) message.get(Message.ENCODING);
+ if (enc == null) {
+ enc = "UTF-8";
+ }
// Set transport mime type
StringBuilder ct = new StringBuilder();
- ct.append("multipart/related; boundary=\"")
+ ct.append("multipart/related; ")
+ .append("type=\"application/xop+xml\"; ")
+ .append("boundary=\"")
.append(bodyBoundary)
.append("\"; ")
- .append("type=\"application/xop+xml\"; ")
.append("start=\"<")
.append(BODY_ATTACHMENT_ID)
.append(">\"; ")
.append("start-info=\"")
.append(bodyCt)
+ .append("; charset=")
+ .append(enc)
.append("\"");
message.put(Message.CONTENT_TYPE, ct.toString());
@@ -72,23 +79,33 @@
encoding = "UTF-8";
}
writer = new OutputStreamWriter(out, encoding);
+ writer.write("\r\n");
writer.write("--");
writer.write(bodyBoundary);
- writeHeaders(bodyCt, BODY_ATTACHMENT_ID);
+ StringBuilder mimeBodyCt = new StringBuilder();
+ mimeBodyCt.append("application/xop+xml; charset=")
+ .append(enc)
+ .append("; type=\"")
+ .append(bodyCt)
+ .append("; charset=")
+ .append(enc)
+ .append("\"");
+
+ writeHeaders(mimeBodyCt.toString(), BODY_ATTACHMENT_ID);
}
private void writeHeaders(String contentType, String attachmentId) throws IOException {
- writer.write("\n");
+ writer.write("\r\n");
writer.write("Content-Type: ");
writer.write(contentType);
- writer.write("\n");
+ writer.write("\r\n");
- writer.write("Content-Transfer-Encoding: binary\n");
+ writer.write("Content-Transfer-Encoding: binary\r\n");
writer.write("Content-ID: <");
writer.write(attachmentId);
- writer.write(">\n\n");
+ writer.write(">\r\n\r\n");
writer.flush();
}
@@ -97,19 +114,21 @@
* @throws IOException
*/
public void writeAttachments() throws IOException {
- writer.write('\n');
- writer.write("--");
- writer.write(bodyBoundary);
-
for (Attachment a : message.getAttachments()) {
- writeHeaders(a.getDataHandler().getContentType(), a.getId());
-
- IOUtils.copy(a.getDataHandler().getInputStream(), out);
+ writer.write("\r\n");
writer.write("--");
writer.write(bodyBoundary);
- writer.write('\n');
+
+ writeHeaders(a.getDataHandler().getContentType(), a.getId());
+
+ IOUtils.copy(a.getDataHandler().getInputStream(), out);
}
+
+ writer.write("\r\n");
+ writer.write("--");
+ writer.write(bodyBoundary);
+ writer.write("--");
writer.flush();
}
Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentSerializerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentSerializerTest.java?view=diff&rev=481398&r1=481397&r2=481398
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentSerializerTest.java (original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentSerializerTest.java Fri Dec 1 13:19:10 2006
@@ -24,12 +24,18 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Properties;
import javax.activation.DataHandler;
+import javax.mail.Session;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
import javax.mail.util.ByteArrayDataSource;
import junit.framework.TestCase;
+import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.message.Attachment;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
@@ -58,11 +64,11 @@
AttachmentSerializer serializer = new AttachmentSerializer(msg);
serializer.writeProlog();
-
+
String ct = (String) msg.get(Message.CONTENT_TYPE);
- assertTrue(ct.indexOf("multipart/related; boundary=") == 0);
+ assertTrue(ct.indexOf("multipart/related;") == 0);
assertTrue(ct.indexOf("start=\"<ro...@cxf.apache.org>\"") > -1);
- assertTrue(ct.indexOf("start-info=\"application/soap+xml\"") > -1);
+ assertTrue(ct.indexOf("start-info=\"application/soap+xml; charset=UTF-8\"") > -1);
out.write("<soap:Body/>".getBytes());
@@ -70,18 +76,30 @@
out.flush();
- MessageImpl in = new MessageImpl();
- in.put(Message.CONTENT_TYPE, ct);
- in.setContent(InputStream.class, new ByteArrayInputStream(out.toByteArray()));
-
- AttachmentDeserializer deserializer = new AttachmentDeserializer(in);
- deserializer.initializeAttachments();
-
- Collection<Attachment> inAtts = in.getAttachments();
- assertNotNull(inAtts);
- assertEquals(1, inAtts.size());
+ Session session = Session.getDefaultInstance(new Properties());
+ MimeMessage inMsg = new MimeMessage(session, new ByteArrayInputStream(out.toByteArray()));
+ inMsg.addHeaderLine("Content-Type: " + ct);
+
+ MimeMultipart multipart = (MimeMultipart) inMsg.getContent();
+
+ MimeBodyPart part = (MimeBodyPart) multipart.getBodyPart(0);
+ assertEquals("application/xop+xml; charset=UTF-8; type=\"application/soap+xml; charset=UTF-8\"",
+ part.getHeader("Content-Type")[0]);
+ assertEquals("binary", part.getHeader("Content-Transfer-Encoding")[0]);
+ assertEquals("<ro...@cxf.apache.org>", part.getHeader("Content-ID")[0]);
+
+ InputStream in = part.getDataHandler().getInputStream();
+ ByteArrayOutputStream bodyOut = new ByteArrayOutputStream();
+ IOUtils.copy(in, bodyOut);
+ out.close();
+ in.close();
+
+ assertEquals("<soap:Body/>", bodyOut.toString());
+
+ MimeBodyPart part2 = (MimeBodyPart) multipart.getBodyPart(1);
+ assertEquals("application/octet-stream", part2.getHeader("Content-Type")[0]);
+ assertEquals("binary", part2.getHeader("Content-Transfer-Encoding")[0]);
+ assertEquals("<test.xml>", part2.getHeader("Content-ID")[0]);
- Attachment inAtt = inAtts.iterator().next();
- assertEquals("test.xml", inAtt.getId());
}
}
Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/Data.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/Data.java?view=diff&rev=481398&r1=481397&r2=481398
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/Data.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/Data.java Fri Dec 1 13:19:10 2006
@@ -23,9 +23,9 @@
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlMimeType;
-import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
-@XmlRootElement(name = "Data", namespace = "http://mtom.systest.cxf.apache.org")
+@XmlType(name = "Data", namespace = "http://mtom.systest.cxf.apache.org")
@XmlAccessorType(XmlAccessType.FIELD)
public class Data {
Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/EchoService.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/EchoService.java?view=diff&rev=481398&r1=481397&r2=481398
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/EchoService.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/EchoService.java Fri Dec 1 13:19:10 2006
@@ -23,6 +23,20 @@
@WebService
public class EchoService {
public Data echo(Data input) {
+// ByteArrayOutputStream out = new ByteArrayOutputStream();
+// try {
+// IOUtils.copy(input.getSomeData().getInputStream(), out);
+// out.close();
+// System.out.println("RECEIVED " + out.size());
+//
+// ByteArrayDataSource source = new ByteArrayDataSource(out.toByteArray(),
+// "application/octet-stream");
+// input.setSomeData(new DataHandler(source));
+// } catch (IOException e) {
+// // do nothing
+// }
+//
+
return input;
}
}
Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java?view=diff&rev=481398&r1=481397&r2=481398
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java Fri Dec 1 13:19:10 2006
@@ -54,7 +54,7 @@
sf.create();
EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/wsdl/http");
- ei.setAddress("http://localhost:9036/EchoService");
+ ei.setAddress(address);
ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
ConduitInitiator conduitInit = conduitMgr.getConduitInitiator("http://schemas.xmlsoap.org/soap/http");
@@ -85,7 +85,6 @@
os.close();
byte[] res = obs.getResponseStream().toByteArray();
-
MessageImpl resMsg = new MessageImpl();
resMsg.setContent(InputStream.class, new ByteArrayInputStream(res));
resMsg.put(Message.CONTENT_TYPE, obs.getResponseContentType());