You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/09/28 09:30:04 UTC
svn commit: r1002043 - in /camel/trunk/tests/camel-itest-osgi: ./
src/main/resources/ src/test/java/org/apache/camel/itest/osgi/cxf/
src/test/resources/org/apache/camel/itest/osgi/cxf/
Author: davsclaus
Date: Tue Sep 28 07:30:03 2010
New Revision: 1002043
URL: http://svn.apache.org/viewvc?rev=1002043&view=rev
Log:
CAMEL-3126: Added part of CXF test for osgi.
Added:
camel/trunk/tests/camel-itest-osgi/src/main/resources/report_incident.wsdl
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/CxfProxyExampleTest.java
- copied, changed from r1002017, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/spring/bean/SpringBeanRouteTest.java
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/EnrichBean.java
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/RealWebServiceBean.java
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/ReportIncidentEndpointService.java
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cxf/
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cxf/camel-config.xml
Modified:
camel/trunk/tests/camel-itest-osgi/pom.xml
Modified: camel/trunk/tests/camel-itest-osgi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/pom.xml?rev=1002043&r1=1002042&r2=1002043&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/pom.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/pom.xml Tue Sep 28 07:30:03 2010
@@ -209,6 +209,30 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-cxf</artifactId>
+ </dependency>
+
+ <!-- cxf -->
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-core</artifactId>
+ <version>${cxf-version}</version>
+ </dependency>
+ <!-- used by the real web service -->
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-frontend-jaxws</artifactId>
+ <version>${cxf-version}</version>
+ </dependency>
+ <!-- regular http transport -->
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http</artifactId>
+ <version>${cxf-version}</version>
+ </dependency>
+
</dependencies>
<build>
@@ -242,6 +266,31 @@
</systemPropertyVariables>
</configuration>
</plugin>
+
+ <!-- CXF wsdl2java generator, will plugin to the compile goal -->
+ <plugin>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-codegen-plugin</artifactId>
+ <version>${cxf-version}</version>
+ <executions>
+ <execution>
+ <id>generate-sources</id>
+ <phase>generate-sources</phase>
+ <configuration>
+ <sourceRoot>${basedir}/target/generated/src/main/java</sourceRoot>
+ <wsdlOptions>
+ <wsdlOption>
+ <wsdl>${basedir}/src/main/resources/report_incident.wsdl</wsdl>
+ </wsdlOption>
+ </wsdlOptions>
+ </configuration>
+ <goals>
+ <goal>wsdl2java</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
</plugins>
</build>
Added: camel/trunk/tests/camel-itest-osgi/src/main/resources/report_incident.wsdl
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/main/resources/report_incident.wsdl?rev=1002043&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/main/resources/report_incident.wsdl (added)
+++ camel/trunk/tests/camel-itest-osgi/src/main/resources/report_incident.wsdl Tue Sep 28 07:30:03 2010
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ 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.
+-->
+
+<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:tns="http://reportincident.example.camel.apache.org"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ targetNamespace="http://reportincident.example.camel.apache.org">
+
+ <!-- Type definitions for input- and output parameters for webservice -->
+ <wsdl:types>
+ <xs:schema targetNamespace="http://reportincident.example.camel.apache.org">
+ <xs:element name="inputReportIncident">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element type="xs:string" name="incidentId"/>
+ <xs:element type="xs:string" name="incidentDate"/>
+ <xs:element type="xs:string" name="givenName"/>
+ <xs:element type="xs:string" name="familyName"/>
+ <xs:element type="xs:string" name="summary"/>
+ <xs:element type="xs:string" name="details"/>
+ <xs:element type="xs:string" name="email"/>
+ <xs:element type="xs:string" name="phone"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="outputReportIncident">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element type="xs:string" name="code"/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:schema>
+ </wsdl:types>
+
+ <!-- Message definitions for input and output -->
+ <wsdl:message name="inputReportIncident">
+ <wsdl:part name="in" element="tns:inputReportIncident"/>
+ </wsdl:message>
+ <wsdl:message name="outputReportIncident">
+ <wsdl:part name="out" element="tns:outputReportIncident"/>
+ </wsdl:message>
+
+ <!-- Port (interface) definitions -->
+ <wsdl:portType name="ReportIncidentEndpoint">
+ <wsdl:operation name="ReportIncident">
+ <wsdl:input message="tns:inputReportIncident"/>
+ <wsdl:output message="tns:outputReportIncident"/>
+ </wsdl:operation>
+ </wsdl:portType>
+
+ <!-- Port bindings to transports and encoding - HTTP, document literal encoding is used -->
+ <wsdl:binding name="ReportIncidentBinding" type="tns:ReportIncidentEndpoint">
+ <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
+ <wsdl:operation name="ReportIncident">
+ <soap:operation
+ soapAction="http://reportincident.example.camel.apache.org/ReportIncident"
+ style="document"/>
+ <wsdl:input>
+ <soap:body parts="in" use="literal"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body parts="out" use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+
+ <!-- Service definition -->
+ <wsdl:service name="ReportIncidentEndpointService">
+ <wsdl:port name="ReportIncidentService" binding="tns:ReportIncidentBinding">
+ <soap:address location="http://localhost:9080/camel-itest-osgi/webservices/incident"/>
+ </wsdl:port>
+ </wsdl:service>
+
+</wsdl:definitions>
Copied: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/CxfProxyExampleTest.java (from r1002017, camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/spring/bean/SpringBeanRouteTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/CxfProxyExampleTest.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/CxfProxyExampleTest.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/spring/bean/SpringBeanRouteTest.java&r1=1002017&r2=1002043&rev=1002043&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/spring/bean/SpringBeanRouteTest.java (original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/CxfProxyExampleTest.java Tue Sep 28 07:30:03 2010
@@ -14,9 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.itest.osgi.spring.bean;
+package org.apache.camel.itest.osgi.cxf;
+import org.apache.camel.example.reportincident.InputReportIncident;
+import org.apache.camel.example.reportincident.OutputReportIncident;
+import org.apache.camel.example.reportincident.ReportIncidentEndpoint;
import org.apache.camel.itest.osgi.OSGiIntegrationSpringTestSupport;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
@@ -25,44 +30,70 @@ import org.ops4j.pax.exam.junit.JUnit4Te
import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
import static org.ops4j.pax.exam.CoreOptions.equinox;
-import static org.ops4j.pax.exam.CoreOptions.felix;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.workingDirectory;
@RunWith(JUnit4TestRunner.class)
-public class SpringBeanRouteTest extends OSGiIntegrationSpringTestSupport {
+@Ignore
+public class CxfProxyExampleTest extends OSGiIntegrationSpringTestSupport {
- @Test
- public void testBean() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+ protected static ReportIncidentEndpoint createCXFClient() {
+ // we use CXF to create a client for us as its easier than JAXWS and works
+ JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
+ factory.setServiceClass(ReportIncidentEndpoint.class);
+ factory.setAddress("http://localhost:9080/camel-itest-osgi/webservices/incident");
+ return (ReportIncidentEndpoint) factory.create();
+ }
- template.sendBody("direct:start", "World");
+ @Test
+ public void testCxfProxy() throws Exception {
+ // create input parameter
+ InputReportIncident input = new InputReportIncident();
+ input.setIncidentId("123");
+ input.setIncidentDate("2010-09-28");
+ input.setGivenName("Claus");
+ input.setFamilyName("Ibsen");
+ input.setSummary("Bla");
+ input.setDetails("Bla bla");
+ input.setEmail("davsclaus@apache.org");
+ input.setPhone("12345678");
+
+ // create the webservice client and send the request
+ ReportIncidentEndpoint client = createCXFClient();
+ OutputReportIncident out = client.reportIncident(input);
- assertMockEndpointsSatisfied();
+ // assert we got a OK back
+ assertEquals("OK;456", out.getCode());
}
@Override
protected OsgiBundleXmlApplicationContext createApplicationContext() {
- return new OsgiBundleXmlApplicationContext(new String[]{"org/apache/camel/itest/osgi/spring/bean/CamelContext.xml"});
+ return new OsgiBundleXmlApplicationContext(new String[]{"org/apache/camel/itest/osgi/cxf/camel-config.xml"});
}
+ // TODO: CxfConsumer should use OSGi http service (no embedded Jetty)
+ // TODO: Make this test work with OSGi
+
@Configuration
public static Option[] configure() {
Option[] options = options(
// install the spring dm profile
profile("spring.dm").version("1.2.0"),
+ profile("compendium"),
+ profile("web"),
+
// this is how you set the default log level when using pax logging (logProfile)
org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
// using the features to install the camel components
scanFeatures(getCamelKarafFeatureUrl(),
- "camel-core", "camel-spring", "camel-test"),
+ "camel-core", "camel-spring", "camel-test", "camel-cxf"),
workingDirectory("target/paxrunner/"),
- felix(), equinox());
+ equinox());
return options;
}
Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/EnrichBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/EnrichBean.java?rev=1002043&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/EnrichBean.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/EnrichBean.java Tue Sep 28 07:30:03 2010
@@ -0,0 +1,33 @@
+/**
+ * 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.camel.itest.osgi.cxf;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * @version $Revision$
+ */
+public class EnrichBean {
+
+ public Document enrich(Document doc) {
+ Node node = doc.getElementsByTagName("incidentId").item(0);
+ node.setTextContent("456");
+ return doc;
+ }
+
+}
Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/RealWebServiceBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/RealWebServiceBean.java?rev=1002043&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/RealWebServiceBean.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/RealWebServiceBean.java Tue Sep 28 07:30:03 2010
@@ -0,0 +1,50 @@
+/**
+ * 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.camel.itest.osgi.cxf;
+
+import javax.xml.ws.Endpoint;
+
+/**
+ * @version $Revision$
+ */
+public class RealWebServiceBean {
+
+ // should be the same address as we have in our route
+ private String url = "http://localhost:9081/real-webservice";
+
+ private ReportIncidentEndpointService service = new ReportIncidentEndpointService();
+ private Endpoint endpoint;
+
+ public void start() throws Exception {
+ endpoint = Endpoint.publish(url, service);
+ }
+
+ public void stop() throws Exception {
+ if (endpoint != null) {
+ endpoint.stop();
+ }
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+}
Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/ReportIncidentEndpointService.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/ReportIncidentEndpointService.java?rev=1002043&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/ReportIncidentEndpointService.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cxf/ReportIncidentEndpointService.java Tue Sep 28 07:30:03 2010
@@ -0,0 +1,34 @@
+/**
+ * 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.camel.itest.osgi.cxf;
+
+import org.apache.camel.example.reportincident.InputReportIncident;
+import org.apache.camel.example.reportincident.OutputReportIncident;
+import org.apache.camel.example.reportincident.ReportIncidentEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class ReportIncidentEndpointService implements ReportIncidentEndpoint {
+
+ public OutputReportIncident reportIncident(InputReportIncident in) {
+ OutputReportIncident out = new OutputReportIncident();
+ out.setCode("OK;" + in.getIncidentId());
+ return out;
+ }
+
+}
Added: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cxf/camel-config.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cxf/camel-config.xml?rev=1002043&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cxf/camel-config.xml (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/cxf/camel-config.xml Tue Sep 28 07:30:03 2010
@@ -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="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:camel="http://camel.apache.org/schema/spring"
+ xmlns:cxf="http://camel.apache.org/schema/cxf"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd">
+
+ <!-- needed cxf imports -->
+ <import resource="classpath:META-INF/cxf/cxf.xml"/>
+ <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
+ <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml"/>
+
+ <!-- use a bean to start and stop the real web service (is not Camel specific) -->
+ <!-- in a real use-case the real web service would be located on another server
+ but we simulate this in the same JVM -->
+ <bean id="realWebService" class="org.apache.camel.itest.osgi.cxf.RealWebServiceBean"
+ init-method="start" destroy-method="stop">
+ <!-- this is the url of the real web service we have proxied -->
+ <property name="url" value="http://localhost:9081/real-webservice"/>
+ </bean>
+
+ <!-- a bean to enrich the input -->
+ <bean id="enrichBean" class="org.apache.camel.example.cxf.proxy.EnrichBean"/>
+
+ <!-- this is the CXF webservice we use as front end -->
+ <cxf:cxfEndpoint id="reportIncident"
+ address="http://localhost:9080/camel-itest-osgi/webservices/incident"
+ serviceClass="org.apache.camel.itest.osgi.cxf.ReportIncidentEndpoint"
+ wsdlURL="report_incident.wsdl"/>
+
+ <!-- this is the camel route which proxy the web service and forward it to the real web service -->
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <route>
+ <!-- cxf consumer using MESSAGE format -->
+ <from uri="cxf:bean:reportIncident?dataFormat=MESSAGE"/>
+ <!-- log input received -->
+ <to uri="log:input"/>
+ <!-- enrich the input by ensure the incidentId parameter is set -->
+ <to uri="bean:enrichBean"/>
+ <!-- send proxied request to real web service -->
+ <to uri="http://localhost:9081/real-webservice?throwExceptionOnFailure=false"/>
+ <!-- log answer from real web service -->
+ <to uri="log:output"/>
+ </route>
+
+ </camelContext>
+
+</beans>