servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r633813 - in /servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src: main/java/org/apache/servicemix/script/ test/java/org/apache/servicemix/script/ test/resources/
Date Wed, 05 Mar 2008 11:00:05 GMT
Author: gnodet
Date: Wed Mar  5 03:00:02 2008
New Revision: 633813

URL: http://svn.apache.org/viewvc?rev=633813&view=rev
Log:
SM-1261: Allow script component to send InOut exchanges as a consumer

Added:
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/test/resources/GroovyConsumerExchangeProcessor.groovy
      - copied unchanged from r633812, servicemix/smx3/trunk/deployables/serviceengines/servicemix-script/src/test/resources/GroovyConsumerExchangeProcessor.groovy
Modified:
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeHelper.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeProcessorEndpoint.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/test/java/org/apache/servicemix/script/ScriptComponentTest.java
    servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/test/resources/spring.xml

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeHelper.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeHelper.java?rev=633813&r1=633812&r2=633813&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeHelper.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeHelper.java
Wed Mar  5 03:00:02 2008
@@ -16,7 +16,10 @@
  */
 package org.apache.servicemix.script;
 
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.DeliveryChannel;
 import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessageExchangeFactory;
 import javax.jbi.messaging.MessagingException;
 
 /**
@@ -50,5 +53,21 @@
 
     public void sendExchange(MessageExchange exchange) throws MessagingException {
         endpoint.send(exchange);
+    }
+
+    public void sendSyncExchange(MessageExchange exchange) throws MessagingException {
+        endpoint.sendSync(exchange);
+    }
+
+    public DeliveryChannel getChannel() {
+        return endpoint.getChannel();
+    }
+
+    public ComponentContext getContext() {
+        return endpoint.getContext();
+    }
+
+    public MessageExchangeFactory getExchangeFactory() {
+        return endpoint.getExchangeFactory();
     }
 }

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeProcessorEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeProcessorEndpoint.java?rev=633813&r1=633812&r2=633813&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeProcessorEndpoint.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/main/java/org/apache/servicemix/script/ScriptExchangeProcessorEndpoint.java
Wed Mar  5 03:00:02 2008
@@ -20,94 +20,25 @@
 import java.util.Iterator;
 import java.util.List;
 
-import javax.jbi.component.ComponentContext;
-import javax.jbi.management.DeploymentException;
-import javax.jbi.messaging.DeliveryChannel;
-import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.MessageExchange;
-import javax.jbi.messaging.MessageExchange.Role;
 import javax.jbi.messaging.MessagingException;
-import javax.jbi.servicedesc.ServiceEndpoint;
 
-import org.apache.servicemix.common.BaseLifeCycle;
-import org.apache.servicemix.common.Endpoint;
 import org.apache.servicemix.common.ExchangeProcessor;
+import org.apache.servicemix.common.endpoints.ProviderEndpoint;
 
 /**
  * @org.apache.xbean.XBean element="exchangeProcessor"
  */
