Skip to content

Commit

Permalink
adding wsdl2rest support to camel-project generator camel-tooling#11
Browse files Browse the repository at this point in the history
-- 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

Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
  • Loading branch information
bfitzpat committed Nov 30, 2018
1 parent 40eda99 commit 3383d28
Show file tree
Hide file tree
Showing 18 changed files with 2,465 additions and 110 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
/node_modules/
/coverage/
/.nyc_output/
/bin/
/app/wsdl2rest/target/
log-camel-lsp.out
.classpath
.project
/.settings/
app/wsdl2rest/.classpath
app/wsdl2rest/.project
/app/wsdl2rest/.settings/
.DS_Store
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ before_install:
- 'export PATH=./node_modules/.bin:$PATH'
- 'npm install -g typescript'
- 'npm install -g mocha'
- 'mvn install -f ./app/wsdl2rest/pom.xml'
install:
- 'npm install --ignore-scripts'
- 'npm install'
# https://github.com/travis-ci/travis-ci/issues/8813
- 'rm -f ./node_modules/.bin/which'
script:
- 'npm test --silent'
- 'mocha'
after_success:
- if [[ $TRAVIS_PULL_REQUEST == "false" && $TRAVIS_BRANCH == "master" ]]; then
sonar-scanner;
Expand Down
235 changes: 225 additions & 10 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ var yeoman = require('yeoman-generator');
var glob = require('glob');
var path = require('path');
var mkdirp = require('mkdirp');
var fileUrl = require('file-url');
var exec = require('child_process').exec;
var fs = require('fs');

const chalk = require('chalk');
const utils = require('./util');

const defaultCamelVersion = "2.22.1";
const defaultCamelVersion = "2.22.2";
const defaultCamelDSL = "spring";
const defaultPackagePrefix = "com.";
const defaultOutputDirectory = 'src/main/java';
const defaultJaxRsUrl = "http://localhost:8081/jaxrs";
const defaultJaxWsUrl = "http://localhost:8080/somepath";

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

// base arguments
this.argument('appname', { type: String, required: false });
this.argument('camelVersion', { type: String, required: false });
this.argument('camelDSL', { type: String, required: false });
this.argument('package', { type: String, required: false });

// wsdl2rest options
this.option('wsdl2rest');
this.option('debug');

// wsdl2rest arguments
this.argument('wsdl', { type: String, required: false });
this.argument('outdirectory', { type: String, required: false });
this.argument('jaxrs', { type: String, required: false });
this.argument('jaxws', { type: String, required: false });
}

