Author: jstrachan
Date: Sun Oct  8 09:39:50 2006
New Revision: 454170

URL: http://svn.apache.org/viewvc?view=rev&rev=454170
Log:
added support for ExchangeProcessor

Added:
    
incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/ExchangeProcessorBeanEndpointTest.java
    
incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/ExchangeProcessorBean.java
Modified:
    
incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java
    
incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/PlainBeanEndpointTest.java
    
incubator/servicemix/trunk/servicemix-bean/src/test/resources/spring-no-endpoints.xml

Modified: 
incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java?view=diff&rev=454170&r1=454169&r2=454170
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-bean/src/main/java/org/apache/servicemix/bean/BeanEndpoint.java
 Sun Oct  8 09:39:50 2006
@@ -19,6 +19,7 @@
 import org.aopalliance.intercept.MethodInvocation;
 import org.apache.servicemix.MessageExchangeListener;
 import org.apache.servicemix.common.ProviderEndpoint;
+import org.apache.servicemix.common.ExchangeProcessor;
 import org.apache.servicemix.bean.support.BeanInfo;
 import org.apache.servicemix.bean.support.DefaultMethodInvocationStrategy;
 import org.apache.servicemix.bean.support.MethodInvocationStrategy;
@@ -62,15 +63,26 @@
             throw new IllegalArgumentException("No 'methodInvocationStrategy' 
property set");
         }
 
+        injectBean(getBean());
+
         // TODO invoke the bean's lifecycle methods for @PostConstruct
         // could use Spring to do this?
-        injectBean(getBean());
+
+        if (getBean() instanceof ExchangeProcessor) {
+            ExchangeProcessor processor = (ExchangeProcessor) getBean();
+            processor.start();
+        }
     }
 
 
     public void stop() throws Exception {
         super.stop();
 
+        if (getBean() instanceof ExchangeProcessor) {
+            ExchangeProcessor processor = (ExchangeProcessor) getBean();
+            processor.stop();
+        }
+
         // TODO invoke the beans destroy methods for @PreDestroy
 
         // lets allow garbage collection to take place
@@ -166,6 +178,10 @@
         if (pojo instanceof MessageExchangeListener) {
             MessageExchangeListener listener = (MessageExchangeListener) pojo;
             listener.onMessageExchange(exchange);
+        }
+        else if (pojo instanceof ExchangeProcessor) {
+            ExchangeProcessor processor = (ExchangeProcessor) pojo;
+            processor.process(exchange);
         }
         else {
             MethodInvocation invocation = 
getMethodInvocationStrategy().createInvocation(pojo, getBeanInfo(), exchange, 
this);

Added: 
incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/ExchangeProcessorBeanEndpointTest.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/ExchangeProcessorBeanEndpointTest.java?view=auto&rev=454170
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/ExchangeProcessorBeanEndpointTest.java
 (added)
+++ 
incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/ExchangeProcessorBeanEndpointTest.java
 Sun Oct  8 09:39:50 2006
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.bean;
+
+import org.apache.servicemix.bean.beans.ExchangeProcessorBean;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.resolver.URIResolver;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.w3c.dom.DocumentFragment;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+
+public class ExchangeProcessorBeanEndpointTest extends SpringTestSupport {
+
+    public void 
testSendingToDynamicEndpointForExchangeProcessorBeanWithFooOperation() throws 
Exception {
+        // now lets make a request on this endpoint
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+
+        DocumentFragment epr = 
URIResolver.createWSAEPR("bean:exchangeProcessorBean");
+        ServiceEndpoint se = client.getContext().resolveEndpointReference(epr);
+        assertNotNull("We should find a service endpoint!", se);
+
+        InOnly exchange = client.createInOnlyExchange();
+        exchange.setEndpoint(se);
+        exchange.getInMessage().setContent(new 
StringSource("<hello>world</hello>"));
+        client.sendSync(exchange);
+
+        assertExchangeWorked(exchange);
+
+        ExchangeProcessorBean bean = (ExchangeProcessorBean) 
getBean("exchangeProcessorBean");
+        MessageExchange answer = bean.getLastExchange();
+
+        log.info("Bean's process() method has been invoked: " + answer);
+
+        assertNotNull("Bean's process() method should bave been invoked", 
answer);
+    }
+
+    protected void assertExchangeWorked(MessageExchange me) throws Exception {
+        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()));
+        }
+    }
+
+    protected AbstractXmlApplicationContext createBeanFactory() {
+        return new ClassPathXmlApplicationContext("spring-no-endpoints.xml");
+    }
+
+}

