WADL Generation Tool - java

Is there a tool which takes a Java File what describes a REST service as a parameter and generates a wadl file out of that.

I had the same problem: was using RESTeasy and wanted to find a way to generate the WADL automatically.
Did some research and came to the solution below.
1. Add this to your pom.xml:
<build>
<plugins>
<plugin>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>maven-wadl-plugin</artifactId>
<version>1.17</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
<phase>${javadoc-phase}</phase>
</execution>
</executions>
<configuration>
<wadlFile>${project.build.outputDirectory}/application.wadl
</wadlFile>
<formatWadlFile>true</formatWadlFile>
<baseUri>http://example.com:8080/rest</baseUri>
<packagesResourceConfig>
<param>com.example.rs.resource</param>
</packagesResourceConfig>
<wadlGenerators>
<wadlGeneratorDescription>
<className>com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc
</className>
<properties>
<property>
<name>applicationDocsFile</name>
<value>${basedir}/src/main/doc/application-doc.xml</value>
</property>
</properties>
</wadlGeneratorDescription>
<wadlGeneratorDescription>
<className>com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport
</className>
<properties>
<property>
<name>grammarsFile</name>
<value>${basedir}/src/main/doc/application-grammars.xml</value>
</property>
</properties>
</wadlGeneratorDescription>
</wadlGenerators>
</configuration>
</plugin>
</plugins>
</build>
Pay attention to the buildUri and packagesResourceConfig elements. You have to change them to reflect your project's configuration. You may also want to change the plugin's version (I used 1.17).
2. Create a /doc folder and add some files.
Create the src/main/doc/ folder and create the two files below.
File: application-doc.xml
Content:
<?xml version="1.0" encoding="UTF-8"?>
<applicationDocs targetNamespace="http://wadl.dev.java.net/2009/02">
<doc xml:lang="en" title="A message in the WADL">This is added to the start of the generated application.wadl</doc>
</applicationDocs>
File: application-grammars.xml
Content:
<?xml version="1.0" encoding="UTF-8" ?>
<grammars xmlns="http://wadl.dev.java.net/2009/02" />
3. Run the maven command.
Go to the project folder and run the following command:
$ mvn compile com.sun.jersey.contribs:maven-wadl-plugin:generate
The files \target\classes\application.wadl (the WADL itself) and \target\classes\xsd0.xsd (the schema of the resources - it's used by the application.wadl) should be generated.
Edit and use them as you wish.
PS.: Bear in mind that this is a very simple use of the maven-wadl-plugin. It can do a lot more. To know it better, please refer to the zip file mentioned in the other answer (by Pavel Bucek).

Yes, please see gerenate-wadl [1] sample from Jersey samples (look for maven-wadl-plugin).
[1] http://search.maven.org/remotecontent?filepath=com/sun/jersey/samples/generate-wadl/1.12/generate-wadl-1.12-project.zip

Related

Access Maven property "developers" in application.yml (Spring Boot)

I want to have the developer, which is defined in the pom.xml with the tag to appear in the application.yml after the build process. Somehow it is working with all attributes but developers.
This is in a Spring Boot project, I want the attributes to be filled during the build process.
This is an excerpt of the pom.xml
<description>my description</description>
<developers>
<developer>
<id>12345</id>
<name>John Doe</name>
<email>john#doe.com</email>
</developer>
</developers>
This is in application.yml
info:
description: "#project.description#"
developer: "#project.developers[0].id#"
It works for description, but not for developer. I tried many variations, e.g. ${..}, "#project.developers.0.id". Nothing seems to be working.
If anybody has an idea, I would be very grateful.
You can read the developer id or email address or any values from the pom.xml with this elegant way:
Generate the build-info.properties with the default data plus your additional data
Read values from this file easily with Spring via the BuildProperties.
pom.xml:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
<configuration>
<additionalProperties>
<developer>${project.developers[0].email}</developer>
</additionalProperties>
</configuration>
</execution>
</executions>
</plugin>
This will produce a build-info.properties file under the META-INF directory with the following content:
build.artifact=<artifactId-from-pom>
build.group=<groupId-from-pom>
build.name=<name-from-pom>
build.time=<build-time>
build.version=<version-from-pom>
build.developer=<email-of-the-first-developer-from-pom>
Then you can read values with Spring:
#Configuration
public class OpenApiConfiguration {
#Autowired
private BuildProperties buildProperties;
#Bean
public OpenAPI customOpenAPI()) {
return new OpenAPI().info(new Info()
.title(...)
.version(buildProperties.getVersion())
.contact(new Contact().email(buildProperties.get("developer"))));
}
}
To read:
Spring Boot Maven Plugin
BuildProperties
I hope that this will help you.
Add it on the property and use on pom and property file, example:
<properties>
<team.name>John Doe</team.name>
</properties>
Use on developer data:
<developers>
<developer>
<name>${team.name}</name>
...
And in the application use the property:
description: "#team.name#"

