Skip to content

Commit 76e3c21

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 Signed-off-by: Brian Fitzpatrick <[email protected]>
1 parent a636b6b commit 76e3c21

18 files changed

+2173
-122
lines changed

Diff for: .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

Diff for: .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;

Diff for: README.md

+17-12
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,31 @@ The generator is located in the npm repository (https://www.npmjs.com/package/ge
7777
\____| \__,_| |_| |_| |_| \___| |_|
7878
-----------------------------------------------
7979
Camel Project Generator
80+
Version: 0.1.2
8081
-----------------------------------------------
8182
8283
? Your Camel project name (myproject)
83-
? Your Camel version 2.18.1
84-
? DSL type (blueprint or spring) blueprint
84+
? Your Camel version 2.18.2
85+
? Camel DSL type (blueprint, spring, or java) blueprint
8586
? Package name: com.myproject
8687
camel project name myproject
87-
camel version 2.18.1
88+
camel version 2.18.2
8889
camel DSL blueprint
8990
package name com.myproject
9091
Creating folders
9192
Copying files
92-
Copying dot files
9393
create pom.xml
9494
create README.md
9595
create src\main\resources\OSGI-INF\blueprint\blueprint.xml
96+
create src\main\resources\OSGI-INF\log4j2.properties
9697
>
9798
```
9899

99100
### Notes on input fields
100101

101102
* 'Camel project name' defaults to the name of the directory in which you start the generator.
102-
* 'Camel version' defaults to 2.18.1 but if you provide a different version, that version then becomes the default for the next time the generator is run.
103-
* 'DSL type' defaults to 'spring' but if you change it to a valid DSL type such as 'blueprint', 'spring', or 'java', that becomes the default for the next time the generator is run. If you enter an invalid value, the generator will present an error ">> Camel DSL must be either 'spring', 'blueprint', or 'java'.".
103+
* 'Camel version' defaults to 2.22.1 but if you provide a different version, that version then becomes the default for the next time the generator is run.
104+
* 'Camel DSL type' defaults to 'spring' but if you change it to a valid DSL type such as 'blueprint', 'spring', or 'java', that becomes the default for the next time the generator is run. If you enter an invalid value, the generator will present an error ">> Camel DSL must be either 'spring', 'blueprint', or 'java'.".
104105
* 'Package name' defaults to 'com.' + the name of the directory (i.e. 'com.myproject'). This default does not change if you provide a different value.
105106

106107
## Development Notes
@@ -122,6 +123,14 @@ Then create a directory you wish to create a Camel project in and run the genera
122123
> yo camel-project
123124
```
124125

126+
## Running the Generator from the Command Line (*NEW*)
127+
With version 0.1.2 we have added command-line capabilities for providing argument values for the prompted information. Without prompting, this allows us to use the generator as part of a larger script to help prep a new project in a more automated fashion.
128+
129+
This allows us to do things like the following and avoid having to go through the prompts:
130+
```
131+
> yo camel-project appname=MyApp camelVersion=2.19.1 camelDSL=spring package=com.myapp
132+
```
133+
125134
### Running the Mocha tests
126135
First you must install mocha with npm.
127136
```
@@ -132,14 +141,10 @@ Then, in the main generator-camel-project directory:
132141
> mocha
133142
```
134143

135-
## Known issues
144+
## Running the Generated Templates
136145

137-
Generated templates for spring and Java DSLs can be run with:
146+
Generated templates for spring, blueprint, and Java DSLs can be run with:
138147
```
139148
> mvn install
140149
> mvn camel:run
141150
```
142-
143-
Unfortunately, the blueprint version does not run successfully. Working on finding a solution.
144-
Created https://github.com/camel-tooling/generator-camel-project/issues/1
145-

Diff for: app/index.js

+224-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,17 @@ module.exports = class extends yeoman {
6988
showPrompts = false;
7089
}
7190

72-
if (showPrompts) {
91+
let showWsdl2Rest = this.options.wsdl2rest;
92+
93+
var showW2EPrompts = true;
94+
if (!showPrompts && showWsdl2Rest) {
95+
showW2EPrompts = !(utils.isNotNull(this.options.wsdl)) &&
96+
!(utils.isNotNull(this.options.outdirectory)) &&
97+
!(utils.isNotNull(this.options.jaxrs)) &&
98+
!(utils.isNotNull(this.options.jaxws));
99+
}
100+
101+
if (showPrompts || showW2EPrompts) {
73102
consoleHeader();
74103
}
75104

@@ -98,7 +127,9 @@ module.exports = class extends yeoman {
98127
message: 'Camel DSL type (blueprint, spring, or java)',
99128
choices: ['blueprint', 'spring', 'java'],
100129
default: defaultDSL,
101-
validate: utils.validateCamelDSL,
130+
validate: (value, showWsdl2Rest) => {
131+
return utils.validateCamelDSL(value, showWsdl2Rest);
132+
},
102133
store: true
103134
}, prompts);
104135
utils.addPrompt({
@@ -109,23 +140,73 @@ module.exports = class extends yeoman {
109140
validate : utils.validatePackage
110141
}, prompts);
111142

112-
if (showPrompts) {
143+
var defaultOutputDir = utils.setDefault(defaultOutputDirectory, this.options.outdirectory);
144+
var defaultJaxRS = utils.setDefault(defaultJaxRsUrl, this.options.jaxrs);
145+
var defaultJaxWS = utils.setDefault(defaultJaxWsUrl, this.options.jaxws);
146+
var defaultWsdl = utils.setDefault('no wsdl specified', this.options.wsdl);
147+
148+
if (showWsdl2Rest) {
149+
utils.addPrompt({
150+
type: 'input',
151+
name: 'wsdl',
152+
message: 'URL to the input WSDL',
153+
store: true
154+
}, prompts);
155+
utils.addPrompt({
156+
type: 'input',
157+
name: 'outdirectory',
158+
message: 'Name of the output directory for generated artifacts',
159+
default: defaultOutputDir,
160+
store: true
161+
}, prompts);
162+
utils.addPrompt({
163+
type: 'input',
164+
name: 'jaxrsURL',
165+
message: 'Address of the generated jaxrs endpoint',
166+
default: defaultJaxRS,
167+
store: true
168+
}, prompts);
169+
utils.addPrompt({
170+
type: 'input',
171+
name: 'jaxwsURL',
172+
message: 'Address of the target jaxws endpoint',
173+
default: defaultJaxWS,
174+
store: true
175+
}, prompts);
176+
}
177+
178+
if (showPrompts || showW2EPrompts) {
113179
return this.prompt(prompts).then(function (props) {
114180
this.appname = props.name;
115181
this.camelVersion = props.camelVersion;
116182
this.camelDSL = props.camelDSL;
117183
this.package = props.package;
184+
if (showWsdl2Rest) {
185+
this.outdirectory = props.outdirectory;
186+
this.wsdl = props.wsdl;
187+
this.jaxwsURL = props.jaxwsURL;
188+
this.jaxrsURL = props.jaxrsURL;
189+
}
118190
}.bind(this));
119191
} else {
120192
this.appname = defaultProject;
121193
this.camelVersion = defaultVersion;
122194
this.camelDSL = defaultDSL;
123195
this.package = defaultPackage;
124-
}
196+
if (showWsdl2Rest) {
197+
this.outdirectory = defaultOutputDir;
198+
this.wsdl = defaultWsdl;
199+
this.jaxwsURL = defaultJaxWS;
200+
this.jaxrsURL = defaultJaxRS;
201+
}
202+
}
125203
};
126204

127205
//writing logic here
128206
writing() {
207+
let showWsdl2Rest = this.options.wsdl2rest;
208+
let showDebug = this.options.debug;
209+
129210
var packageFolder = this.package.replace(/\./g, '/');
130211
var src = 'src/main/java';
131212
var myTemplatePath = path.join(this.templatePath(), this.camelDSL);
@@ -147,11 +228,144 @@ module.exports = class extends yeoman {
147228
userProps.package = this.package;
148229

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

0 commit comments

Comments
 (0)