8000 #4 · soujava/soujava-test-kit@ef035c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit ef035c9

Browse files
1 parent 4b1dba2 commit ef035c9

17 files changed

+866
-0
lines changed

webservice/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/

webservice/pom.xml

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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/maven-v4_0_0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>br.org.soujava</groupId>
7+
<artifactId>webservice</artifactId>
8+
<packaging>bundle</packaging>
9+
<version>1.0</version>
10+
11+
<properties>
12+
<camel.version>2.12.0.redhat-611412</camel.version>
13+
<cxf.version>2.7.0.redhat-610379</cxf.version>
14+
<activemq.version>5.9.0.redhat-610379</activemq.version>
15+
<testng.version>6.8.5</testng.version>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.apache.camel</groupId>
21+
<artifactId>camel-netty</artifactId>
22+
<version>${camel.version}</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.apache.camel</groupId>
26+
<artifactId>camel-core</artifactId>
27+
<version>${camel.version}</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.apache.camel</groupId>
31+
<artifactId>camel-cxf</artifactId>
32+
<version>${camel.version}</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.apache.cxf</groupId>
36+
<artifactId>cxf-rt-frontend-jaxws</artifactId>
37+
<version>${cxf.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.apache.cxf</groupId>
41+
<artifactId>cxf-rt-transports-http</artifactId>
42+
<version>${cxf.version}</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.apache.cxf</groupId>
46+
<artifactId>cxf-rt-transports-http-jetty</artifactId>
47+
<version>${cxf.version}</version>
48+
49+
</dependency>
50+
<!-- logging -->
51+
<dependency>
52+
<groupId>org.slf4j</groupId>
53+
<artifactId>slf4j-log4j12</artifactId>
54+
<version>1.7.12</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>log4j</groupId>
58+
<artifactId>log4j</artifactId>
59+
<version>1.2.17</version>
60+
</dependency>
61+
<!-- test -->
62+
<dependency>
63+
<groupId>org.apache.camel</groupId>
64+
<artifactId>camel-test-spring</artifactId>
65+
<version>${camel.version}</version>
66+
<scope>test</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.apache.camel</groupId>
70+
<artifactId>camel-jaxb</artifactId>
71+
<version>${camel.version}</version>
72+
<scope>test</scope>
73+
</dependency>
74+
</dependencies>
75+
76+
<build>
77+
<plugins>
78+
79+
<!-- Allows the routes to be run via 'mvn camel:run' -->
80+
<plugin>
81+
<groupId>org.apache.camel</groupId>
82+
<artifactId>camel-maven-plugin</artifactId>
83+
<version>${camel.version}</version>
84+
</plugin>
85+
86+
<plugin>
87+
<groupId>org.codehaus.mojo</groupId>
88+
<artifactId>build-helper-maven-plugin</artifactId>
89+
<executions>
90+
<execution>
91+
<id>attach-features-xml</id>
92+
<phase>package</phase>
93+
<goals>
94+
<goal>attach-artifact</goal>
95+
</goals>
96+
<configuration>
97+
<artifacts>
98+
<artifact>
99+
<file>${basedir}/target/classes/features.xml</file>
100+
<type>xml</type>
101+
<classifier>features</classifier>
102+
</artifact>
103+
</artifacts>
104+
</configuration>
105+
</execution>
106+
</executions>
107+
</plugin>
108+
109+
<!-- CXF wsdl2java generator, will plugin to the compile goal -->
110+
<plugin>
111+
<groupId>org.apache.cxf</groupId>
112+
<artifactId>cxf-codegen-plugin</artifactId>
113+
<version>3.1.2</version>
114+
<executions>
115+
<execution>
116+
<id>generate-sources</id>
117+
<phase>generate-sources</phase>
118+
<configuration>
119+
<sourceRoot>${basedir}/src/main/java</sourceRoot>
120+
<wsdlOptions>
121+
<wsdlOption>
122+
<wsdl>${basedir}/src/main/resources/META-INF/wsdl/report_incident.wsdl</wsdl>
123+
</wsdlOption>
124+
</wsdlOptions>
125+
</configuration>
126+
<goals>
127+
<goal>wsdl2java</goal>
128+
</goals>
129+
</execution>
130+
</executions>
131+
</plugin>
132+
133+
<!-- build the OSGi bundle -->
134+
<!-- to generate the MANIFEST-FILE of the bundle -->
135+
<plugin>
136+
<groupId>org.apache.felix</groupId>
137+
<artifactId>maven-bundle-plugin</artifactId>
138+
<version>2.3.7</version>
139+
<extensions>true</extensions>
140+
<configuration>
141+
<manifestLocation>target/META-INF</manifestLocation>
142+
<instructions>
143+
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
144+
<Export-Package>br.org.soujava</Export-Package>
145+
<Import-Package>
146+
org.apache.cxf,
147+
org.apache.cxf.binding,
148+
org.apache.cxf.binding.corba,
149+
org.apache.cxf.binding.soap,
150+
org.apache.cxf.binding.soap.spring,
151+
org.apache.cxf.bus,
152+
org.apache.cxf.bus.resource,
153+
org.apache.cxf.bus.spring,
154+
org.apache.cxf.buslifecycle,
155+
org.apache.cxf.catalog,
156+
org.apache.cxf.configuration,
157+
org.apache.cxf.configuration.spring,
158+
org.apache.cxf.endpoint,
159+
org.apache.cxf.headers,
160+
org.apache.cxf.management,
161+
org.apache.cxf.management.jmx,
162+
org.apache.cxf.phase,
163+
org.apache.cxf.resource,
164+
org.apache.cxf.service.factory,
165+
org.apache.cxf.transport,
166+
org.apache.cxf.transport.http,
167+
org.apache.cxf.transport.http.policy,
168+
org.apache.cxf.transport.http_jetty,
169+
org.apache.cxf.transport.jms,
170+
org.apache.cxf.workqueue,
171+
org.apache.cxf.wsdl,
172+
org.apache.cxf.wsdl11,
173+
*
174+
</Import-Package>
175+
</instructions>
176+
</configuration>
177+
</plugin>
178+
</plugins>
179+
</build>
180+
</project>

webservice/readme.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Camel - CXF - Netty - Basic Webservice
2+
3+
4+
This module was created to be used as part of the Scala Gatling Bootstrap project.
5+
6+
This includes 1 test case that are evidencing the webservice starts up and stop, correctly binding to a port and accepting post messages.
7+
The message will be send to a netty processor that will execute the transformation. The transformation will just get the message and respond with a ok.
8+
9+
# Building
10+
=========================
11+
12+
To build this project use
13+
14+
```mvn clean install```
15+
16+
# Running
17+
===========
18+
19+
To run this project from within Maven use
20+
21+
```mvn camel:run```
22+
23+
24+
# Testing
25+
============
26+
27+
To execute tests
28+
29+
```mvn test```
30+
31+
# Running with OSGi JBOSS Fuse
32+
================================
33+
34+
To run this project with FUSE or any other OSGi Karaf container, after starting the container `./fuse`
35+
36+
(make sure you did clean install before running this)
37+
38+
Add the features url:
39+
```
40+
features:addurl mvn:br.org.soujava/webservice/1.0/xml/features
41+
```
42+
43+
Then install it:
44+
```
45+
features:install webservice
46+
```
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package br.org.soujava;
2+
3+
4+
import br.org.soujava.schema.webservice.wsdl._1.CompletionStatusCode;
5+
import br.org.soujava.schema.webservice.wsdl._1.WebServiceInvocationResult;
6+
import org.apache.camel.Exchange;
7+
import org.apache.camel.Processor;
8+
import org.apache.camel.builder.RouteBuilder;
9+
import org.apache.camel.component.cxf.CxfPayload;
10+
import org.apache.cxf.binding.soap.SoapHeader;
11+
import org.w3c.dom.Document;
12+
import org.w3c.dom.Element;
13+
14+
import javax.xml.bind.JAXBContext;
15+
import javax.xml.bind.JAXBException;
16+
import javax.xml.bind.Marshaller;
17+
import javax.xml.parsers.DocumentBuilder;
18+
import javax.xml.parsers.DocumentBuilderFactory;
19+
import javax.xml.parsers.ParserConfigurationException;
20+
import java.util.ArrayList;
21+
import java.util.List;
22+
23+
/**
24+
* Basic routes
25+
*/
26+
public class ReportIncidentRoutes extends RouteBuilder {
27+
28+
private JAXBContext jaxbContext;
29+
30+
protected CxfPayload<SoapHeader> initResult(WebServiceInvocationResult invocationResult) throws JAXBException, ParserConfigurationException {
31+
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
32+
dbf.setNamespaceAware(true);
33+
DocumentBuilder db = dbf.newDocumentBuilder();
34+
Document doc = db.newDocument();
35+
Marshaller marshaller = jaxbContext.createMarshaller();
36+
marshaller.marshal(invocationResult, doc);
37+
List<Element> outElements = new ArrayList<Element>();
38+
outElements.add(doc.getDocumentElement());
39+
CxfPayload<SoapHeader> responsePayload = new CxfPayload<SoapHeader>(null, outElements);
40+
// LOG.info("Done creating CXF payload result...");
41+
return responsePayload;
42+
}
43+
44+
@Override
45+
public void configure() throws Exception {
46+
47+
// Input route using CXF
48+
from("cxf:bean:esbWebServiceEndpoint")
49+
.to("direct:cxf-codec");
50+
51+
from("direct:cxf-codec")
52+
.convertBodyTo(String.class).process(new Processor() {
53+
public void process(Exchange exchange) throws Exception {
54+
jaxbContext = JAXBContext.newInstance(WebServiceInvocationResult.class, CompletionStatusCode.class);
55+
// System.out.println(exchange.getIn().getBody(String.class));
56+
}
57+
}).to("direct:netty-codec");
58+
59+
from("direct:netty-codec").to("netty:tcp://localhost:9999").to("mock:result");
60+
61+
from("netty:tcp://localhost:9999").process(new Processor() {
62+
public void process(Exchange exchange) throws Exception {
63+
System.out.println("Got to the processor, will send a response back");
64+
String str = exchange.getIn().getBody(String.class);
65+
// exchange.getOut().setBody(initResult(result));
66+
exchange.getOut().setBody("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><WebServiceInvocationResult xmlns=\"http://schema.soujava.org.br/webservice/wsdl/1.1\"><code>OK</code><message>cxvxcv</message></WebServiceInvocationResult></soap:Body></soap:Envelope>\n");
67+
}
68+
});
69+
}
70+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
package br.org.soujava.schema.webservice.wsdl._1;
3+
4+
import javax.xml.bind.annotation.XmlEnum;
5+
import javax.xml.bind.annotation.XmlType;
6+
7+
8+
/**
9+
* <p>Java class for CompletionStatusCode.
10+
*
11+
* <p>The following schema fragment specifies the expected content contained within this class.
12+
* <p>
13+
* <pre>
14+
* &lt;simpleType name="CompletionStatusCode"&gt;
15+
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string"&gt;
16+
* &lt;enumeration value="OK"/&gt;
17+
* &lt;enumeration value="ERROR"/&gt;
18+
* &lt;/restriction&gt;
19+
* &lt;/simpleType&gt;
20+
* </pre>
21+
*
22+
*/
23+
@XmlType(name = "CompletionStatusCode")
24+
@XmlEnum
25+
public enum CompletionStatusCode {
26+
27+
OK,
28+
ERROR;
29+
30+
public String value() {
31+
return name();
32+
}
33+
34+
public static CompletionStatusCode fromValue(String v) {
35+
return valueOf(v);
36+
}
37+
38+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
package br.org.soujava.schema.webservice.wsdl._1;
3+
4+
import javax.xml.bind.JAXBElement;
5+
import javax.xml.bind.annotation.XmlElementDecl;
6+
import javax.xml.bind.annotation.XmlRegistry;
7+
import javax.xml.namespace.QName;
8+
9+
10+
/**
11+
* This object contains factory methods for each
12+
* Java content interface and Java element interface
13+
* generated in the br.org.soujava.schema.webservice.wsdl._1 package.
14+
* <p>An ObjectFactory allows you to programatically
15+
* construct new instances of the Java representation
16+
* for XML content. The Java representation of XML
17+
* content can consist of schema derived interfaces
18+
* and classes representing the binding of schema
19+
* type definitions, element declarations and model
20+
* groups. Factory methods for each of these are
21+
* provided in this class.
22+
*
23+
*/
24+
@XmlRegistry
25+
public class ObjectFactory {
26+
27+
private final static QName _Xml_QNAME = new QName("http://schema.soujava.org.br/webservice/wsdl/1.1", "xml");
28+
29+
/**
30+
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: br.org.soujava.schema.webservice.wsdl._1
31+
*
32+
*/
33+
public ObjectFactory() {
34+
}
35+
36+
/**
37+
* Create an instance of {@link WebServiceInvocationResult }
38+
*
39+
*/
40+
public WebServiceInvocationResult createWebServiceInvocationResult() {
41+
return new WebServiceInvocationResult();
42+
}
43+
44+
/**
45+
* Create an instance of {@link JAXBElement }{@code <}{@link String }{@code >}}
46+
*
47+
*/
48+
@XmlElementDecl(namespace = "http://schema.soujava.org.br/webservice/wsdl/1.1", name = "xml")
49+
public JAXBElement<String> createXml(String value) {
50+
return new JAXBElement<String>(_Xml_QNAME, String.class, null, value);
51+
}
52+
53+
}

0 commit comments

Comments
 (0)
0