Skip to content

Commit

Permalink
[resolves jboss-fuse#20] Separate locations for generated Camel and J…
Browse files Browse the repository at this point in the history
…ava files
  • Loading branch information
tdiesler committed Mar 21, 2018
1 parent 876ed2d commit 68b6f96
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
38 changes: 36 additions & 2 deletions impl/src/main/java/org/jboss/fuse/wsdl2rest/impl/Wsdl2Rest.java
Expand Up @@ -2,6 +2,8 @@

import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand All @@ -21,6 +23,7 @@ public class Wsdl2Rest {
private URL jaxrsAddress;
private URL jaxwsAddress;
private Path camelContext;
private Path javaOut;

public Wsdl2Rest(URL wsdlUrl, Path outpath) {
IllegalArgumentAssertion.assertNotNull(wsdlUrl, "wsdlUrl");
Expand All @@ -37,10 +40,20 @@ public void setJaxwsAddress(URL jaxwsAddress) {
this.jaxwsAddress = jaxwsAddress;
}

/**
* Defaults to [outpath]/camel/wsdl2rest-camel-context.xml
*/
public void setCamelContext(Path camelContext) {
this.camelContext = camelContext;
}

/**
* Defaults to [outpath]/java
*/
public void setJavaOut(Path javaOut) {
this.javaOut = javaOut;
}

public List<EndpointInfo> process() throws Exception {

WSDLProcessor wsdlProcessor = new WSDLProcessorImpl();
Expand All @@ -50,17 +63,38 @@ public List<EndpointInfo> process() throws Exception {
ResourceMapper resMapper = new ResourceMapperImpl();
resMapper.assignResources(clazzDefs);

JavaTypeGenerator typeGen = new JavaTypeGenerator(outpath, wsdlUrl);
JavaTypeGenerator typeGen = new JavaTypeGenerator(effectiveJavaOut(), wsdlUrl);
JavaModel javaModel = typeGen.execute();

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

return Collections.unmodifiableList(clazzDefs);
}

private Path effectiveJavaOut() {
Path resultPath = javaOut;
if (resultPath == null) {
resultPath = Paths.get("java");
}
return outpath.resolve(resultPath);
}

private Path effectiveCamelContext() {
Path resultPath = camelContext;
if (resultPath == null) {
resultPath = Paths.get("wsdl2rest-camel-context.xml");
}
List<Path> pathElements = new ArrayList<>();
resultPath.iterator().forEachRemaining(pathElements::add);
if (pathElements.size() < 2) {
resultPath = Paths.get("camel", resultPath.toString());
}
return outpath.resolve(resultPath);
}
}
Expand Up @@ -28,14 +28,11 @@

public class CamelContextGenerator {

private final Path outpath;

private Path camelContext;
private URL jaxrsAddress;
private URL jaxwsAddress;

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

public void setCamelContext(Path camelContext) {
Expand All @@ -53,9 +50,8 @@ public void setJaxwsAddress(URL 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(camelContext, "Camel context file name not set");
IllegalArgumentAssertion.assertTrue(clazzDefs.size() == 1, "Multiple endpoints not supported");

EndpointInfo epinfo = clazzDefs.get(0);

Expand All @@ -82,7 +78,9 @@ public void process(List<EndpointInfo> clazzDefs, JavaModel javaModel) throws IO

addTypeMapping(epinfo, javaModel);

File outfile = outpath.resolve(camelContext).toFile();
File outfile = camelContext.toFile();
outfile.getParentFile().mkdirs();

try (BufferedWriter writer = new BufferedWriter(new FileWriter(outfile))) {
ve.evaluate(context, writer, tmplPath, reader);
}
Expand Down
Expand Up @@ -87,7 +87,7 @@ public void testJavaClient() throws Exception {
@Test
public void testCamelClient() throws Exception {

URL resourceUrl = getClass().getResource("/doclit-camel-context.xml");
URL resourceUrl = getClass().getResource("/camel/doclit-camel-context.xml");
CamelContext camelctx = SpringCamelContextFactory.createSingleCamelContext(resourceUrl, null);
camelctx.start();
try {
Expand Down Expand Up @@ -116,7 +116,7 @@ public void testCamelClient() throws Exception {
@SuppressWarnings("unchecked")
public void testRestClient() throws Exception {

URL resourceUrl = getClass().getResource("/doclit-camel-context.xml");
URL resourceUrl = getClass().getResource("/camel/doclit-camel-context.xml");
CamelContext camelctx = SpringCamelContextFactory.createSingleCamelContext(resourceUrl, null);
camelctx.start();
try {
Expand Down
Expand Up @@ -90,7 +90,7 @@ public void testJavaClient() throws Exception {
@Test
public void testCamelClient() throws Exception {

URL resourceUrl = getClass().getResource("/rpclit-camel-context.xml");
URL resourceUrl = getClass().getResource("/camel/rpclit-camel-context.xml");
CamelContext camelctx = SpringCamelContextFactory.createSingleCamelContext(resourceUrl, null);
camelctx.start();
try {
Expand All @@ -116,7 +116,7 @@ public void testCamelClient() throws Exception {
@Test
public void testRestClient() throws Exception {

URL resourceUrl = getClass().getResource("/rpclit-camel-context.xml");
URL resourceUrl = getClass().getResource("/camel/rpclit-camel-context.xml");
CamelContext camelctx = SpringCamelContextFactory.createSingleCamelContext(resourceUrl, null);
camelctx.start();
try {
Expand Down
Expand Up @@ -153,7 +153,7 @@ private ProxyUtils() {
* @throws Exception
*/
public static void invokeProxied(final Callable<?> callable, final ClassLoader classLoader) throws Exception {
Callable<?> callableProxy = (Callable) Proxy.newProxyInstance(classLoader, new Class<?>[] { Callable.class }, new InvocationHandler() {
Callable<?> callableProxy = (Callable<?>) Proxy.newProxyInstance(classLoader, new Class<?>[] { Callable.class }, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
callable.call();
Expand Down

0 comments on commit 68b6f96

Please sign in to comment.