Skip to content

Commit

Permalink
[resolves jboss-fuse#41] Add target address options for both jaxws & …
Browse files Browse the repository at this point in the history
…jaxrs

[resolves jboss-fuse#40] Update README with new options
  • Loading branch information
tdiesler committed Mar 21, 2018
1 parent 86c7fd4 commit 876ed2d
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 45 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Generates REST endpoints from WSDL
----------------------------------

A tool chain allowing quick migration from existing
JAX-WS services to RESTful services by using existing WSDL.
A tool allowing quick migration from existing JAX-WS services to REST services.

Derived from https://sourceforge.net/projects/wsdl2rest

Expand All @@ -11,9 +10,9 @@ Usage

```
wsdl2rest [options...]
--out PATH : Output path for generated artefacts (required)
--target-address URL : Address for the generated camel endpoint
--target-bean VAL : Classname for the bean that camel delegates to
--target-context PATH : Path to the generated camel context
--wsdl URL : URL to the input WSDL (required)
--wsdl URL : URL to the input WSDL (required)
--out PATH : Output path for generated artefacts (required)
--camel-context PATH : Path to the generated camel context file name
--jaxrs URL : Address of the generated jaxrs endpoint
--jaxws URL : Address of the target jaxws endpoint
```
1 change: 1 addition & 0 deletions dist/scripts/assembly-directory.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">

<id>assemble-directory</id>
<formats>
<format>dir</format>
</formats>
Expand Down
1 change: 1 addition & 0 deletions dist/scripts/assembly-distro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">

<id>assemble-distro</id>
<formats>
<format>zip</format>
</formats>
Expand Down
4 changes: 2 additions & 2 deletions impl/src/main/java/org/jboss/fuse/wsdl2rest/impl/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public List<EndpointInfo> mainInternal(String[] args) throws Exception {

try {
Wsdl2Rest tool = new Wsdl2Rest(options.wsdlUrl, options.outpath);
tool.setTargetContext(options.targetContext);
tool.setTargetAddress(options.targetAddress);
tool.setCamelContext(options.camelContext);
tool.setJaxwsAddress(options.jaxwsAddress);
return tool.process();
} catch (Throwable th) {
LOG.error("Error executing command", th);
Expand Down
11 changes: 7 additions & 4 deletions impl/src/main/java/org/jboss/fuse/wsdl2rest/impl/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ final class Options {
@Option(name = "--out", required = true, usage = "Output path for generated artefacts (required)")
Path outpath;

@Option(name = "--target-context", usage = "Path to the generated camel context")
Path targetContext;
@Option(name = "--camel-context", usage = "Path to the generated camel context file name")
Path camelContext;

@Option(name = "--target-address", usage = "Address for the generated camel endpoint")
URL targetAddress;
@Option(name = "--jaxrs", usage = "Address of the generated jaxrs endpoint")
URL jaxrsAddress;

@Option(name = "--jaxws", usage = "Address of the target jaxws endpoint")
URL jaxwsAddress;
}
24 changes: 15 additions & 9 deletions impl/src/main/java/org/jboss/fuse/wsdl2rest/impl/Wsdl2Rest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public class Wsdl2Rest {
private final URL wsdlUrl;
private final Path outpath;

private URL targetAddress;
private Path targetContext;
private URL jaxrsAddress;
private URL jaxwsAddress;
private Path camelContext;

public Wsdl2Rest(URL wsdlUrl, Path outpath) {
IllegalArgumentAssertion.assertNotNull(wsdlUrl, "wsdlUrl");
Expand All @@ -28,12 +29,16 @@ public Wsdl2Rest(URL wsdlUrl, Path outpath) {
this.outpath = outpath;
}

public void setTargetAddress(URL targetAddress) {
this.targetAddress = targetAddress;
public void setJaxrsAddress(URL jaxrsAddress) {
this.jaxrsAddress = jaxrsAddress;
}

public void setTargetContext(Path targetContext) {
this.targetContext = targetContext;
public void setJaxwsAddress(URL jaxwsAddress) {
this.jaxwsAddress = jaxwsAddress;
}

public void setCamelContext(Path camelContext) {
this.camelContext = camelContext;
}

public List<EndpointInfo> process() throws Exception {
Expand All @@ -48,10 +53,11 @@ public List<EndpointInfo> process() throws Exception {
JavaTypeGenerator typeGen = new JavaTypeGenerator(outpath, wsdlUrl);
JavaModel javaModel = typeGen.execute();

if (targetContext != null) {
if (camelContext != null) {
CamelContextGenerator camelGen = new CamelContextGenerator(outpath);
camelGen.setTargetContext(targetContext);
camelGen.setTargetAddress(targetAddress);
camelGen.setCamelContext(camelContext);
camelGen.setJaxrsAddress(jaxrsAddress);
camelGen.setJaxwsAddress(jaxwsAddress);
camelGen.process(clazzDefs, javaModel);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,32 @@ public class CamelContextGenerator {

private final Path outpath;

private Path targetContext;
private URL targetAddress;
private Path camelContext;
private URL jaxrsAddress;
private URL jaxwsAddress;

public CamelContextGenerator(Path outpath) {
this.outpath = outpath;
}

public void setTargetContext(Path targetContext) {
this.targetContext = targetContext;
public void setCamelContext(Path camelContext) {
this.camelContext = camelContext;
}

public void setTargetAddress(URL targetAddress) {
this.targetAddress = targetAddress;
public void setJaxrsAddress(URL jaxrsAddress) {
this.jaxrsAddress = jaxrsAddress;
}

public void setJaxwsAddress(URL jaxwsAddress) {
this.jaxwsAddress = jaxwsAddress;
}

public void process(List<EndpointInfo> clazzDefs, JavaModel javaModel) throws IOException {
IllegalArgumentAssertion.assertNotNull(clazzDefs, "clazzDefs");
IllegalArgumentAssertion.assertNotNull(javaModel, "javaModel");
IllegalArgumentAssertion.assertTrue(clazzDefs.size() == 1, "Multiple endpoints not supported");

IllegalStateAssertion.assertNotNull(targetContext, "Camel context file name not set");
IllegalStateAssertion.assertNotNull(camelContext, "Camel context file name not set");

EndpointInfo epinfo = clazzDefs.get(0);

Expand All @@ -62,14 +67,22 @@ public void process(List<EndpointInfo> clazzDefs, JavaModel javaModel) throws IO
String tmplPath = "templates/jaxrs-camel-context.vm";
try (InputStreamReader reader = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(tmplPath))) {

jaxrsAddress = jaxrsAddress != null ? jaxrsAddress : new URL("http://localhost:8081/jaxrs");
String jaxrsHost = jaxrsAddress.getHost();
String jaxrsPort = "" + jaxrsAddress.getPort();
String jaxrsPath = jaxrsAddress.getPath();

VelocityContext context = new VelocityContext();
context.put("targetAddress", targetAddress != null ? targetAddress : "http://localhost:8080/somepath");
context.put("jaxwsAddress", jaxwsAddress != null ? jaxwsAddress : "http://localhost:8080/somepath");
context.put("jaxrsHost", jaxrsHost);
context.put("jaxrsPort", jaxrsPort);
context.put("jaxrsPath", jaxrsPath);
context.put("serviceClass", epinfo.getFQN());
context.put("allMethods", epinfo.getMethods());

addTypeMapping(epinfo, javaModel);

File outfile = outpath.resolve(targetContext).toFile();
File outfile = outpath.resolve(camelContext).toFile();
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outfile))) {
ve.evaluate(context, writer, tmplPath, reader);
}
Expand Down
6 changes: 3 additions & 3 deletions impl/src/main/resources/templates/jaxrs-camel-context.vm
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<xmljson id="xmljson"/>
</dataFormats>

<restConfiguration component="jetty" host="0.0.0.0" port="8081" bindingMode="json">
<restConfiguration component="jetty" host="$jaxrsHost" port="$jaxrsPort" bindingMode="json">
</restConfiguration>

<rest path="/jaxrs">
<rest path="/$jaxrsPath">
#foreach( $method in $allMethods )

<$method.httpMethod.toLowerCase() uri="/$method.path"
Expand Down Expand Up @@ -54,7 +54,7 @@
<simple>null</simple>
</setBody>
#end
<to uri="cxf://$targetAddress?serviceClass=$serviceClass&amp;defaultOperationName=$method.methodName"/>
<to uri="cxf://$jaxwsAddress?serviceClass=$serviceClass&amp;defaultOperationName=$method.methodName"/>
#set ( $returnType = $method.wrappedReturnType )
#if ( $returnType.startsWith('java.lang') && !$returnType.endsWith('[]'))
<setHeader headerName="Content-Type">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void testGenerate() throws Exception {
Path outpath = new File(OUTPUT_PATH).toPath();

Wsdl2Rest tool = new Wsdl2Rest(wsdlFile.toURI().toURL(), outpath);
tool.setTargetContext(Paths.get("doclit-camel-context.xml"));
tool.setTargetAddress(new URL("http://localhost:8080/doclit"));
tool.setCamelContext(Paths.get("doclit-camel-context.xml"));
tool.setJaxwsAddress(new URL("http://localhost:8080/doclit"));

List<EndpointInfo> clazzDefs = tool.process();
Assert.assertEquals(1, clazzDefs.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public void testGenerate() throws Exception {
Path outpath = new File(OUTPUT_PATH).toPath();

Wsdl2Rest tool = new Wsdl2Rest(wsdlFile.toURI().toURL(), outpath);
tool.setTargetContext(Paths.get("rpclit-camel-context.xml"));
tool.setTargetAddress(new URL("http://localhost:8080/rpclit"));
tool.setCamelContext(Paths.get("rpclit-camel-context.xml"));
tool.setJaxwsAddress(new URL("http://localhost:8080/rpclit"));

List<EndpointInfo> clazzDefs = tool.process();
Assert.assertEquals(1, clazzDefs.size());
Expand Down
5 changes: 2 additions & 3 deletions jaxws/src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
#

# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE
#log4j.rootCategory=INFO, CONSOLE, LOGFILE
log4j.rootCategory=INFO, CONSOLE, LOGFILE

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
log4j.appender.CONSOLE.Threshold=WARN

# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<!-- Plugin versions -->
<version-build-helper-plugin>3.0.0</version-build-helper-plugin>
<version-maven-antrun-plugin>1.8</version-maven-antrun-plugin>
<version-maven-assembly-plugin>3.1.0</version-maven-assembly-plugin>
<version-maven-compiler-plugin>3.7.0</version-maven-compiler-plugin>
<version-maven-jar-plugin>2.6</version-maven-jar-plugin>
<version-maven-javadoc-plugin>2.9.1</version-maven-javadoc-plugin>
Expand Down Expand Up @@ -150,6 +151,11 @@
<artifactId>maven-antrun-plugin</artifactId>
<version>${version-maven-antrun-plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${version-maven-assembly-plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
10 changes: 6 additions & 4 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@
<target>
<java classname="org.jboss.fuse.wsdl2rest.impl.Main" classpathref="maven.test.classpath" failonerror="true">
<arg value="--wsdl=file:${basedir}/../jaxws/src/main/resources/doclit/Address.wsdl" />
<arg value="--target-address=http://localhost:8080/doclit/AddressService" />
<arg value="--target-context=doclit-camel-context.xml" />
<arg value="--jaxrs=http://localhost:8081/jaxrs" />
<arg value="--jaxws=http://localhost:8080/doclit/AddressService" />
<arg value="--camel-context=doclit-camel-context.xml" />
<arg value="--out=${basedir}/target/generated-wsdl2rest" />
</java>
</target>
Expand All @@ -98,8 +99,9 @@
<target>
<java classname="org.jboss.fuse.wsdl2rest.impl.Main" classpathref="maven.test.classpath" failonerror="true">
<arg value="--wsdl=file:${basedir}/../jaxws/src/main/resources/rpclit/Address.wsdl" />
<arg value="--target-address=http://localhost:8080/rpclit/AddressService" />
<arg value="--target-context=rpclit-camel-context.xml" />
<arg value="--jaxrs=http://localhost:8081/jaxrs" />
<arg value="--jaxws=http://localhost:8080/rpclit/AddressService" />
<arg value="--camel-context=rpclit-camel-context.xml" />
<arg value="--out=${basedir}/target/generated-wsdl2rest" />
</java>
</target>
Expand Down

0 comments on commit 876ed2d

Please sign in to comment.