servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r397524 - in /incubator/servicemix/trunk/servicemix-eip/src: main/java/org/apache/servicemix/eip/ main/java/org/apache/servicemix/eip/patterns/ test/java/org/apache/servicemix/eip/ test/resources/su/
Date Thu, 27 Apr 2006 11:44:07 GMT
Author: gnodet
Date: Thu Apr 27 04:44:04 2006
New Revision: 397524

URL: http://svn.apache.org/viewcvs?rev=397524&view=rev
Log:
Fix EIP component deployer.
Add the MessageFilter pattern.
Add an empty configuration (will be enhanced to customize the Store used)

Added:
    incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPConfiguration.java
    incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPConfigurationMBean.java
    incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/MessageFilter.java
    incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/DeploymentTest.java
    incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/MessageFilterTest.java
    incubator/servicemix/trunk/servicemix-eip/src/test/resources/su/
    incubator/servicemix/trunk/servicemix-eip/src/test/resources/su/xbean.xml
Modified:
    incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPComponent.java
    incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPLifeCycle.java
    incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/VMEIPTests.java

Modified: incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPComponent.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPComponent.java?rev=397524&r1=397523&r2=397524&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPComponent.java
(original)
+++ incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPComponent.java
Thu Apr 27 04:44:04 2006
@@ -16,11 +16,29 @@
 package org.apache.servicemix.eip;
 
 import org.apache.servicemix.common.BaseComponent;
+import org.apache.servicemix.common.BaseLifeCycle;
+import org.apache.servicemix.common.BaseServiceUnitManager;
+import org.apache.servicemix.common.Deployer;
 
 /**
  * @author gnodet
  * @version $Revision: 376451 $
  */
 public class EIPComponent extends BaseComponent {
+
+    /* (non-Javadoc)
+     * @see org.servicemix.common.BaseComponent#createLifeCycle()
+     */
+    protected BaseLifeCycle createLifeCycle() {
+        return new EIPLifeCycle(this);
+    }
+
+    /* (non-Javadoc)
+     * @see org.servicemix.common.BaseComponent#createServiceUnitManager()
+     */
+    public BaseServiceUnitManager createServiceUnitManager() {
+        Deployer[] deployers = new Deployer[] { new EIPDeployer(this) };
+        return new BaseServiceUnitManager(this, deployers);
+    }
 
 }

Added: incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPConfiguration.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPConfiguration.java?rev=397524&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPConfiguration.java
(added)
+++ incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPConfiguration.java
Thu Apr 27 04:44:04 2006
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.eip;
+
+import org.apache.servicemix.common.PersistentConfiguration;
+
+/**
+ * EIP component configuration
+ * 
+ * @author gnodet
+ * @version $Revision: 376451 $
+ */
+public class EIPConfiguration extends PersistentConfiguration implements EIPConfigurationMBean
{
+
+}

Added: incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPConfigurationMBean.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPConfigurationMBean.java?rev=397524&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPConfigurationMBean.java
(added)
+++ incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPConfigurationMBean.java
Thu Apr 27 04:44:04 2006
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.eip;
+
+/**
+ * MBean interface for the EIP component configuration
+ * 
+ * @author gnodet
+ * @version $Revision: 376451 $
+ */
+public interface EIPConfigurationMBean {
+
+}

Modified: incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPLifeCycle.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPLifeCycle.java?rev=397524&r1=397523&r2=397524&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPLifeCycle.java
(original)
+++ incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/EIPLifeCycle.java
Thu Apr 27 04:44:04 2006
@@ -24,8 +24,38 @@
  */
 public class EIPLifeCycle extends BaseLifeCycle {
 
+    protected EIPConfiguration configuration;
+
     public EIPLifeCycle(BaseComponent component) {
         super(component);
+        configuration = new EIPConfiguration();
+    }
+
+    /**
+     * @return Returns the configuration.
+     */
+    public EIPConfiguration getConfiguration() {
+        return configuration;
+    }
+
+    /**
+     * @param configuration The configuration to set.
+     */
+    public void setConfiguration(EIPConfiguration configuration) {
+        this.configuration = configuration;
+    }
+
+    /* (non-Javadoc)
+     * @see org.servicemix.common.BaseComponentLifeCycle#getExtensionMBean()
+     */
+    protected Object getExtensionMBean() throws Exception {
+        return configuration;
+    }
+
+    protected void doInit() throws Exception {
+        super.doInit();
+        configuration.setRootDir(context.getWorkspaceRoot());
+        configuration.load();
     }
 
 }

