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

Signed-off-by: Brian Fitzpatrick <bfitzpat@redhat.com>
  • Loading branch information
bfitzpat committed Nov 15, 2018
1 parent a636b6b commit ad41322
Show file tree
Hide file tree
Showing 10 changed files with 570 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/node_modules/
/coverage/
/.nyc_output/
/app/wsdl2rest/target/
log-camel-lsp.out
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
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,31 @@ The generator is located in the npm repository (https://www.npmjs.com/package/ge
\____| \__,_| |_| |_| |_| \___| |_|
-----------------------------------------------
Camel Project Generator
Version: 0.1.2
-----------------------------------------------
? Your Camel project name (myproject)
? Your Camel version 2.18.1
? DSL type (blueprint or spring) blueprint
? Your Camel version 2.18.2
? Camel DSL type (blueprint, spring, or java) blueprint
? Package name: com.myproject
camel project name myproject
camel version 2.18.1
camel version 2.18.2
camel DSL blueprint
package name com.myproject
Creating folders
Copying files
Copying dot files
create pom.xml
create README.md
create src\main\resources\OSGI-INF\blueprint\blueprint.xml
create src\main\resources\OSGI-INF\log4j2.properties
>
```

### Notes on input fields

* 'Camel project name' defaults to the name of the directory in which you start the generator.
* '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.
* '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'.".
* '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.
* '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'.".
* '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.

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

## Running the Generator from the Command Line (*NEW*)
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.

This allows us to do things like the following and avoid having to go through the prompts:
```
> yo camel-project appname=MyApp camelVersion=2.19.1 camelDSL=spring package=com.myapp
```

### Running the Mocha tests
First you must install mocha with npm.
```
Expand All @@ -132,14 +141,10 @@ Then, in the main generator-camel-project directory:
> mocha
```

## Known issues
## Running the Generated Templates

Generated templates for spring and Java DSLs can be run with:
Generated templates for spring, blueprint, and Java DSLs can be run with:
```
> mvn install
> mvn camel:run
```

Unfortunately, the blueprint version does not run successfully. Working on finding a solution.
Created https://github.com/camel-tooling/generator-camel-project/issues/1

101 changes: 100 additions & 1 deletion app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ 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 utils = require('./util');

const defaultCamelVersion = "2.22.1";
const defaultCamelVersion = "2.22.2";
const defaultCamelDSL = "spring";
const defaultPackagePrefix = "com.";

Expand Down Expand Up @@ -55,6 +59,8 @@ module.exports = class extends yeoman {
this.argument('camelVersion', { type: String, required: false });
this.argument('camelDSL', { type: String, required: false });
this.argument('package', { type: String, required: false });

this.option('wsdl2rest');
}

prompting() {
Expand All @@ -69,6 +75,8 @@ module.exports = class extends yeoman {
showPrompts = false;
}

let showWsdl2Rest = this.options.wsdl2rest;

if (showPrompts) {
consoleHeader();
}
Expand Down Expand Up @@ -109,12 +117,34 @@ module.exports = class extends yeoman {
validate : utils.validatePackage
}, prompts);

if (showWsdl2Rest) {
var defaultOutput = 'src//main//java';
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: defaultOutput,
store: true
}, prompts);

}

if (showPrompts) {
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;
}
}.bind(this));
} else {
this.appname = defaultProject;
Expand All @@ -126,6 +156,8 @@ module.exports = class extends yeoman {

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

var packageFolder = this.package.replace(/\./g, '/');
var src = 'src/main/java';
var myTemplatePath = path.join(this.templatePath(), this.camelDSL);
Expand Down Expand Up @@ -153,5 +185,72 @@ module.exports = class extends yeoman {
{ userProps: userProps }
);
}

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

function wsdl2restGenerate(wsdlUrl, outputDirectory, dsl) {
if (dsl.indexOf('java') > 0) {
console.log(`Generating Rest DSL from SOAP for a Camel Java DSL is currently unsupported.`);
}

var wsdl2restdir = path.join(__dirname, 'wsdl2rest');
var targetDir = path.join(wsdl2restdir, 'target');
var jar = path.join(targetDir, 'wsdl2rest-impl-fatjar-0.1.3-SNAPSHOT.jar');
var outPath = path.join(process.cwd(), outputDirectory);
var wsdlFileUrl;
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 blueprintPath;
var springPath;
var isBlueprint = dsl.includes('blueprint') > 0;
if (isBlueprint) {
blueprintPath = path.join(process.cwd(), "src/main/resources/OSGI-INF/blueprint/blueprint-rest.xml");
} else {
springPath = path.join(process.cwd(), "src/main/resources/META-INF/spring/camel-context-rest.xml");
};

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

if (isBlueprint) {
cmdString = cmdString + ' --blueprint-context ' + blueprintPath;
} else {
cmdString = cmdString + ' --camel-context ' + springPath;
}
console.log('calling: ' + cmdString);
return new Promise((resolve, reject) => {
const wsdl2rest = exec(cmdString);
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(`wsdl2rest generated artifacts successfully`);
resolve()
} else {
reject()
console.log(`stderr: ${code}`);
console.log(`wsdl2rest did not generate artifacts successfully - please check the log file for details`);
}
});
})
}
38 changes: 38 additions & 0 deletions app/wsdl2rest/config/logging.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
###
# #%L
# Fuse wsdl2rest :: Distro :: Standalone
# %%
# Copyright (C) 2015 Private
# %%
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# #L%
###

# Root logger option
log4j.rootLogger=DEBUG, file, console

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.file=wsdl2rest.log
log4j.appender.file.append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n
log4j.appender.file.threshold=DEBUG

# Direct log messages to console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%m%n
log4j.appender.console.threshold=INFO

Loading

0 comments on commit ad41322

Please sign in to comment.