Skip to content

Commit 9921453

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

15 files changed

+1292
-118
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/node_modules/
22
/coverage/
33
/.nyc_output/
4+
/app/wsdl2rest/target/
45
log-camel-lsp.out

.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;

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-

app/index.js

+170-7
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ 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.";
2732

@@ -55,6 +60,9 @@ module.exports = class extends yeoman {
5560
this.argument('camelVersion', { type: String, required: false });
5661
this.argument('camelDSL', { type: String, required: false });
5762
this.argument('package', { type: String, required: false });
63+
64+
this.option('wsdl2rest');
65+
this.option('debug');
5866
}
5967

6068
prompting() {
@@ -69,6 +77,8 @@ module.exports = class extends yeoman {
6977
showPrompts = false;
7078
}
7179

80+
let showWsdl2Rest = this.options.wsdl2rest;
81+
7282
if (showPrompts) {
7383
consoleHeader();
7484
}
@@ -98,7 +108,9 @@ module.exports = class extends yeoman {
98108
message: 'Camel DSL type (blueprint, spring, or java)',
99109
choices: ['blueprint', 'spring', 'java'],
100110
default: defaultDSL,
101-
validate: utils.validateCamelDSL,
111+
validate: (value, showWsdl2Rest) => {
112+
return utils.validateCamelDSL(value, showWsdl2Rest);
113+
},
102114
store: true
103115
}, prompts);
104116
utils.addPrompt({
@@ -109,12 +121,34 @@ module.exports = class extends yeoman {
109121
validate : utils.validatePackage
110122
}, prompts);
111123

124+
if (showWsdl2Rest) {
125+
var defaultOutput = 'src/main/java';
126+
utils.addPrompt({
127+
type: 'input',
128+
name: 'wsdl',
129+
message: 'URL to the input WSDL',
130+
store: true
131+
}, prompts);
132+
utils.addPrompt({
133+
type: 'input',
134+
name: 'outdirectory',
135+
message: 'Name of the output directory for generated artifacts',
136+
default: defaultOutput,
137+
store: true
138+
}, prompts);
139+
140+
}
141+
112142
if (showPrompts) {
113143
return this.prompt(prompts).then(function (props) {
114144
this.appname = props.name;
115145
this.camelVersion = props.camelVersion;
116146
this.camelDSL = props.camelDSL;
117147
this.package = props.package;
148+
if (showWsdl2Rest) {
149+
this.outdirectory = props.outdirectory;
150+
this.wsdl = props.wsdl;
151+
}
118152
}.bind(this));
119153
} else {
120154
this.appname = defaultProject;
@@ -126,6 +160,9 @@ module.exports = class extends yeoman {
126160

127161
//writing logic here
128162
writing() {
163+
let showWsdl2Rest = this.options.wsdl2rest;
164+
let showDebug = this.options.debug;
165+
129166
var packageFolder = this.package.replace(/\./g, '/');
130167
var src = 'src/main/java';
131168
var myTemplatePath = path.join(this.templatePath(), this.camelDSL);
@@ -147,11 +184,137 @@ module.exports = class extends yeoman {
147184
userProps.package = this.package;
148185

149186
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-
);
187+
var skipFile = false;
188+
if (showWsdl2Rest) {
189+
skipFile = testFileForWsdl2RestSkip(this.files[i]); //(testFileForWsdl2RestSkip(this.files[i]) == true);
190+
} else {
191+
skipFile = testFileForTemplateSkip(this.files[i]);
192+
}
193+
194+
if (!skipFile) {
195+
if(this.files[i].localeCompare('pom.xml.wsdl2rest') == 0) {
196+
var tempOutFile = "pom.xml";
197+
this.fs.copyTpl(
198+
this.templatePath(this.files[i]),
199+
this.destinationPath(tempOutFile.replace(/src\/main\/java/g, path.join(src, packageFolder))),
200+
{ userProps: userProps }
201+
);
202+
} else {
203+
this.fs.copyTpl(
204+
this.templatePath(this.files[i]),
205+
this.destinationPath(this.files[i].replace(/src\/main\/java/g, path.join(src, packageFolder))),
206+
{ userProps: userProps }
207+
);
208+
}
209+
}
210+
}
211+
212+
if (showWsdl2Rest) {
213+
return wsdl2restGenerate(this.wsdl, this.outdirectory, this.camelDSL, showDebug);
155214
}
156215
}
157216
};
217+
218+
var skipListForWsdl2RestFiles = [
219+
'src/main/resources/META-INF/spring/camel-context.xml',
220+
'src/main/resources/OSGI-INF/blueprint/blueprint.xml',
221+
'pom.xml'
222+
];
223+
224+
function testFileForWsdl2RestSkip(file) {
225+
for(var i=0; i<skipListForWsdl2RestFiles.length; i++) {
226+
if (skipListForWsdl2RestFiles[i] == file) return true;
227+
}
228+
}
229+
230+
var skipListForTemplateFiles = [
231+
'pom.xml.wsdl2rest'
232+
];
233+
234+
function testFileForTemplateSkip(file) {
235+
for(var i=0; i<skipListForTemplateFiles.length; i++) {
236+
if (skipListForTemplateFiles[i] == file) return true;
237+
}
238+
}
239+
240+
function wsdl2restGenerate(wsdlUrl, outputDirectory, dsl, isDebug) {
241+
if (dsl.includes('java')) {
242+
console.log(`Generating Rest DSL from SOAP for a Camel Java DSL is currently unsupported.`);
243+
return;
244+
}
245+
246+
var wsdl2restdir = path.join(__dirname, 'wsdl2rest');
247+
var targetDir = path.join(wsdl2restdir, 'target');
248+
var jar = utils.findWsdl2RestJar(targetDir);
249+
250+
var logPath = path.join(wsdl2restdir, 'config', 'logging.properties');
251+
var logUrl = fileUrl(logPath);
252+
253+
var actualJavaOutDirectory = outputDirectory;
254+
if (actualJavaOutDirectory.endsWith('/java')) {
255+
actualJavaOutDirectory = actualJavaOutDirectory.substring(0, actualJavaOutDirectory.indexOf("/java"));
256+
}
257+
var outPath = path.join(process.cwd(), actualJavaOutDirectory);
258+
var wsdlFileUrl;
259+
if (wsdlUrl.startsWith('http')) {
260+
wsdlFileUrl = wsdlUrl;
261+
} else if (!wsdlUrl.startsWith('file:')) {
262+
wsdlFileUrl = fileUrl(wsdlUrl);
263+
} else {
264+
wsdlFileUrl = wsdlUrl;
265+
}
266+
267+
if (!fs.existsSync(outPath)){
268+
console.log(`Creating wsdl2rest java output directory`);
269+
fs.mkdirSync(outPath);
270+
}
271+
272+
var restContextPath;
273+
var rawContextPath;
274+
var isBlueprint = dsl.includes('blueprint') > 0;
275+
if (isBlueprint) {
276+
rawContextPath = "src/main/resources/OSGI-INF/blueprint/blueprint.xml";
277+
} else {
278+
rawContextPath = "src/main/resources/META-INF/spring/camel-context.xml";
279+
}
280+
restContextPath = path.join(process.cwd(), rawContextPath);
281+
282+
// build the java command with classpath, class name, and the passed parameters
283+
var cmdString = 'java '
284+
+ ' -Dlog4j.configuration=' + logUrl
285+
+ ' -jar ' + jar
286+
+ ' --wsdl ' + wsdlFileUrl
287+
+ ' --out ' + outPath;
288+
289+
if (isBlueprint) {
290+
cmdString = cmdString + ' --blueprint-context ' + restContextPath;
291+
} else {
292+
cmdString = cmdString + ' --camel-context ' + restContextPath;
293+
}
294+
console.log('Calling wsdl2rest');
295+
if (isDebug) {
296+
console.log(' command used: ' + cmdString);
297+
}
298+
return new Promise((resolve, reject) => {
299+
const wsdl2rest = exec(cmdString);
300+
if (isDebug) {
301+
wsdl2rest.stdout.on('data', function (data) {
302+
console.log(`stdout: ${data}`);
303+
});
304+
wsdl2rest.stderr.on('data', function (data) {
305+
console.log(`stderr: ${data}`);
306+
});
307+
}
308+
wsdl2rest.on('close', function (code) {
309+
if (code === 0) {
310+
console.log(' ' + chalk.green('create') + ' CXF artifacts for specified WSDL at ' + outputDirectory);
311+
console.log(' ' + chalk.green('create') + ' ' + rawContextPath);
312+
resolve()
313+
} else {
314+
reject()
315+
console.log(` stderr: ${code}`);
316+
console.log(` wsdl2rest did not generate artifacts successfully - please check the log file for details or re-run with --debug flag`);
317+
}
318+
});
319+
})
320+
}

0 commit comments

Comments
 (0)