Skip to content

Commit a33432d

Browse files
committed
adding wsdl2rest support to camel-project generator camel-tooling#11
-- initial cut with fat jar and running the wsdl2rest tool with inputs -- updating to support full paths and a logging.props file -- Updating version for when we include wsdl2rest functionality -- also updating the travis file to build the wsdl2rest jar -- additional work on test and wsdl2rest call -- additional fixes -- Setting jar to specific version vs asterisk and returning to broken test -- updates to make wsdl2rest run in a promise camel-tooling#11 -- Increasing the mocha timeout in the travis configuration camel-tooling#11 -- addressing some review feedback -- updating tests to run with npm test call -- reset readme.md -- updating console messages to better reflect what's happening to user -- adding --debug flag for wsdl2rest -- fixing log4j issue -- adding appropriate dependencies to pom for wsdl2rest projects -- fixing issue when using URL to non-local WSDL -- adding test for non-local WSDL -- adding validation to avoid java and wsdl2rest combo -- adding function to avoid hardcoding wsdl2rest fat jar version -- addressing more feedback -- fixing test for jar finding function -- increased mocha test timeout to 15000 -- added new test that starts a sample JAX-WS web service and uses the WSDL it serves up to create a project -- updated helloworld wsdl and sample WS -- added jaxws and jaxrs URL property prompts -- fixed helloworld wsdl to generate properly -- added new command line arguments and first test -- removed some extraneous console messages and debug settings -- improved wsdl2rest command line tests -- adjusted to ensure that all wsdl2rest command line args are present -- fixed issue with java dsl option -- addressed more minor feedback -- added test-in-progress to run generated service and do a get request against it -- more test tweaks -- attempting child_process -- fixing issue camel-tooling#34 (missing camel-maven-plugin version for spring projects) -- fixing error with test soap utility -- adding test for camel dsl validation -- split up tests Signed-off-by: Brian Fitzpatrick <[email protected]>
1 parent 40eda99 commit a33432d

20 files changed

+2487
-119
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
/node_modules/
22
/coverage/
33
/.nyc_output/
4+
/bin/
5+
/app/wsdl2rest/target/
46
log-camel-lsp.out
7+
.classpath
8+
.project
9+
/.settings/
10+
app/wsdl2rest/.classpath
11+
app/wsdl2rest/.project
12+
/app/wsdl2rest/.settings/
13+
.DS_Store

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ before_install:
66
- 'export PATH=./node_modules/.bin:$PATH'
77
- 'npm install -g typescript'
88
- 'npm install -g mocha'
9+
- 'mvn install -f ./app/wsdl2rest/pom.xml'
910
install:
1011
- 'npm install --ignore-scripts'
1112
- 'npm install'
1213
# https://github.com/travis-ci/travis-ci/issues/8813
1314
- 'rm -f ./node_modules/.bin/which'
1415
script:
1516
- 'npm test --silent'
16-
- 'mocha'
1717
after_success:
1818
- if [[ $TRAVIS_PULL_REQUEST == "false" && $TRAVIS_BRANCH == "master" ]]; then
1919
sonar-scanner;

app/index.js

+225-10
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@ var yeoman = require('yeoman-generator');
1919
var glob = require('glob');
2020
var path = require('path');
2121
var mkdirp = require('mkdirp');
22+
var fileUrl = require('file-url');
23+
var exec = require('child_process').exec;
24+
var fs = require('fs');
25+
26+
const chalk = require('chalk');
2227
const utils = require('./util');
2328

24-
const defaultCamelVersion = "2.22.1";
29+
const defaultCamelVersion = "2.22.2";
2530
const defaultCamelDSL = "spring";
2631
const defaultPackagePrefix = "com.";
32+
const defaultOutputDirectory = 'src/main/java';
33+
const defaultJaxRsUrl = "http://localhost:8081/jaxrs";
34+
const defaultJaxWsUrl = "http://localhost:8080/somepath";
2735