How to work around the stricter Java 8 Javadoc when using Maven

You'll quickly realize that JDK8 is a lot more strict (by default) when it comes to Javadoc. (link - see last bullet point)
If you never generate any Javadoc then of course you'll not experience any problems but things like Maven release process and possibly your CI builds will suddenly fail where they worked just fine with JDK7. Anything that checks the exit value of the Javadoc tool will now fail. JDK8 Javadoc is probably also more verbose in terms of warnings compared to JDK7 but that's not the scope here. We are talking about errors!
This question exist to collect proposals on what to do about it. What is the best approach ? Should these errors be fixed once and for all in the source code files? If you have a huge code base this might be a lot of work. What other options exist ?
You are also welcome to comment with stories of what now fails that would previously pass.
Horror stories of what now fails
wsimport tools
wsimport tool is a code generator for creating web service consumers. It is included in the JDK. Even if you use the wsimport tool from JDK8 it will nevertheless produce source code that cannot be compiled with the javadoc compiler from JDK8.
#author tag
I'm opening up source code files 3-4 years old and see this:
/**
* My very best class
* #author John <john.doe#mine.com>
*/
This now fails because of the < character. Strictly speaking this is justified, but not very forgiving.
HTML tables
HTML Tables in your Javadoc? Consider this valid HTML:
/**
*
* <table>
* <tr>
* <td>Col1</td><td>Col2</td><td>Col3</td>
* </tr>
* </table>
*/
This now fails with error message no summary or caption for table. One quick fix is to do like this:
/**
*
* <table summary="">
* <tr>
* <td>Col1</td><td>Col2</td><td>Col3</td>
* </tr>
* </table>
*/
but why this has to be a stop-the-world error from Javadoc tool beats me??
Things that now fail for more obvious reasons
Invalid links, e.g. {#link notexist}
Malformed HTML, e.g. always returns <code>true<code> if ...
UPDATE
Links:
Excellent blog on the subject by Stephen Colebourne.
For now, the easiest way I know to work around the stricter Java 8 Javadoc when using Maven is deactivating it.
Since the parameter -Xdoclint:none only exists in Java 8, defining this parameter breaks the build for any other Java. To prevent this, we can create a profile that will be active only for Java 8, making sure our solution works regardless of the Java version.
<profiles>
<profile>
<id>disable-java8-doclint</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<additionalparam>-Xdoclint:none</additionalparam>
</properties>
</profile>
</profiles>
Just add that to your POM and you're good to go.
For maven-javadoc-plugin 3.0.0 users:
Replace
<additionalparam>-Xdoclint:none</additionalparam>
by
<doclint>none</doclint>
Thanks #banterCZ!
If you are using the maven javadoc plugin, you can use the failOnError option to prevent it from stopping if it finds any html errors:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<failOnError>false</failOnError>
</configuration>
</plugin>
Or you can deactivate the strict html options completely with:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</plugin>
</plugins>
For more info.
Note that for the error no summary or caption for table, using <table summary=""> won't work anymore. If that's your situation, add a <caption> element to your table, like this:
<table>
<caption>Examples</caption>
...
</table>
Hope this helps someone out there. It took me a while until I found this out.
Since version 3.0.0 of maven-javadoc-plugin the doclint is configured via the dedicated XML tag
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<doclint>none</doclint>
</configuration>
</plugin>
I like #ThiagoPorciúncula's solution but it didn't quite go far enough for me.
I typically already have javadoc plugin additionalparam set which were not being overridden by the profile. Because of this I had to:
Set a disableDoclint property to be empty by default.
If in java >= 8, set the disableDoclint property to be -Xdoclint:none
The use ${disableDoclint} in the additionalparam section of the maven-javadoc-plugin.
This seems to work well albeit verbose.
<properties>
<!-- set empty property -->
<disableDoclint></disableDoclint>
</properties>
<profiles>
<profile>
<id>disable-java8-doclint</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<!-- set property if >= java 8 -->
<disableDoclint>-Xdoclint:none</disableDoclint>
</properties>
</profile>
...
</profiles>
Then down below I could use the optional ${disableDoclint} variable in the additionalparam section that I had already defined.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<showPackage>false</showPackage>
<additionalparam>-tag inheritDoc:X ${disableDoclint}</additionalparam>
</configuration>
</execution>
</executions>
<configuration>
<showPackage>false</showPackage>
<bottom>This documentation content is licensed...</bottom>
<additionalparam>-tag inheritDoc:X ${disableDoclint}</additionalparam>
</configuration>
</plugin>
This works under java 8 but doesn't cause syntax errors under java 7. Woo hoo!

JAX-WS service implementation class name customization not working

I'm using Maven to generate the implementation code for a web service. Originally, this code was generated from a WSDL and schema using something else (probably a wizard in Eclipse). The service implementation class name that jaxws-maven-plugin generates is MyService_MyServieSOAPImpl. When this was originally generated, the implementation class was named MyService_SOAPImplementation. I'm guessing that the wizard that Eclipse uses allows the user to choose the name of the implementation class. I tried using the sei element, but it does not work. Here's a snippet of the wsimport plugin in my POM:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<id>generateMyServiceFromWSDL</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<genJWS>true</genJWS>
<bindingDirectory>${basedir}/src/main/bindings</bindingDirectory>
<bindingFiles>
<bindingFile>otherSchema.episode</bindingFile>
</bindingFiles>
<wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>MyService.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>${project.basedir}/src/main/resources/wsdl/MyService.wsdl</wsdlLocation>
<sourceDestDir>${project.basedir}/src/main/java</sourceDestDir>
<sei>com.myCompany.MyService_SOAPImplementation</sei>
<xdonotoverwrite>true</xdonotoverwrite>
<xnocompile>true</xnocompile>
<xdebug>true</xdebug>
<verbose>true</verbose>
<target>2.0</target>
</configuration
</execution>
...
From some of the documents I've read, it looks like sei is only applicable for wsgen, not wsimport. If that is so, is there any way to force a name for the implementation class name?
UPDATE
Ok, so from my reading, it should be possible to do this with a JAX-WS binding file, not directly in the POM file.
I've created my binding file like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxws:bindings version="2.1" xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
jaxws:wsdlLocation="src/main/webapp/wsdl/MyService.wsdl">
<jaxws:bindings node="wsdl:definitions/wsdl:portType[#name='MyService']">
<!-- change the generated SEI class -->
<jxb:class name="MyServiceSOAPImpl"></jxb:class>
</jaxws:bindings>
</jaxws:bindings>
But this still doesn't seem to have any effect - wsimport is still producing the implementation as MyService_MyServiceSOAPImpl.
Try changing your
<jaxws:bindings node="wsdl:definitions/wsdl:portType[#name='MyService']">
to
<jaxws:bindings node="wsdl:definitions/wsdl:service[#name='MyServiceService']">
Note that the second part of the node path is service and not portType. You would use portType to customize the service interface, not the implementation.
As an aside it's important to note that JAX-WS bindings (seemingly) need to be in their own XML file (per WSDL) and not included with JAXB bindings.
Someone may find the list of JAX-WS bindings here to be useful: http://docs.oracle.com/cd/E13222_01/wls/docs103/webserv/data_types.html#wp227312
In case this helps someone, two changes are required in OPs bindings.xml file to get it to work:
The first change was already suggested by MGE - changing the wsdl:portType in the Xpath to wsdl:service
The namespace for class name has to be 'jaxws', so
change to this:
<jaxws:class name="MyServiceSOAPImpl"/>
from
<jxb:class name="MyServiceSOAPImpl"></jxb:class>

Composite components in an external JAR are not recognized in Netbeans

I have packaged a number of composite components in a JAR. However, when using them in another project (using Maven), Netbeans editor puts red error lines under lines which use the composite component, even though the project compiles and runs as expected.
The folder structure for the composite component JAR look like:
compositeComponent.jar
META-INF
faces-config.xml
highcharts-taglib.xml
MANIFEST.MF
web.xml
maven
// maven stuff.
resources
highcharts
Chart.xhtml
Series.xhtml
Tooltip.xml
nz
co
kevindoran
highcharts
example
NZPopulationTrend.class
The highcharts.taglib.xml looks like:
<facelet-taglib version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd">
<namespace>http://nz.co.kevindoran/highcharts-jsf</namespace>
<composite-library-name>highcharts</composite-library-name>
</facelet-taglib>
[Side note: The faces-config.xml and web.xml are present to allow the 'JAR' to be deployed as a WAR by changing the file extension to WAR (this is to done to run the examples).]
In my current project, I have specify a Maven dependency on the above project like so:
<dependency>
<groupId>nz.co.kevindoran</groupId>
<artifactId>jsf-menu</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
In a JSF page, I use on of the composite components like so:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:hc="http://nz.co.kevindoran/highcharts-jsf">
....
<hc:TimeChart title="Price Over Time" xLabel="Date" yLabel="Sold Price (NZD)">
<hc:TimeSeries name="Sold" series="#{cc.attrs.model.priceVsTimeChart.soldSeries}"/>
</hc:TimeChart>
....
</html>
Red error lines appear under all lines above, with message: "No library found for namespace http://nz.co.kevindoran/highcharts-jsf"
How do I get these error lines to be removed? I have seen many Netbeans bug reports for similar issues, but all seem resolved.
This error occurs on Netbeans 7.1, 7.2 and 7.3 (including 7.3.1).
I have absolutely the same problem. In my case it depends on the /src/main/java folder. If it's exist (only in the project and not even in the jar) the project which includes this library shows the "No library found for namespace... "
When i remove the "java" folder it works. But then my backing bean class is missed in the jar...
Tried with Netbeans 7.2 and 7.3, maven 2
Solution:
Generate a second project which contains the Java source files. (called: jsf-lib-java)
In jsf-lib project (your composite component project with xhtml) delete the "java" folder and all *.java sources.
add in the jsf-lib pom.xml following configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.mycompany.project</groupId>
<artifactId>jsf-lib-java</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>src/main/</outputDirectory>
<includes>**/*.class</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
That's it. This will generate a "good" jar file with the required *.class files. So it's possible to "trick" Netbeans.
Now i work with this solution. It's a hack but didn't found a better solution.

control schema file name created by jaxb schemagen maven plugin (maven-jaxb-schemagen-plugin)

I don't seem to be able to work out how to get control the file name of the XSD file created by maven-jaxb-schemagen-plugin. The documentation is a bit sparse.
<groupId>com.sun.tools.jxc.maven2</groupId>
<artifactId>maven-jaxb-schemagen-plugin</artifactId>
<version>1.2</version>
<configuration>
<project>${project}</project>
<destdir>${project.build.directory}/generated-resources/schemas</destdir>
<srcdir>${project.build.sourceDirectory}/my/jaxb/bean/package</srcdir>
<verbose>true</verbose>
</configuration>
It always seems to create a file called schema1.xsd
You need to add schema elements which describe which file should contain the elements of each namespace you have:
<configuration>
[...]
<schemas>
<schema>
<namespace>http://www.example.invalid/2001/05/27/wibble</namespace>
<file>wibble.xsd</file>
</schema>
</schemas>
<configuration>
Assuming you have set the namespace of you components
#XmlRootElement(name = "wobble", namespace="http://www.example.invalid/2001/05/27/wibble")

Categories

Resources