Skip to content

Commit 35239aa

Browse files
committed
Initial commit
0 parents  commit 35239aa

File tree

43 files changed

+2025
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2025
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

Acknowledgments.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Based on the source code originally developed by Adrian Trenaman,
2+
for a serious of CXF Webinars broadcast by FuseSource.

LICENSE.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2011 FuseSource
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

README.txt

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
These demos have been built and tested using JBoss Fuse 6.1 (beta) build 337
2+
3+
Building the examples
4+
---------------------
5+
The examples are built using Apache Maven. To build all of the examples (and install the
6+
corresponding artifacts in your local Maven repository) enter the following commands from
7+
the top-level directory of the examples:
8+
9+
$ cd parent
10+
$ mvn install
11+
$ cd ..
12+
$ mvn install
13+
14+
15+
Installing the customer-ws-osgi-bundle
16+
--------------------------------------
17+
The 'customer-ws-osgi-bundle' deploys a simple web service listening on ServiceMix's
18+
HTTP port (by default, this is port 8181). To install and start the bundle, just do
19+
20+
karaf@root> install -s mvn:com.fusesource.byexample.cxf-webinars/customer-ws-osgi-bundle
21+
22+
You will now find that the server is listening on 'http://localhost:8181/cxf/Customer'
23+
- you can verify this quickly by pointing your browser at 'http://localhost:8181/cxf/Customer?wsdl'.
24+
You can test the service by using a tool such as SoapUI from http://www.soapui.org.
25+
26+
Alternatively, you can install a bundle that creates a CXF client to this web
27+
service.
28+
29+
karaf@root> install -s mvn:com.fusesource.byexample.cxf-webinars/customer-ws-client
30+
31+
The bundle creates a thread that invokes on the web service once a second. It logs
32+
the response it gets; you can view the log using
33+
34+
karaf@root> log:display -n 10
35+
36+
37+
38+
Installing the camel-cxf routes
39+
-------------------------------
40+
To install the camel-cxf demos into JBoss Fuse, you need to install the relevant OSGi bundle.
41+
42+
For example, to install the camel-cxf POJO route, do
43+
44+
karaf@root> install -s mvn:com.fusesource.byexample.cxf-webinars/customer-ws-camel-cxf-pojo
45+
46+
To install the camel-cxf Payload route, do
47+
48+
karaf@root> install -s mvn:com.fusesource.byexample.cxf-webinars/customer-ws-camel-cxf-payload
49+
50+
Finally, to install the camel-cxf Provider route, do
51+
52+
karaf@root> install -s mvn:com.fusesource.byexample.cxf-webinars/customer-ws-camel-cxf-provider
53+
54+

