You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2008/10/09 12:35:11 UTC
svn commit: r703123 - in
/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip:
./ src/main/java/org/apache/servicemix/eip/
src/main/java/org/apache/servicemix/eip/patterns/
src/test/java/org/apache/servicemix/eip/
Author: gertv
Date: Thu Oct 9 03:35:11 2008
New Revision: 703123
URL: http://svn.apache.org/viewvc?rev=703123&view=rev
Log:
SM-1622: servicemix-eip content enricher should copy message properties and attachments
Modified:
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/pom.xml
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/ContentEnricher.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/test/java/org/apache/servicemix/eip/AbstractEIPTest.java
servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/test/java/org/apache/servicemix/eip/ContentEnricherTest.java
Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/pom.xml?rev=703123&r1=703122&r2=703123&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/pom.xml (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/pom.xml Thu Oct 9 03:35:11 2008
@@ -121,6 +121,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
+ <forkMode>pertest</forkMode>
<workingDirectory>${basedir}</workingDirectory>
<includes>
<include>**/*Test.*</include>
Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java?rev=703123&r1=703122&r2=703123&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPEndpoint.java Thu Oct 9 03:35:11 2008
@@ -17,11 +17,15 @@
package org.apache.servicemix.eip;
import java.net.URL;
+import java.util.Set;
+import javax.activation.DataHandler;
import javax.jbi.JBIException;
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.MessageExchange.Role;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
import javax.jbi.servicedesc.ServiceEndpoint;
import javax.wsdl.Definition;
import javax.wsdl.WSDLException;
@@ -35,6 +39,7 @@
import org.apache.servicemix.JbiConstants;
import org.apache.servicemix.common.endpoints.ProviderEndpoint;
import org.apache.servicemix.eip.support.ExchangeTarget;
+import org.apache.servicemix.jbi.messaging.PojoMarshaler;
import org.apache.servicemix.locks.LockManager;
import org.apache.servicemix.locks.impl.SimpleLockManager;
import org.apache.servicemix.store.Store;
@@ -307,5 +312,37 @@
public void setWsdlExchangeTarget(ExchangeTarget wsdlExchangeTarget) {
this.wsdlExchangeTarget = wsdlExchangeTarget;
}
-
+
+ /**
+ * Copies properties from one message to another that do not already exist
+ *
+ * @param from the message containing the properties
+ * @param to the destination message where the properties are set
+ */
+ protected void copyProperties(NormalizedMessage from, NormalizedMessage to) {
+ for (String propertyName : (Set<String>) from.getPropertyNames()) {
+ // Do not copy existing properties or transient properties
+ if (to.getProperty(propertyName) == null && !PojoMarshaler.BODY.equals(propertyName)) {
+ Object value = from.getProperty(propertyName);
+ to.setProperty(propertyName, value);
+ }
+ }
+ }
+
+ /**
+ * Copies attachments from one message to another that do not already exist
+ *
+ * @param from the message with the attachments
+ * @param to the destination message where the attachments are to be added
+ * @throws javax.jbi.messaging.MessagingException if an attachment could not be added
+ */
+ protected void copyAttachments(NormalizedMessage from, NormalizedMessage to) throws MessagingException {
+ for (String attachmentName : (Set<String>) from.getAttachmentNames()) {
+ // Do not copy existing attachments
+ if (to.getAttachment(attachmentName) == null) {
+ DataHandler value = from.getAttachment(attachmentName);
+ to.addAttachment(attachmentName, value);
+ }
+ }
+ }
}
Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/ContentEnricher.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/ContentEnricher.java?rev=703123&r1=703122&r2=703123&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/ContentEnricher.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/ContentEnricher.java Thu Oct 9 03:35:11 2008
@@ -20,6 +20,7 @@
import javax.jbi.messaging.InOnly;
import javax.jbi.messaging.InOut;
import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
import javax.jbi.messaging.NormalizedMessage;
import javax.jbi.messaging.RobustInOnly;
import javax.xml.namespace.QName;
@@ -75,6 +76,16 @@
private QName resultElementName = new QName("result");
/**
+ * Should message properties be copied ?
+ */
+ private boolean copyProperties;
+
+ /**
+ * Should message attachments be copied ?
+ */
+ private boolean copyAttachments;
+
+ /**
* returns the QName of the resulting root node
* @return QName of the resulting root node
*/
@@ -132,6 +143,34 @@
this.resultElementName = resultElementName;
}
+ public boolean isCopyProperties() {
+ return copyProperties;
+ }
+
+ /**
+ * If this is set to <code>true</code>, message properties from the incoming exchange and the enricher exchange will be copied
+ * to the outgoing message exchange. The default value is <code>false</code> (do not copy message properties).
+ *
+ * @param copyProperties
+ */
+ public void setCopyProperties(boolean copyProperties) {
+ this.copyProperties = copyProperties;
+ }
+
+ public boolean isCopyAttachments() {
+ return copyAttachments;
+ }
+
+ /**
+ * If this is set to <code>true</code>, message attachments from the incoming exchange and the enricher exchange will be copied
+ * to the outgoing message exchange. The default value is <code>false</code> (do not copy message atachments).
+ *
+ * @param copyAttachments
+ */
+ public void setCopyAttachments(boolean copyAttachments) {
+ this.copyAttachments = copyAttachments;
+ }
+
protected void processAsync(MessageExchange exchange) throws Exception {
throw new IllegalStateException();
}
@@ -176,9 +215,13 @@
outExchange.setMessage(out, "in");
+ if (copyProperties || copyAttachments) {
+ copyPropertiesAndAttachments(exchange.getMessage("in"), outExchange.getMessage("in"));
+ copyPropertiesAndAttachments(enricherTargetME.getMessage("out"), outExchange.getMessage("in"));
+ }
+
sendSync(outExchange);
done(exchange);
-
}
/**
@@ -259,4 +302,21 @@
this.enricherTarget = enricherTarget;
}
+
+ /**
+ * Copies properties and attachments from one message to another
+ * depending on the endpoint configuration
+ *
+ * @param from the message containing the properties and attachments
+ * @param to the destination message where the properties and attachments are set
+ */
+ private void copyPropertiesAndAttachments(NormalizedMessage from, NormalizedMessage to) throws MessagingException {
+ if (copyProperties) {
+ copyProperties(from, to);
+ }
+ if (copyAttachments) {
+ copyAttachments(from, to);
+ }
+ }
+
}
Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/test/java/org/apache/servicemix/eip/AbstractEIPTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/test/java/org/apache/servicemix/eip/AbstractEIPTest.java?rev=703123&r1=703122&r2=703123&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/test/java/org/apache/servicemix/eip/AbstractEIPTest.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/test/java/org/apache/servicemix/eip/AbstractEIPTest.java Thu Oct 9 03:35:11 2008
@@ -63,7 +63,7 @@
client = new DefaultServiceMixClient(jbi);
- //LogManager.getLogger(DeliveryChannel.class).setLevel(Level.OFF);
+ //LogManager.getLogger(DeliveryChannel.class).setLevel(Level.DEBUG);
}
protected void tearDown() throws Exception {
@@ -146,7 +146,13 @@
}
protected static class ReturnMockComponent extends ComponentSupport implements MessageExchangeListener {
+
+ //message property (name, value) to be set on the generated message
+ public static final String PROPERTY_NAME = "ReturnMockComponentPropName";
+ public static final String PROPERTY_VALUE = "ReturnMockComponentPropValue";
+
private String response;
+
public ReturnMockComponent(String response) {
this.response = response;
}
@@ -156,6 +162,10 @@
&& Boolean.TRUE.equals(exchange.getProperty(JbiConstants.SEND_SYNC));
NormalizedMessage out = exchange.createMessage();
out.setContent(createSource(response));
+
+ //add some message properties
+ out.setProperty(PROPERTY_NAME, PROPERTY_VALUE);
+
exchange.setMessage(out, "out");
if (txSync) {
sendSync(exchange);
Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/test/java/org/apache/servicemix/eip/ContentEnricherTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/test/java/org/apache/servicemix/eip/ContentEnricherTest.java?rev=703123&r1=703122&r2=703123&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/test/java/org/apache/servicemix/eip/ContentEnricherTest.java (original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-eip/src/test/java/org/apache/servicemix/eip/ContentEnricherTest.java Thu Oct 9 03:35:11 2008
@@ -93,4 +93,36 @@
assertEquals(ExchangeStatus.ERROR, me.getStatus());
}
+
+ public void testMsgProperties() throws Exception {
+
+ String propName1 = "propName1";
+ String propName2 = "propName2";
+ String propVal1 = "propVal1";
+ String propVal2 = "propVal2";
+
+ enricher.setCopyProperties(true);
+
+ activateComponent(new ReturnMockComponent("<helloMock/>"), "enricherTarget");
+
+ ReceiverComponent rec = activateReceiver("target");
+
+ InOnly me = client.createInOnlyExchange();
+
+ me.setService(new QName("enricher"));
+ me.getInMessage().setContent(createSource("<hello/>"));
+ me.getInMessage().setProperty(propName1, propVal1);
+ me.getInMessage().setProperty(propName2, propVal2);
+ client.sendSync(me);
+
+ NormalizedMessage msg = (NormalizedMessage) rec.getMessageList()
+ .getMessages().get(0);
+
+ //assertions
+ assertEquals(ExchangeStatus.DONE, me.getStatus());
+ assertEquals(1, rec.getMessageList().getMessageCount());
+ assertEquals(propVal1, msg.getProperty(propName1));
+ assertEquals(propVal2, msg.getProperty(propName2));
+ assertEquals(ReturnMockComponent.PROPERTY_VALUE, msg.getProperty(ReturnMockComponent.PROPERTY_NAME));
+ }
}