You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2008/05/07 10:31:14 UTC
svn commit: r654032 - in /cxf/branches/2.0.x-fixes/rt/transports/jbi/src:
main/java/org/apache/cxf/transport/jbi/
test/java/org/apache/cxf/transport/jbi/
Author: ffang
Date: Wed May 7 01:31:13 2008
New Revision: 654032
URL: http://svn.apache.org/viewvc?rev=654032&view=rev
Log:
[CXF-1573]JBIDestinationOutputStream should copy attachments into NormalizedMessage to support outbound attachments
Modified:
cxf/branches/2.0.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestination.java
cxf/branches/2.0.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestinationOutputStream.java
cxf/branches/2.0.x-fixes/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIDestinationTest.java
Modified: cxf/branches/2.0.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestination.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestination.java?rev=654032&r1=654031&r2=654032&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestination.java (original)
+++ cxf/branches/2.0.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestination.java Wed May 7 01:31:13 2008
@@ -118,7 +118,7 @@
DeliveryChannel dc = channel;
message.put(MessageExchange.class, inMessage.get(MessageExchange.class));
message.setContent(OutputStream.class,
- new JBIDestinationOutputStream(inMessage, dc));
+ new JBIDestinationOutputStream(inMessage, message, dc));
}
protected Logger getLogger() {
Modified: cxf/branches/2.0.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestinationOutputStream.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestinationOutputStream.java?rev=654032&r1=654031&r2=654032&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestinationOutputStream.java (original)
+++ cxf/branches/2.0.x-fixes/rt/transports/jbi/src/main/java/org/apache/cxf/transport/jbi/JBIDestinationOutputStream.java Wed May 7 01:31:13 2008
@@ -36,18 +36,22 @@
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.message.Attachment;
import org.apache.cxf.message.Message;
public class JBIDestinationOutputStream extends CachedOutputStream {
private static final Logger LOG = LogUtils.getL7dLogger(JBIDestinationOutputStream.class);
private Message inMessage;
+ private Message outMessage;
private DeliveryChannel channel;
public JBIDestinationOutputStream(Message m,
+ Message outM,
DeliveryChannel dc) {
super();
inMessage = m;
+ outMessage = outM;
channel = dc;
}
@@ -95,6 +99,13 @@
}
} else {
NormalizedMessage msg = xchng.createMessage();
+ //copy attachments
+ if (outMessage != null && outMessage.getAttachments() != null) {
+ for (Attachment att : outMessage.getAttachments()) {
+ msg.addAttachment(att.getId(), att
+ .getDataHandler());
+ }
+ }
msg.setContent(new DOMSource(doc));
xchng.setMessage(msg, "out");
Modified: cxf/branches/2.0.x-fixes/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIDestinationTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIDestinationTest.java?rev=654032&r1=654031&r2=654032&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIDestinationTest.java (original)
+++ cxf/branches/2.0.x-fixes/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIDestinationTest.java Wed May 7 01:31:13 2008
@@ -20,8 +20,17 @@
package org.apache.cxf.transport.jbi;
import java.util.logging.Logger;
-
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.easymock.EasyMock;
+
+
import org.junit.Test;
public class JBIDestinationTest extends AbstractJBITest {
@@ -30,4 +39,42 @@
public void testDestination() throws Exception {
LOG.info("JBI destination test");
}
+
+ @Test
+ public void testOutputStreamSubstitutionDoesntCauseExceptionInDoClose() throws Exception {
+ //Create enough of the object structure to get through the code.
+ NormalizedMessage normalizedMessage = control.createMock(NormalizedMessage.class);
+ channel = control.createMock(DeliveryChannel.class);
+ Exchange exchange = new ExchangeImpl();
+ exchange.setOneWay(false);
+ Message message = new MessageImpl();
+ message.setExchange(exchange);
+
+
+ MessageExchange messageExchange = control.createMock(MessageExchange.class);
+ EasyMock.expect(messageExchange.createMessage()).andReturn(normalizedMessage);
+ message.put(MessageExchange.class, messageExchange);
+ channel.send(messageExchange);
+ EasyMock.replay(channel);
+
+ JBIDestinationOutputStream jbiOS = new JBIDestinationOutputStream(message, null, channel);
+
+ //Create array of more than what is in threshold in CachedOutputStream,
+ //though the threshold in CachedOutputStream should be made protected
+ //perhaps so it can be referenced here in case it ever changes.
+ int targetLength = 64 * 1025;
+ StringBuffer sb = new StringBuffer();
+ sb.append("<root>");
+ while (sb.length() < targetLength) {
+ sb.append("<dummy>some xml</dummy>");
+ }
+ sb.append("</root>");
+ byte[] testBytes = sb.toString().getBytes();
+
+ jbiOS.write(testBytes);
+ jbiOS.doClose();
+
+ //Verify send method was called.
+ EasyMock.verify(channel);
+ }
}