You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2007/09/26 09:33:26 UTC
svn commit: r579493 - in
/incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se:
./ src/main/java/org/apache/servicemix/cxfse/
src/test/java/org/apache/servicemix/cxfse/
src/test/resources/org/apache/servicemix/cxfse/
Author: ffang
Date: Wed Sep 26 00:33:25 2007
New Revision: 579493
URL: http://svn.apache.org/viewvc?rev=579493&view=rev
Log:
[SM-1060] CXF SE support ComponentContext injection
Added:
incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/CxfSeContextInjectionTest.java (with props)
incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/GreeterImpl.java (with props)
incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/context-injection.xml (with props)
Modified:
incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/pom.xml
incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java
incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/spring.xml
Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/pom.xml?rev=579493&r1=579492&r2=579493&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/pom.xml (original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/pom.xml Wed Sep 26 00:33:25 2007
@@ -34,6 +34,7 @@
<description>A CXF Service Engine</description>
<properties>
+ <surefire.fork.mode>pertest</surefire.fork.mode>
</properties>
<dependencies>
@@ -174,6 +175,7 @@
<!-- exclude abstract test cases -->
<exclude>**/Abstract*.*</exclude>
</excludes>
+ <forkMode>${surefire.fork.mode}</forkMode>
</configuration>
</plugin>
</plugins>
Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java?rev=579493&r1=579492&r2=579493&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java (original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/main/java/org/apache/servicemix/cxfse/CxfSeEndpoint.java Wed Sep 26 00:33:25 2007
@@ -17,11 +17,14 @@
package org.apache.servicemix.cxfse;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
+import javax.jbi.component.ComponentContext;
import javax.jbi.management.DeploymentException;
import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.ExchangeStatus;
@@ -71,6 +74,8 @@
private List<Interceptor> outFault = new CopyOnWriteArrayList<Interceptor>();
private List<Interceptor> inFault = new CopyOnWriteArrayList<Interceptor>();
+
+ private Map properties;
/**
* @return the pojo
@@ -119,6 +124,15 @@
outFault = interceptors;
}
+ public Map getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map properties) {
+ this.properties = properties;
+ }
+
+
/*
* (non-Javadoc)
*
@@ -204,6 +218,7 @@
}
});
ReflectionUtils.callLifecycleMethod(getPojo(), PostConstruct.class);
+ injectPojo();
}
/*
@@ -223,4 +238,17 @@
return ((CxfSeComponent) getServiceUnit().getComponent()).getBus();
}
+
+ @PostConstruct
+ protected void injectPojo() {
+ try {
+ Method mth = pojo.getClass().getMethod("setContext", new Class[] {ComponentContext.class });
+ if (mth != null) {
+ mth.invoke(pojo, new Object[] {getContext()});
+ }
+ } catch (Exception e) {
+ logger.debug("Unable to inject ComponentContext: " + e.getMessage());
+ }
+
+ }
}
Added: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/CxfSeContextInjectionTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/CxfSeContextInjectionTest.java?rev=579493&view=auto
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/CxfSeContextInjectionTest.java (added)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/CxfSeContextInjectionTest.java Wed Sep 26 00:33:25 2007
@@ -0,0 +1,72 @@
+/*
+ * 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.cxfse;
+
+import java.util.logging.Logger;
+
+import javax.jbi.messaging.InOut;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+public class CxfSeContextInjectionTest extends SpringTestSupport {
+
+ private static final Logger LOG = Logger.getLogger(CxfSeContextInjectionTest.class.getName());
+ private DefaultServiceMixClient client;
+ private InOut io;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ client = new DefaultServiceMixClient(jbi);
+ io = client.createInOutExchange();
+ io.setService(new QName("http://apache.org/hello_world_soap_http", "SOAPService"));
+ io.setInterfaceName(new QName("http://apache.org/hello_world_soap_http", "Greeter"));
+ io.setOperation(new QName("http://apache.org/hello_world_soap_http", "greetMe"));
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testContextInjection() throws Exception {
+ LOG.info("test Injection");
+ io.getInMessage().setContent(new StringSource(
+ "<message xmlns='http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper'>"
+ + "<part> "
+ + "<greetMe xmlns='http://apache.org/hello_world_soap_http/types'><requestType>"
+ + "ffang"
+ + "</requestType></greetMe>"
+ + "</part> "
+ + "</message>"));
+ client.sendSync(io);
+ // the injected context belong to servicemix-cxfse component
+ assertTrue(new SourceTransformer().contentToString(
+ io.getOutMessage()).indexOf("Hello ffang servicemix-cxfse") > 0);
+
+ }
+
+ @Override
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/cxfse/context-injection.xml");
+ }
+
+}
Propchange: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/CxfSeContextInjectionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/CxfSeContextInjectionTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/GreeterImpl.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/GreeterImpl.java?rev=579493&view=auto
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/GreeterImpl.java (added)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/GreeterImpl.java Wed Sep 26 00:33:25 2007
@@ -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.cxfse;
+
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.client.ServiceMixClientFacade;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+@WebService(serviceName = "SOAPService",
+ portName = "SoapPort",
+ endpointInterface = "org.apache.hello_world_soap_http.Greeter",
+ targetNamespace = "http://apache.org/hello_world_soap_http")
+
+public class GreeterImpl {
+
+ private ComponentContext context;
+ public String greetMe(String me) {
+ try {
+
+ // here use client api to test the injected context to invoke another endpoint
+ ServiceMixClient client = new ServiceMixClientFacade(this.context);
+ InOut exchange = client.createInOutExchange();
+ NormalizedMessage message = exchange.getInMessage();
+
+ message.setContent(new StringSource(
+ "<message xmlns='http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper'>"
+ + " <part>"
+ + " <add xmlns='http://apache.org/cxf/calculator/types'>"
+ + " <arg0>1</arg0>"
+ + " <arg1>2</arg1>"
+ + " </add>"
+ + " </part>"
+ + "</message>"));
+
+ exchange.setService(new QName("http://apache.org/cxf/calculator", "CalculatorService"));
+ exchange.setInterfaceName(new QName("http://apache.org/cxf/calculator", "CalculatorPortType"));
+ exchange.setOperation(new QName("http://apache.org/cxf/calculator", "add"));
+ client.sendSync(exchange);
+
+ } catch (JBIException e) {
+ //
+ }
+ return "Hello " + me + " " + context.getComponentName();
+ }
+
+ public ComponentContext getContext() {
+ return context;
+ }
+
+ public void setContext(ComponentContext context) {
+ this.context = context;
+ }
+
+
+}
Propchange: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/GreeterImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/java/org/apache/servicemix/cxfse/GreeterImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/context-injection.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/context-injection.xml?rev=579493&view=auto
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/context-injection.xml (added)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/context-injection.xml Wed Sep 26 00:33:25 2007
@@ -0,0 +1,69 @@
+<?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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:cxfse="http://servicemix.apache.org/cxfse/1.0"
+ xmlns:test="urn:test">
+
+ <sm:container id="jbi" embedded="true">
+
+ <sm:endpoints>
+ <cxfse:endpoint>
+ <cxfse:pojo>
+ <bean class="org.apache.cxf.calculator.CalculatorImpl">
+ </bean>
+
+ </cxfse:pojo>
+ <cxfse:inInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+ </cxfse:inInterceptors>
+ <cxfse:outInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+ </cxfse:outInterceptors>
+ <cxfse:inFaultInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+ </cxfse:inFaultInterceptors>
+ <cxfse:outFaultInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+ </cxfse:outFaultInterceptors>
+ </cxfse:endpoint>
+ <cxfse:endpoint>
+ <cxfse:pojo>
+ <bean class="org.apache.servicemix.cxfse.GreeterImpl">
+ </bean>
+
+ </cxfse:pojo>
+ <cxfse:inInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+ </cxfse:inInterceptors>
+ <cxfse:outInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+ </cxfse:outInterceptors>
+ <cxfse:inFaultInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+ </cxfse:inFaultInterceptors>
+ <cxfse:outFaultInterceptors>
+ <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
+ </cxfse:outFaultInterceptors>
+ </cxfse:endpoint>
+ </sm:endpoints>
+
+ </sm:container>
+
+</beans>
Propchange: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/context-injection.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/context-injection.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/context-injection.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/spring.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/spring.xml?rev=579493&r1=579492&r2=579493&view=diff
==============================================================================
--- incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/spring.xml (original)
+++ incubator/servicemix/trunk/deployables/serviceengines/servicemix-cxf-se/src/test/resources/org/apache/servicemix/cxfse/spring.xml Wed Sep 26 00:33:25 2007
@@ -26,7 +26,9 @@
<sm:endpoints>
<cxfse:endpoint>
<cxfse:pojo>
- <bean class="org.apache.cxf.calculator.CalculatorImpl" />
+ <bean class="org.apache.cxf.calculator.CalculatorImpl">
+ </bean>
+
</cxfse:pojo>
<cxfse:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>