customer-ws-camel-cxf-payload/pom.xml

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2011 FuseSource
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18+
<modelVersion>4.0.0</modelVersion>
19+
20+
<parent>
21+
<groupId>com.fusesource.byexample.cxf-webinars</groupId>
22+
<artifactId>cxf-webinars</artifactId>
23+
<version>1.0-SNAPSHOT</version>
24+
</parent>
25+
26+
<groupId>com.fusesource.byexample.cxf-webinars</groupId>
27+
<artifactId>customer-ws-camel-cxf-payload</artifactId>
28+
<name>customer-ws-camel-cxf-payload</name>
29+
<packaging>bundle</packaging>
30+
31+
<dependencies>
32+
<dependency>
33+
<groupId>org.slf4j</groupId>
34+
<artifactId>slf4j-api</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.apache.camel</groupId>
38+
<artifactId>camel-core</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.apache.camel</groupId>
42+
<artifactId>camel-cxf</artifactId>
43+
<version>${camel-version}</version>
44+
</dependency>
45+
</dependencies>
46+
47+
<build>
48+
<!-- Ensure that WSDL and XSD files are copied into the bundle. -->
49+
<resources>
50+
<resource>
51+
<directory>${basedir}/../src/main/resources</directory>
52+
<includes>
53+
<include>wsdl/*.wsdl</include>
54+
<include>xsd/*.xsd</include>
55+
</includes>
56+
</resource>
57+
<resource>
58+
<directory>${basedir}/src/main/resources</directory>
59+
</resource>
60+
</resources>
61+
62+
<plugins>
63+
<plugin>
64+
<groupId>org.apache.felix</groupId>
65+
<artifactId>maven-bundle-plugin</artifactId>
66+
<extensions>true</extensions>
67+
<configuration>
68+
<instructions>
69+
<Import-Package>
70+
org.apache.camel.component.velocity,
71+
META-INF.cxf,
72+
META-INF.cxf.osgi,
73+
javax.jws,
74+
javax.wsdl,
75+
javax.xml.bind,
76+
javax.xml.bind.annotation,
77+
javax.xml.namespace,
78+
javax.xml.ws,
79+
org.w3c.dom,
80+
<!-- Workaround to access DOM XPathFactory -->
81+
org.apache.xpath.jaxp,
82+
*
83+
</Import-Package>
84+
<DynamicImport-Package>
85+
org.apache.cxf.*,
86+
org.springframework.beans.*
87+
</DynamicImport-Package>
88+
</instructions>
89+
</configuration>
90+
</plugin>
91+
</plugins>
92+
</build>
93+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
/**
3+
* Copyright 2011 FuseSource
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.fusesource.customerwscamelcxfpayload;
19+
20+
import java.io.ByteArrayInputStream;
21+
import java.io.StringWriter;
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
import javax.xml.transform.OutputKeys;
25+
import javax.xml.transform.Transformer;
26+
import javax.xml.transform.TransformerFactory;
27+
import javax.xml.transform.dom.DOMSource;
28+
import javax.xml.transform.stream.StreamResult;
29+
import org.apache.camel.Converter;
30+
import org.apache.camel.component.cxf.CxfPayload;
31+
import org.apache.cxf.binding.soap.SoapHeader;
32+
import org.slf4j.Logger;
33+
import org.slf4j.LoggerFactory;
34+
import org.w3c.dom.Document;
35+
import org.w3c.dom.Element;
36+
import org.w3c.dom.Node;
37+
38+
@Converter
39+
public class AdditionalCxfPayloadConverters {
40+
41+
private static final Logger log = LoggerFactory.getLogger(AdditionalCxfPayloadConverters.class);
42+
private static javax.xml.parsers.DocumentBuilderFactory b = javax.xml.parsers.DocumentBuilderFactory.newInstance();
43+
44+
@Converter
45+
public static CxfPayload<SoapHeader> toCxfPayload(String xml) {
46+
// System.out.println("To CxfPayload " + xml);
47+
List<Element> elements = new ArrayList<Element>();
48+
try {
49+
Document doc = b.newDocumentBuilder().parse(new ByteArrayInputStream(xml.getBytes()));
50+
elements.add(doc.getDocumentElement());
51+
} catch (Exception ex) {
52+
log.warn("Exception while converting String payload to CxfPayload; resulting payload will be empty.");
53+
}
54+
// The CxfPayload is changed to use Source object under layer, the elements API only work if we already setup the list before creating the CxfPayload
55+
CxfPayload<SoapHeader> ret = new CxfPayload<SoapHeader>(null, elements);
56+
return ret;
57+
}
58+
59+
private static TransformerFactory transFactory = TransformerFactory.newInstance();
60+
61+
@Converter
62+
public static String toString(CxfPayload<SoapHeader> payload) {
63+
StringBuilder sb = new StringBuilder();
64+
65+
List<Element> elements = payload.getBody();
66+
for (Element e : elements) {
67+
try {
68+
Transformer transformer = transFactory.newTransformer();
69+
StringWriter buffer = new StringWriter();
70+
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
71+
transformer.transform(new DOMSource(e),
72+
new StreamResult(buffer));
73+
sb.append(buffer.toString());
74+
} catch (Exception ex) {
75+
log.warn("Warning: problems producing XML String content : " + ex.getMessage());
76+
}
77+
}
78+
79+
return sb.toString();
80+
}
81+
82+
@Converter
83+
public static Node toNode(CxfPayload<SoapHeader> payload) {
84+
return payload.getBody().get(0);
85+
}
86+
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
/**
3+
* Copyright 2011 FuseSource
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.fusesource.customerwscamelcxfpayload;
19+
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
import org.apache.camel.Exchange;
23+
import org.apache.camel.Processor;
24+
import org.apache.camel.component.cxf.CxfPayload;
25+
import org.apache.cxf.binding.soap.SoapHeader;
26+
import org.slf4j.Logger;
27+
import org.slf4j.LoggerFactory;
28+
import org.w3c.dom.Document;
29+
import org.w3c.dom.Element;
30+
31+
public class CxfPayloadProcessor implements Processor {
32+
private static final Logger log = LoggerFactory.getLogger(CxfPayloadProcessor.class);
33+
34+
public void process(Exchange exchng) throws Exception {
35+
Document xml = exchng.getIn().getBody(Document.class);
36+
List<Element> elements = new ArrayList<Element>();
37+
elements.add(xml.getDocumentElement());
38+
exchng.getOut().setBody(new CxfPayload<SoapHeader>(null, elements));
39+
}
40+
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
/**
3+
* Copyright 2011 FuseSource
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.fusesource.customerwscamelcxfpayload;
19+
20+
import org.apache.camel.Exchange;
21+
import org.apache.camel.Processor;
22+
23+
public class GetCustomerStatus implements Processor
24+
{
25+
public void process(Exchange exchng) throws Exception {
26+
String id = exchng.getIn().getHeader("customerId", String.class);
27+
28+
// Maybe do some kind of lookup here!
29+
//
30+
31+
exchng.getIn().setHeader("status", "Away");
32+
exchng.getIn().setHeader("statusMessage", "Going to sleep.");
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2011 FuseSource
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.fusesource.customerwscamelcxfpayload;
18+
19+
import org.apache.camel.Exchange;
20+
import org.apache.camel.Processor;
21+
22+
public class LookupCustomer implements Processor
23+
{
24+
public void process(Exchange exchng) throws Exception {
25+
String id = exchng.getIn().getHeader("customerId", String.class);
26+
27+
// Maybe do some kind of lookup here!
28+
//
29+
30+
exchng.getIn().setHeader("firstName", "Ade");
31+
exchng.getIn().setHeader("lastName", "Trenaman");
32+
exchng.getIn().setHeader("phoneNumber", "012343210");
33+
exchng.getIn().setHeader("id", id);
34+
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.fusesource.customerwscamelcxfpayload

0 commit comments

Comments
 (0)