Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 29240 invoked from network); 7 May 2008 08:31:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 May 2008 08:31:47 -0000 Received: (qmail 70084 invoked by uid 500); 7 May 2008 08:31:49 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 70021 invoked by uid 500); 7 May 2008 08:31:49 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 70010 invoked by uid 99); 7 May 2008 08:31:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 May 2008 01:31:49 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 May 2008 08:30:55 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AA4EF2388A27; Wed, 7 May 2008 01:31:15 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/ Date: Wed, 07 May 2008 08:31:14 -0000 To: commits@cxf.apache.org From: ffang@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080507083115.AA4EF2388A27@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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(""); + while (sb.length() < targetLength) { + sb.append("some xml"); + } + sb.append(""); + byte[] testBytes = sb.toString().getBytes(); + + jbiOS.write(testBytes); + jbiOS.doClose(); + + //Verify send method was called. + EasyMock.verify(channel); + } }