Modified: 
incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/PlainBeanEndpointTest.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/PlainBeanEndpointTest.java?view=diff&rev=454170&r1=454169&r2=454170
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/PlainBeanEndpointTest.java
 (original)
+++ 
incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/PlainBeanEndpointTest.java
 Sun Oct  8 09:39:50 2006
@@ -35,7 +35,7 @@
 
 public class PlainBeanEndpointTest extends SpringTestSupport {
 
-    public void testSendingToDynamicEndpointForPlainPojoWithFooOperation() 
throws Exception {
+    public void testSendingToDynamicEndpointForPlainBeanWithFooOperation() 
throws Exception {
         // now lets make a request on this endpoint
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
 
@@ -59,7 +59,7 @@
         assertNotNull("Bean's foo() method should bave been invoked", answer);
     }
 
-    public void testSendingToDynamicEndpointForPlainPojoWithBarOperation() 
throws Exception {
+    public void testSendingToDynamicEndpointForPlainBeanWithBarOperation() 
throws Exception {
         // now lets make a request on this endpoint
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
 
@@ -82,7 +82,7 @@
         assertNotNull("Bean's bar() method should bave been invoked", bar);
     }
 
-    public void 
testSendingToDynamicEndpointForPlainPojoWithPropertyExpressionParamameter() 
throws Exception {
+    public void 
testSendingToDynamicEndpointForPlainBeanWithPropertyExpressionParamameter() 
throws Exception {
         // now lets make a request on this endpoint
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
 
@@ -107,7 +107,7 @@
         assertEquals("Bean's methodWithPropertyParameter() method should bave 
been invoked", "James", answer);
     }
 
-    public void 
testSendingToDynamicEndpointForPlainPojoWithPropertyAndXPathExpressionParamameter()
 throws Exception {
+    public void 
testSendingToDynamicEndpointForPlainBeanWithPropertyAndXPathExpressionParamameter()
 throws Exception {
         // now lets make a request on this endpoint
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
 

Added: 
incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/ExchangeProcessorBean.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/ExchangeProcessorBean.java?view=auto&rev=454170
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/ExchangeProcessorBean.java
 (added)
+++ 
incubator/servicemix/trunk/servicemix-bean/src/test/java/org/apache/servicemix/bean/beans/ExchangeProcessorBean.java
 Sun Oct  8 09:39:50 2006
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+package org.apache.servicemix.bean.beans;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.common.ExchangeProcessor;
+
+import javax.jbi.messaging.MessageExchange;
+
+/**
+ * A simple POJO which implements the [EMAIL PROTECTED] ExchangeProcessor} 
interface
+ *
+ * @version $Revision: $
+ */
+public class ExchangeProcessorBean implements ExchangeProcessor {
+
+    private static final Log log = 
LogFactory.getLog(ExchangeProcessorBean.class);
+
+    private MessageExchange lastExchange;
+    private String param;
+
+    public void process(MessageExchange messageExchange) throws Exception {
+        this.lastExchange = messageExchange;
+
+        log.info("Received exchange: " + messageExchange);
+    }
+
+    public void start() throws Exception {
+    }
+
+    public void stop() throws Exception {
+    }
+
+    public MessageExchange getLastExchange() {
+        return lastExchange;
+    }
+
+
+    public String getParam() {
+        return param;
+    }
+
+    public void setParam(String param) {
+        this.param = param;
+    }
+
+
+}

Modified: 
incubator/servicemix/trunk/servicemix-bean/src/test/resources/spring-no-endpoints.xml
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-bean/src/test/resources/spring-no-endpoints.xml?view=diff&rev=454170&r1=454169&r2=454170
==============================================================================
--- 
incubator/servicemix/trunk/servicemix-bean/src/test/resources/spring-no-endpoints.xml
 (original)
+++ 
incubator/servicemix/trunk/servicemix-bean/src/test/resources/spring-no-endpoints.xml
 Sun Oct  8 09:39:50 2006
@@ -34,6 +34,7 @@
     </sm:activationSpecs>
   </sm:container>
 
+  <bean id="exchangeProcessorBean" 
class="org.apache.servicemix.bean.beans.ExchangeProcessorBean"/>
   <bean id="listenerBean" 
class="org.apache.servicemix.bean.beans.ListenerBean"/>
   <bean id="annotationsBean" 
class="org.apache.servicemix.bean.beans.AnnotatedBean"/>
   <bean id="plainBean" class="org.apache.servicemix.bean.beans.PlainBean"/>


Reply via email to