2836
function consoleHeader() {
2937
var pjson = require('../package.json');
@@ -51,10 +59,21 @@ module.exports = class extends yeoman {
5159
constructor(args, opts) {
5260
super(args, opts);
5361

62+
// base arguments
5463
this.argument('appname', { type: String, required: false });
5564
this.argument('camelVersion', { type: String, required: false });
5665
this.argument('camelDSL', { type: String, required: false });
5766
this.argument('package', { type: String, required: false });
67+
68+
// wsdl2rest options
69+
this.option('wsdl2rest');
70+
this.option('debug');
71+
72+
// wsdl2rest arguments
73+
this.argument('wsdl', { type: String, required: false });
74+
this.argument('outdirectory', { type: String, required: false });
75+
this.argument('jaxrs', { type: String, required: false });
76+
this.argument('jaxws', { type: String, required: false });
5877
}
5978

6079
prompting() {
@@ -69,7 +88,18 @@ module.exports = class extends yeoman {
6988
showPrompts = false;
7089
}
7190

72-
if (showPrompts) {
91+
let showWsdl2Rest = this.options.wsdl2rest;
92+
if (typeof showWsdl2Rest == 'undefined') showWsdl2Rest = false;
93+
94+
var showW2RPrompts = true;
95+
if (!showPrompts && showWsdl2Rest) {
96+
showW2RPrompts = (utils.isNull(this.options.wsdl)) &&
97+
(utils.isNull(this.options.outdirectory)) &&
98+
(utils.isNull(this.options.jaxrs)) &&
99+
(utils.isNull(this.options.jaxws));
100+
}
101+
102+
if (showPrompts || showW2RPrompts) {
73103
consoleHeader();
74104
}
75105

@@ -98,7 +128,9 @@ module.exports = class extends yeoman {
98128
message: 'Camel DSL type (blueprint, spring, or java)',
99129
choices: ['blueprint', 'spring', 'java'],
100130
default: defaultDSL,
101-
validate: utils.validateCamelDSL,
131+
validate: (value) => {
132+
return utils.validateCamelDSL(value, showWsdl2Rest);
133+
},
102134
store: true
103135
}, prompts);
104136
utils.addPrompt({
@@ -109,23 +141,73 @@ module.exports = class extends yeoman {
109141
validate : utils.validatePackage
110142
}, prompts);
111143

112-
if (showPrompts) {
144+
var defaultOutputDir = utils.setDefault(defaultOutputDirectory, this.options.outdirectory);
145+
var defaultJaxRS = utils.setDefault(defaultJaxRsUrl, this.options.jaxrs);
146+
var defaultJaxWS = utils.setDefault(defaultJaxWsUrl, this.options.jaxws);
147+
var defaultWsdl = utils.setDefault('no wsdl specified', this.options.wsdl);
148+
149+
if (showWsdl2Rest) {
150+
utils.addPrompt({
151+
type: 'input',
152+
name: 'wsdl',
153+
message: 'URL to the input WSDL',
154+
store: true
155+
}, prompts);
156+
utils.addPrompt({
157+
type: 'input',
158+
name: 'outdirectory',
159+
message: 'Name of the output directory for generated artifacts',
160+
default: defaultOutputDir,
161+
store: true
162+
}, prompts);
163+
utils.addPrompt({
164+
type: 'input',
165+
name: 'jaxrsURL',
166+
message: 'Address of the generated jaxrs endpoint',
167+
default: defaultJaxRS,
168+
store: true
169+
}, prompts);
170+
utils.addPrompt({
171+
type: 'input',
172+
name: 'jaxwsURL',
173+
message: 'Address of the target jaxws endpoint',
174+
default: defaultJaxWS,
175+
store: true
176+
}, prompts);
177+
}
178+
179+
if (showPrompts || showW2RPrompts) {
113180
return this.prompt(prompts).then(function (props) {
114181
this.appname = props.name;
115182
this.camelVersion = props.camelVersion;
116183
this.camelDSL = props.camelDSL;
117184
this.package = props.package;
185+
if (showWsdl2Rest) {
186+
this.outdirectory = props.outdirectory;
187+
this.wsdl = props.wsdl;
188+
this.jaxwsURL = props.jaxwsURL;
189+
this.jaxrsURL = props.jaxrsURL;
190+
}
118191
}.bind(this));
119192
} else {
120193
this.appname = defaultProject;
121194
this.camelVersion = defaultVersion;
122195
this.camelDSL = defaultDSL;
123196
this.package = defaultPackage;
124-
}
197+
if (showWsdl2Rest) {
198+
this.outdirectory = defaultOutputDir;
199+
this.wsdl = defaultWsdl;
200+
this.jaxwsURL = defaultJaxWS;
201+
this.jaxrsURL = defaultJaxRS;
202+
}
203+
}
125204
};
126205

127206
//writing logic here
128207
writing() {
208+
let showWsdl2Rest = this.options.wsdl2rest;
209+
let showDebug = this.options.debug;
210+
129211
var packageFolder = this.package.replace(/\./g, '/');
130212
var src = 'src/main/java';
131213
var myTemplatePath = path.join(this.templatePath(), this.camelDSL);
@@ -147,11 +229,144 @@ module.exports = class extends yeoman {
147229
userProps.package = this.package;
148230

149231
for (var i = 0; i < this.files.length; i++) {
150-
this.fs.copyTpl(
151-
this.templatePath(this.files[i]),
152-
this.destinationPath(this.files[i].replace(/src\/main\/java/g, path.join(src, packageFolder))),
153-
{ userProps: userProps }
154-
);
232+
var skipFile = false;
233+
if (showWsdl2Rest) {
234+
skipFile = testFileForWsdl2RestSkip(this.files[i]);
235+
} else {
236+
skipFile = testFileForTemplateSkip(this.files[i]);
237+
}
238+
239+
if (!skipFile) {
240+
if(this.files[i].localeCompare('pom.xml.wsdl2rest') == 0) {
241+
var tempOutFile = "pom.xml";
242+
this.fs.copyTpl(
243+
this.templatePath(this.files[i]),
244+
this.destinationPath(tempOutFile.replace(/src\/main\/java/g, path.join(src, packageFolder))),
245+
{ userProps: userProps }
246+
);
247+
} else {
248+
this.fs.copyTpl(
249+
this.templatePath(this.files[i]),
250+
this.destinationPath(this.files[i].replace(/src\/main\/java/g, path.join(src, packageFolder))),
251+
{ userProps: userProps }
252+
);
253+
}
254+
}
255+
}
256+
257+
if (showWsdl2Rest) {
258+
return wsdl2restGenerate(this.wsdl, this.outdirectory, this.jaxrsURL, this.jaxwsURL, this.camelDSL, showDebug);
155259
}
156260
}
157261
};
262+
263+
var skipListForWsdl2RestFiles = [
264+
'src/main/resources/META-INF/spring/camel-context.xml',
265+
'src/main/resources/OSGI-INF/blueprint/blueprint.xml',
266+
'pom.xml'
267+
];
268+
269+
function testFileForWsdl2RestSkip(file) {
270+
for(var i=0; i<skipListForWsdl2RestFiles.length; i++) {
271+
if (skipListForWsdl2RestFiles[i] == file) return true;
272+
}
273+
}
274+
275+
var skipListForTemplateFiles = [
276+
'pom.xml.wsdl2rest'
277+
];
278+
279+
function testFileForTemplateSkip(file) {
280+
for(var i=0; i<skipListForTemplateFiles.length; i++) {
281+
if (skipListForTemplateFiles[i] == file) return true;
282+
}
283+
}
284+
285+
function wsdl2restGenerate(wsdlUrl, outputDirectory, jaxrs, jaxws, dsl, isDebug) {
286+
if (dsl.includes('java')) {
287+
console.log(`Generating Rest DSL from SOAP for a Camel Java DSL is currently unsupported.`);
288+
return;
289+
}
290+
291+
var wsdl2restdir = path.join(__dirname, 'wsdl2rest');
292+
var targetDir = path.join(wsdl2restdir, 'target');
293+
var jar = utils.findWsdl2RestJar(targetDir);
294+
295+
var logPath = path.join(wsdl2restdir, 'config', 'logging.properties');
296+
var logUrl = fileUrl(logPath);
297+
298+
var actualJavaOutDirectory = outputDirectory;
299+
if (actualJavaOutDirectory.endsWith('/java')) {
300+
actualJavaOutDirectory = actualJavaOutDirectory.substring(0, actualJavaOutDirectory.indexOf("/java"));
301+
}
302+
var outPath = path.join(process.cwd(), actualJavaOutDirectory);
303+
var wsdlFileUrl;
304+
if (wsdlUrl.startsWith('http')) {
305+
wsdlFileUrl = wsdlUrl;
306+
} else if (!wsdlUrl.startsWith('file:')) {
307+
wsdlFileUrl = fileUrl(wsdlUrl);
308+
} else {
309+
wsdlFileUrl = wsdlUrl;
310+
}
311+
312+
if (!fs.existsSync(outPath)){
313+
console.log(`Creating wsdl2rest java output directory`);
314+
fs.mkdirSync(outPath);
315+
}
316+
317+
var restContextPath;
318+
var rawContextPath;
319+
var isBlueprint = dsl.includes('blueprint') > 0;
320+
if (isBlueprint) {
321+
rawContextPath = "src/main/resources/OSGI-INF/blueprint/blueprint.xml";
322+
} else {
323+
rawContextPath = "src/main/resources/META-INF/spring/camel-context.xml";
324+
}
325+
restContextPath = path.join(process.cwd(), rawContextPath);
326+
327+
// build the java command with classpath, class name, and the passed parameters
328+
var cmdString = 'java '
329+
+ ' -Dlog4j.configuration=' + logUrl
330+
+ ' -jar ' + jar
331+
+ ' --wsdl ' + wsdlFileUrl
332+
+ ' --out ' + outPath;
333+
334+
if (isBlueprint) {
335+
cmdString = cmdString + ' --blueprint-context ' + restContextPath;
336+
} else {
337+
cmdString = cmdString + ' --camel-context ' + restContextPath;
338+
}
339+
340+
if (jaxrs) {
341+
cmdString = cmdString + ' --jaxrs ' + jaxrs;
342+
}
343+
if (jaxws) {
344+
cmdString = cmdString + ' --jaxws ' + jaxws;
345+
}
346+
console.log('Calling wsdl2rest');
347+
if (isDebug) {
348+
console.log(' command used: ' + cmdString);
349+
}
350+
return new Promise((resolve, reject) => {
351+
const wsdl2rest = exec(cmdString);
352+
if (isDebug) {
353+
wsdl2rest.stdout.on('data', function (data) {
354+
console.log(`stdout: ${data}`);
355+
});
356+
wsdl2rest.stderr.on('data', function (data) {
357+
console.log(`stderr: ${data}`);
358+
});
359+
}
360+
wsdl2rest.on('close', function (code) {
361+
if (code === 0) {
362+
console.log(' ' + chalk.green('create') + ' CXF artifacts for specified WSDL at ' + outputDirectory);
363+
console.log(' ' + chalk.green('create') + ' ' + rawContextPath);
364+
resolve()
365+
} else {
366+
reject()
367+
console.log(` stderr: ${code}`);
368+
console.log(` wsdl2rest did not generate artifacts successfully - please check the log file for details or re-run with --debug flag`);
369+
}
370+
});
371+
})
372+
}

0 commit comments

Comments
 (0)