Added: incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/MessageFilter.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/MessageFilter.java?rev=397524&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/MessageFilter.java
(added)
+++ incubator/servicemix/trunk/servicemix-eip/src/main/java/org/apache/servicemix/eip/patterns/MessageFilter.java
Thu Apr 27 04:44:04 2006
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.eip.patterns;
+
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.messaging.RobustInOnly;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.eip.EIPEndpoint;
+import org.apache.servicemix.eip.support.ExchangeTarget;
+import org.apache.servicemix.eip.support.MessageUtil;
+import org.apache.servicemix.eip.support.Predicate;
+
+/**
+ * MessageFilter allows filtering incoming JBI exchanges.
+ * This component implements the  
+ * <a href="http://www.enterpriseintegrationpatterns.com/Filter.html">Message Filter</a>

+ * pattern.
+ *  
+ * @author gnodet
+ * @version $Revision: 376451 $
+ * @org.apache.xbean.XBean element="message-filter"
+ *                  description="A Message Filter"
+ */
+public class MessageFilter extends EIPEndpoint {
+
+    private static final Log log = LogFactory.getLog(MessageFilter.class);
+    
+    /**
+     * The main target destination which will receive the exchange
+     */
+    private ExchangeTarget target;
+    /**
+     * The filter to use on incoming messages
+     */
+    private Predicate filter;
+    /**
+     * The correlation property used by this component
+     */
+    private String correlation;
+    /**
+     * Indicates if faults and errors from recipients should be sent
+     * back to the consumer.  In such a case, only the first fault or
+     * error received will be reported.
+     * Note that if the consumer is synchronous, it will be blocked
+     * until all recipients successfully acked the exchange, or
+     * a fault or error is reported, and the exchange will be kept in the
+     * store for recovery. 
+     */
+    private boolean reportErrors;
+    
+    /**
+     * @return Returns the target.
+     */
+    public ExchangeTarget getTarget() {
+        return target;
+    }
+
+    /**
+     * @param target The target to set.
+     */
+    public void setTarget(ExchangeTarget target) {
+        this.target = target;
+    }
+
+    /**
+     * @return Returns the filter.
+     */
+    public Predicate getFilter() {
+        return filter;
+    }
+
+    /**
+     * @param filter The filter to set.
+     */
+    public void setFilter(Predicate filter) {
+        this.filter = filter;
+    }
+
+    /**
+     * @return Returns the reportErrors.
+     */
+    public boolean isReportErrors() {
+        return reportErrors;
+    }
+
+    /**
+     * @param reportErrors The reportErrors to set.
+     */
+    public void setReportErrors(boolean reportErrors) {
+        this.reportErrors = reportErrors;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.eip.EIPEndpoint#validate()
+     */
+    public void validate() throws DeploymentException {
+        super.validate();
+        // Check target
+        if (target == null) {
+            throw new IllegalArgumentException("target should be set to a valid ExchangeTarget");
+        }
+        // Check filter
+        if (filter == null) {
+            throw new IllegalArgumentException("filter property should be set");
+        }
+        // Create correlation property
+        correlation = "MessageFilter.Correlation." + getService() + "." + getEndpoint();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.common.ExchangeProcessor#process(javax.jbi.messaging.MessageExchange)
+     */
+    public void process(MessageExchange exchange) throws Exception {
+        try {
+            // If we need to report errors, the behavior is really different,
+            // as we need to keep the incoming exchange in the store until
+            // all acks have been received
+            if (reportErrors) {
+                // TODO: implement this
+                throw new UnsupportedOperationException("Not implemented");
+            // We are in a simple fire-and-forget behaviour.
+            // This implementation is really efficient as we do not use
+            // the store at all.
+            } else {
+                if (exchange.getStatus() == ExchangeStatus.DONE) {
+                    return;
+                } else if (exchange.getStatus() == ExchangeStatus.ERROR) {
+                    return;
+                } else if (exchange instanceof InOnly == false &&
+                           exchange instanceof RobustInOnly == false) {
+                    fail(exchange, new UnsupportedOperationException("Use an InOnly or RobustInOnly
MEP"));
+                } else if (exchange.getFault() != null) {
+                    done(exchange);
+                } else {
+                    NormalizedMessage in = MessageUtil.copyIn(exchange);
+                    MessageExchange me = exchangeFactory.createExchange(exchange.getPattern());
+                    target.configureTarget(me, getContext());
+                    MessageUtil.transferToIn(in, me);
+                    if (filter.matches(me)) {
+                        send(me);
+                    }
+                    done(exchange);
+                }
+            }
+        // If an error occurs, log it and report the error back to the sender
+        // if the exchange is still ACTIVE 
+        } catch (Exception e) {
+            log.error("An exception occured while processing exchange", e);
+            if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+                fail(exchange, e);
+            }
+        }
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/DeploymentTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/DeploymentTest.java?rev=397524&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/DeploymentTest.java
(added)
+++ incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/DeploymentTest.java
Thu Apr 27 04:44:04 2006
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.eip;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.servicemix.jbi.container.JBIContainer;
+
+import junit.framework.TestCase;
+
+public class DeploymentTest extends TestCase {
+
+    protected JBIContainer container;
+    
+    protected void setUp() throws Exception {
+        container = new JBIContainer();
+        container.setUseMBeanServer(false);
+        container.setCreateMBeanServer(false);
+        container.setEmbedded(true);
+        container.init();
+    }
+    
+    protected void tearDown() throws Exception {
+        if (container != null) {
+            container.shutDown();
+        }
+    }
+    
+    public void testDeployer() throws Exception {
+        EIPComponent component = new EIPComponent();
+        container.activateComponent(component, "EIPComponent");
+
+        // Start container
+        container.start();
+
+        // Deploy SU
+        URL url = getClass().getClassLoader().getResource("su/xbean.xml");
+        File path = new File(new URI(url.toString()));
+        path = path.getParentFile();
+        component.getServiceUnitManager().deploy("su", path.getAbsolutePath());
+        component.getServiceUnitManager().start("su");
+        
+        component.getServiceUnitManager().stop("su");
+        component.getServiceUnitManager().shutDown("su");
+        component.getServiceUnitManager().undeploy("su", path.getAbsolutePath());
+    }
+    
+}

Added: incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/MessageFilterTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/MessageFilterTest.java?rev=397524&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/MessageFilterTest.java
(added)
+++ incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/MessageFilterTest.java
Thu Apr 27 04:44:04 2006
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.eip;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.xml.namespace.QName;
+
+import org.apache.activemq.util.IdGenerator;
+import org.apache.servicemix.eip.patterns.MessageFilter;
+import org.apache.servicemix.eip.support.XPathPredicate;
+import org.apache.servicemix.store.memory.MemoryStore;
+import org.apache.servicemix.tck.ReceiverComponent;
+
+public class MessageFilterTest extends AbstractEIPTest {
+
+    protected MessageFilter messageFilter;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        messageFilter = new MessageFilter();
+        messageFilter.setFilter(new XPathPredicate("/hello/@id = '1'"));
+        messageFilter.setTarget(createServiceExchangeTarget(new QName("target")));
+        configureMessageFilter();
+        activateComponent(messageFilter, "messageFilter");
+    }
+    
+    protected void configureMessageFilter() throws Exception {
+        messageFilter.setStore(new MemoryStore(new IdGenerator()) {
+            public void store(String id, Object exchange) throws IOException {
+                ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                new ObjectOutputStream(baos).writeObject(exchange);
+                super.store(id, exchange);
+            }
+        });
+    }
+
+    public void testInOnly() throws Exception {
+        ReceiverComponent rec = activateReceiver("target");
+        
+        InOnly me = client.createInOnlyExchange();
+        me.setService(new QName("messageFilter"));
+        me.getInMessage().setContent(createSource("<hello><one/><two/><three/></hello>"));
+        client.sendSync(me);
+        assertEquals(ExchangeStatus.DONE, me.getStatus());
+        
+        rec.getMessageList().assertMessagesReceived(0); 
+
+        me = client.createInOnlyExchange();
+        me.setService(new QName("messageFilter"));
+        me.getInMessage().setContent(createSource("<hello id='1'><one/><two/><three/></hello>"));
+        client.sendSync(me);
+        assertEquals(ExchangeStatus.DONE, me.getStatus());
+        
+        rec.getMessageList().assertMessagesReceived(1); 
+    }
+
+    public void testInOut() throws Exception {
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("messageFilter"));
+        me.getInMessage().setContent(createSource("<hello><one/><two/><three/></hello>"));
+        client.sendSync(me);
+        assertEquals(ExchangeStatus.ERROR, me.getStatus());
+    }
+
+}

Modified: incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/VMEIPTests.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/VMEIPTests.java?rev=397524&r1=397523&r2=397524&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/VMEIPTests.java
(original)
+++ incubator/servicemix/trunk/servicemix-eip/src/test/java/org/apache/servicemix/eip/VMEIPTests.java
Thu Apr 27 04:44:04 2006
@@ -14,6 +14,7 @@
         suite.addTestSuite(ContentBasedRouterTest.class);
         suite.addTestSuite(WireTapTest.class);
         suite.addTestSuite(StaticRecipientListTest.class);
+        suite.addTestSuite(MessageFilterTest.class);
         //$JUnit-END$
         return suite;
     }

Added: incubator/servicemix/trunk/servicemix-eip/src/test/resources/su/xbean.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-eip/src/test/resources/su/xbean.xml?rev=397524&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-eip/src/test/resources/su/xbean.xml (added)
+++ incubator/servicemix/trunk/servicemix-eip/src/test/resources/su/xbean.xml Thu Apr 27 04:44:04
2006
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:eip="http://servicemix.apache.org/eip/1.0"
+  xmlns:test="urn:test">
+
+  <eip:wire-tap service="test:wireTap" endpoint="endpoint">
+    <eip:target>
+      <eip:exchange-target service="test:target" />
+    </eip:target>
+    <eip:inListener>
+      <eip:exchange-target service="test:listener" />
+    </eip:inListener>
+  </eip:wire-tap>
+
+</beans>



Mime
View raw message