-public class ScriptExchangeProcessorEndpoint extends Endpoint implements ExchangeProcessor
{
-
-    private ServiceEndpoint activated;
-
-    private DeliveryChannel channel;
+public class ScriptExchangeProcessorEndpoint extends ProviderEndpoint {
 
     private ExchangeProcessor implementation;
 
     private List helpers = new ArrayList();
 
-    public void activate() throws Exception {
-        logger = this.serviceUnit.getComponent().getLogger();
-        ComponentContext ctx = getServiceUnit().getComponent().getComponentContext();
-        channel = ctx.getDeliveryChannel();
-        activated = ctx.activateEndpoint(service, endpoint);
-        start();
-    }
-
-    public void deactivate() throws Exception {
-        stop();
-        ServiceEndpoint ep = activated;
-        activated = null;
-        ComponentContext ctx = getServiceUnit().getComponent().getComponentContext();
-        ctx.deactivateEndpoint(ep);
-    }
-
-    protected void done(MessageExchange me) throws MessagingException {
-        me.setStatus(ExchangeStatus.DONE);
-        send(me);
-    }
-
-    protected void fail(MessageExchange me, Exception error) throws MessagingException {
-        me.setError(error);
-        send(me);
-    }
-
     public List getHelpers() {
         return helpers;
     }
 
-    public ExchangeProcessor getImplementation() {
-        return implementation;
-    }
-
-    public ExchangeProcessor getProcessor() {
-        return this;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.servicemix.common.Endpoint#getRole()
-     */
-    public Role getRole() {
-        return Role.PROVIDER;
-    }
-
-    public void process(MessageExchange exchange) throws Exception {
-        if (implementation != null) {
-            implementation.process(exchange);
-        }
-    }
-
-    protected void send(MessageExchange me) throws MessagingException {
-        if (me.getRole() == MessageExchange.Role.CONSUMER && me.getStatus() == ExchangeStatus.ACTIVE)
{
-            BaseLifeCycle lf = (BaseLifeCycle) getServiceUnit().getComponent().getLifeCycle();
-            lf.sendConsumerExchange(me, (Endpoint) this);
-        } else {
-            channel.send(me);
-        }
-    }
-
     public void setHelpers(List helpers) {
         this.helpers = helpers;
         for (Iterator iterator = helpers.iterator(); iterator.hasNext();) {
@@ -118,17 +49,23 @@
         }
     }
 
+    public ExchangeProcessor getImplementation() {
+        return implementation;
+    }
+
     public void setImplementation(ExchangeProcessor implementation) {
         this.implementation = implementation;
     }
 
     public void start() throws Exception {
+        super.start();
+        logger = this.serviceUnit.getComponent().getLogger();
         if (implementation != null) {
             implementation.start();
         }
     }
 
-    public void stop() {
+    public void stop() throws Exception {
         if (implementation != null) {
             try {
                 implementation.stop();
@@ -136,10 +73,28 @@
                 e.printStackTrace();
             }
         }
+        super.stop();
+    }
+
+    public void process(MessageExchange exchange) throws Exception {
+        if (implementation != null) {
+            implementation.process(exchange);
+        }
+    }
 
+    protected void fail(MessageExchange messageExchange, Exception e) throws MessagingException
{
+        super.fail(messageExchange, e);
     }
 
-    public void validate() throws DeploymentException {
+    protected void send(MessageExchange messageExchange) throws MessagingException {
+        super.send(messageExchange);
     }
 
+    protected void sendSync(MessageExchange messageExchange) throws MessagingException {
+        super.sendSync(messageExchange);
+    }
+
+    protected void done(MessageExchange messageExchange) throws MessagingException {
+        super.done(messageExchange);
+    }
 }

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/test/java/org/apache/servicemix/script/ScriptComponentTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/test/java/org/apache/servicemix/script/ScriptComponentTest.java?rev=633813&r1=633812&r2=633813&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/test/java/org/apache/servicemix/script/ScriptComponentTest.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/test/java/org/apache/servicemix/script/ScriptComponentTest.java
Wed Mar  5 03:00:02 2008
@@ -50,7 +50,26 @@
         log.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
         client.done(me);
     }
-    
+
+    public void testGroovyConsumer() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("urn:test", "groovyConsumer"));
+        me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
+        client.sendSync(me);
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else if (me.getFault() != null) {
+            fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+        }
+        log.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
+        client.done(me);
+    }
+
     public void testRuby() throws Exception {
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
         InOut me = client.createInOutExchange();

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/test/resources/spring.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/test/resources/spring.xml?rev=633813&r1=633812&r2=633813&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/test/resources/spring.xml
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/serviceengines/servicemix-script/src/test/resources/spring.xml
Wed Mar  5 03:00:02 2008
@@ -1,76 +1,94 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!--
-	
-	Licensed to the Apache Software Foundation (ASF) under one or more
-	contributor license agreements.  See the NOTICE file distributed with
-	this work for additional information regarding copyright ownership.
-	The ASF licenses this file to You 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.
-	
+<!--
+	
+	Licensed to the Apache Software Foundation (ASF) under one or more
+	contributor license agreements.  See the NOTICE file distributed with
+	this work for additional information regarding copyright ownership.
+	The ASF licenses this file to You 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.
+	
 -->
-<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
-	xmlns:script="http://org.apache.servicemix/script/1.0"
-	xmlns:lang="http://www.springframework.org/schema/lang"
-	xmlns:test="urn:test">
-
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+	xmlns:script="http://org.apache.servicemix/script/1.0"
+	xmlns:lang="http://www.springframework.org/schema/lang"
+	xmlns:test="urn:test">
+
 	<sm:container id="jbi" embedded="true" createMBeanServer="false">
 		<sm:activationSpecs>
-			<sm:activationSpec>
+			<sm:activationSpec service="test:echo">
 				<sm:component>
-					<script:component>
-						<script:endpoints>
-							<!-- Groovy Endpoint  -->
-							<script:exchangeProcessor
-								service="test:groovy" endpoint="endpoint">
-								<property name="helpers">
-									<list>
-										<ref bean="groovyExchangeHelper" />
-									</list>
-								</property>
-								<property name="implementation"
-									ref="groovyExchangeProcessor" />
-							</script:exchangeProcessor>
-
-							<!-- JRuby Endpoint  -->
-							<script:exchangeProcessor
-								service="test:jruby" endpoint="endpoint">
-								<property name="helpers">
-									<list>
-										<ref bean="jrubyExchangeHelper" />
-									</list>
-								</property>
-								<property name="implementation"
-									ref="jrubyExchangeProcessor" />
-							</script:exchangeProcessor>
-						</script:endpoints>
-					</script:component>
-				</sm:component>
-			</sm:activationSpec>
-		</sm:activationSpecs>
-	</sm:container>
-
-	<script:exchangeHelper id="groovyExchangeHelper" singleton="true" />
-
-	<script:exchangeHelper id="jrubyExchangeHelper" singleton="true" />
-
-	<lang:groovy id="groovyExchangeProcessor"
-		script-source="classpath:GroovyExchangeProcessor.groovy">
-		<lang:property name="exchangeHelper" ref="groovyExchangeHelper" />
-	</lang:groovy>
-
-	<lang:jruby id="jrubyExchangeProcessor"
-		script-interfaces="org.apache.servicemix.common.ExchangeProcessor"
-		script-source="classpath:RubyExchangeProcessor.rb">
-		<lang:property name="exchangeHelper" ref="jrubyExchangeHelper" />
-	</lang:jruby>
-
+                    <bean class="org.apache.servicemix.components.util.EchoComponent"
/>
+                </sm:component>
+            </sm:activationSpec>
+        </sm:activationSpecs>
+
+        <sm:endpoints>
+
+            <!-- Groovy Endpoint  -->
+            <script:exchangeProcessor
+                service="test:groovy" endpoint="endpoint">
+                <property name="helpers">
+                    <list>
+                        <ref bean="groovyExchangeHelper" />
+                    </list>
+                </property>
+                <property name="implementation" ref="groovyExchangeProcessor" />
+            </script:exchangeProcessor>
+
+            <!-- Groovy Endpoint  -->
+            <script:exchangeProcessor
+                service="test:groovyConsumer" endpoint="endpoint">
+                <property name="helpers">
+                    <list>
+                        <ref bean="groovyConsumerExchangeHelper" />
+                    </list>
+                </property>
+                <property name="implementation" ref="groovyConsumerExchangeProcessor"
/>
+            </script:exchangeProcessor>
+
+            <!-- JRuby Endpoint  -->
+            <script:exchangeProcessor
+                service="test:jruby" endpoint="endpoint">
+                <property name="helpers">
+                    <list>
+                        <ref bean="jrubyExchangeHelper" />
+                    </list>
+                </property>
+                <property name="implementation" ref="jrubyExchangeProcessor" />
+            </script:exchangeProcessor>
+
+        </sm:endpoints>
+    </sm:container>
+
+    <script:exchangeHelper id="groovyExchangeHelper" singleton="true" />
+
+    <script:exchangeHelper id="groovyConsumerExchangeHelper" singleton="true" />
+
+	<script:exchangeHelper id="jrubyExchangeHelper" singleton="true" />
+
+    <lang:groovy id="groovyExchangeProcessor"
+        script-source="classpath:GroovyExchangeProcessor.groovy">
+        <lang:property name="exchangeHelper" ref="groovyExchangeHelper" />
+    </lang:groovy>
+
+    <lang:groovy id="groovyConsumerExchangeProcessor"
+        script-source="classpath:GroovyConsumerExchangeProcessor.groovy">
+        <lang:property name="exchangeHelper" ref="groovyConsumerExchangeHelper" />
+    </lang:groovy>
+
+	<lang:jruby id="jrubyExchangeProcessor"
+		script-interfaces="org.apache.servicemix.common.ExchangeProcessor"
+		script-source="classpath:RubyExchangeProcessor.rb">
+		<lang:property name="exchangeHelper" ref="jrubyExchangeHelper" />
+	</lang:jruby>
+
 </beans>



Mime
View raw message