prompting() {
Expand All @@ -69,7 +88,18 @@ module.exports = class extends yeoman {
showPrompts = false;
}

if (showPrompts) {
let showWsdl2Rest = this.options.wsdl2rest;
if (typeof showWsdl2Rest == 'undefined') showWsdl2Rest = false;

var showW2RPrompts = true;
if (!showPrompts && showWsdl2Rest) {
showW2RPrompts = (utils.isNull(this.options.wsdl)) &&
(utils.isNull(this.options.outdirectory)) &&
(utils.isNull(this.options.jaxrs)) &&
(utils.isNull(this.options.jaxws));
}

if (showPrompts || showW2RPrompts) {
consoleHeader();
}

Expand Down Expand Up @@ -98,7 +128,9 @@ module.exports = class extends yeoman {
message: 'Camel DSL type (blueprint, spring, or java)',
choices: ['blueprint', 'spring', 'java'],
default: defaultDSL,
validate: utils.validateCamelDSL,
validate: (value) => {
return utils.validateCamelDSL(value, showWsdl2Rest);
},
store: true
}, prompts);
utils.addPrompt({
Expand All @@ -109,23 +141,73 @@ module.exports = class extends yeoman {
validate : utils.validatePackage
}, prompts);

if (showPrompts) {
var defaultOutputDir = utils.setDefault(defaultOutputDirectory, this.options.outdirectory);
var defaultJaxRS = utils.setDefault(defaultJaxRsUrl, this.options.jaxrs);
var defaultJaxWS = utils.setDefault(defaultJaxWsUrl, this.options.jaxws);
var defaultWsdl = utils.setDefault('no wsdl specified', this.options.wsdl);

if (showWsdl2Rest) {
utils.addPrompt({
type: 'input',
name: 'wsdl',
message: 'URL to the input WSDL',
store: true
}, prompts);
utils.addPrompt({
type: 'input',
name: 'outdirectory',
message: 'Name of the output directory for generated artifacts',
default: defaultOutputDir,
store: true
}, prompts);
utils.addPrompt({
type: 'input',
name: 'jaxrsURL',
message: 'Address of the generated jaxrs endpoint',
default: defaultJaxRS,
store: true
}, prompts);
utils.addPrompt({
type: 'input',
name: 'jaxwsURL',
message: 'Address of the target jaxws endpoint',
default: defaultJaxWS,
store: true
}, prompts);
}

if (showPrompts || showW2RPrompts) {
return this.prompt(prompts).then(function (props) {
this.appname = props.name;
this.camelVersion = props.camelVersion;
this.camelDSL = props.camelDSL;
this.package = props.package;
if (showWsdl2Rest) {
this.outdirectory = props.outdirectory;
this.wsdl = props.wsdl;
this.jaxwsURL = props.jaxwsURL;
this.jaxrsURL = props.jaxrsURL;
}
}.bind(this));
} else {
this.appname = defaultProject;
this.camelVersion = defaultVersion;
this.camelDSL = defaultDSL;
this.package = defaultPackage;
}
if (showWsdl2Rest) {
this.outdirectory = defaultOutputDir;
this.wsdl = defaultWsdl;
this.jaxwsURL = defaultJaxWS;
this.jaxrsURL = defaultJaxRS;
}
}
};

//writing logic here
writing() {
let showWsdl2Rest = this.options.wsdl2rest;
let showDebug = this.options.debug;

var packageFolder = this.package.replace(/\./g, '/');
var src = 'src/main/java';
var myTemplatePath = path.join(this.templatePath(), this.camelDSL);
Expand All @@ -147,11 +229,144 @@ module.exports = class extends yeoman {
userProps.package = this.package;

for (var i = 0; i < this.files.length; i++) {
this.fs.copyTpl(
this.templatePath(this.files[i]),
this.destinationPath(this.files[i].replace(/src\/main\/java/g, path.join(src, packageFolder))),
{ userProps: userProps }
);
var skipFile = false;
if (showWsdl2Rest) {
skipFile = testFileForWsdl2RestSkip(this.files[i]);
} else {
skipFile = testFileForTemplateSkip(this.files[i]);
}

if (!skipFile) {
if(this.files[i].localeCompare('pom.xml.wsdl2rest') == 0) {
var tempOutFile = "pom.xml";
this.fs.copyTpl(
this.templatePath(this.files[i]),
this.destinationPath(tempOutFile.replace(/src\/main\/java/g, path.join(src, packageFolder))),
{ userProps: userProps }
);
} else {
this.fs.copyTpl(
this.templatePath(this.files[i]),
this.destinationPath(this.files[i].replace(/src\/main\/java/g, path.join(src, packageFolder))),
{ userProps: userProps }
);
}
}
}

if (showWsdl2Rest) {
return wsdl2restGenerate(this.wsdl, this.outdirectory, this.jaxrsURL, this.jaxwsURL, this.camelDSL, showDebug);
}
}
};

var skipListForWsdl2RestFiles = [
'src/main/resources/META-INF/spring/camel-context.xml',
'src/main/resources/OSGI-INF/blueprint/blueprint.xml',
'pom.xml'
];

function testFileForWsdl2RestSkip(file) {
for(var i=0; i<skipListForWsdl2RestFiles.length; i++) {
if (skipListForWsdl2RestFiles[i] == file) return true;
}
}

var skipListForTemplateFiles = [
'pom.xml.wsdl2rest'
];

function testFileForTemplateSkip(file) {
for(var i=0; i<skipListForTemplateFiles.length; i++) {
if (skipListForTemplateFiles[i] == file) return true;
}
}

function wsdl2restGenerate(wsdlUrl, outputDirectory, jaxrs, jaxws, dsl, isDebug) {
if (dsl.includes('java')) {
console.log(`Generating Rest DSL from SOAP for a Camel Java DSL is currently unsupported.`);
return;
}

var wsdl2restdir = path.join(__dirname, 'wsdl2rest');
var targetDir = path.join(wsdl2restdir, 'target');
var jar = utils.findWsdl2RestJar(targetDir);

var logPath = path.join(wsdl2restdir, 'config', 'logging.properties');
var logUrl = fileUrl(logPath);

var actualJavaOutDirectory = outputDirectory;
if (actualJavaOutDirectory.endsWith('/java')) {
actualJavaOutDirectory = actualJavaOutDirectory.substring(0, actualJavaOutDirectory.indexOf("/java"));
}
var outPath = path.join(process.cwd(), actualJavaOutDirectory);
var wsdlFileUrl;
if (wsdlUrl.startsWith('http')) {
wsdlFileUrl = wsdlUrl;
} else if (!wsdlUrl.startsWith('file:')) {
wsdlFileUrl = fileUrl(wsdlUrl);
} else {
wsdlFileUrl = wsdlUrl;
}

if (!fs.existsSync(outPath)){
console.log(`Creating wsdl2rest java output directory`);
fs.mkdirSync(outPath);
}

var restContextPath;
var rawContextPath;
var isBlueprint = dsl.includes('blueprint') > 0;
if (isBlueprint) {
rawContextPath = "src/main/resources/OSGI-INF/blueprint/blueprint.xml";
} else {
rawContextPath = "src/main/resources/META-INF/spring/camel-context.xml";
}
restContextPath = path.join(process.cwd(), rawContextPath);

// build the java command with classpath, class name, and the passed parameters
var cmdString = 'java '
+ ' -Dlog4j.configuration=' + logUrl
+ ' -jar ' + jar
+ ' --wsdl ' + wsdlFileUrl
+ ' --out ' + outPath;

if (isBlueprint) {
cmdString = cmdString + ' --blueprint-context ' + restContextPath;
} else {
cmdString = cmdString + ' --camel-context ' + restContextPath;
}

if (jaxrs) {
cmdString = cmdString + ' --jaxrs ' + jaxrs;
}
if (jaxws) {
cmdString = cmdString + ' --jaxws ' + jaxws;
}
console.log('Calling wsdl2rest');
if (isDebug) {
console.log(' command used: ' + cmdString);
}
return new Promise((resolve, reject) => {
const wsdl2rest = exec(cmdString);
if (isDebug) {
wsdl2rest.stdout.on('data', function (data) {
console.log(`stdout: ${data}`);
});
wsdl2rest.stderr.on('data', function (data) {
console.log(`stderr: ${data}`);
});
}
wsdl2rest.on('close', function (code) {
if (code === 0) {
console.log(' ' + chalk.green('create') + ' CXF artifacts for specified WSDL at ' + outputDirectory);
console.log(' ' + chalk.green('create') + ' ' + rawContextPath);
resolve()
} else {
reject()
console.log(` stderr: ${code}`);
console.log(` wsdl2rest did not generate artifacts successfully - please check the log file for details or re-run with --debug flag`);
}
});
})
}
Loading

0 comments on commit 3383d28

Please sign in to comment.