0
votes

I am trying to learn about jax-ws and created a simple Bottom-Up HelloWorld webservice in order to train myself:

import org.jboss.annotation.ejb.LocalBinding;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(serviceName = "HelloWorldWebServiceExperiment",
    portName = "HelloWorldPort",
    name = "HelloWorld")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, 
    use = SOAPBinding.Use.LITERAL, 
    parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
@Stateless
@Remote
@LocalBinding(jndiBinding = "training.webservice.HelloWorldWebServiceRemote/local")

public class HelloWorldWebServiceBean {
    private static final String HELLO_WORLD = "Hello World";
    @WebMethod
    public String helloWorld() {
        return HELLO_WORLD;
    }
}

When I deploy this webservice I can access the wsdl, so that seems to work fine. Then I tried to generate a webservice client. And to do so I needed to create stubs, which I tried to create with the maven plugin jaxws-maven-plugin. Here is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>training.webservice</groupId>
<artifactId>HelloWorldWebServiceExperiment</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
    <wsdlPath>${project.build.directory}</wsdlPath>
</properties>

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webResources>
                    <resource>
                        <targetPath>WEB-INF</targetPath>
                        <directory>src/main/webapp/WEB-INF</directory>
                        <includes>
                            <include>web.xml</include>
                        </includes>
                        <filtering>true</filtering>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>genwsdl</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>wsgen</goal>
                    </goals>
                    <configuration>
                        <genWsdl>true</genWsdl>
                        <sei>training.webservice.HelloWorldWebServiceBean</sei>
                    </configuration>
                </execution>
                <execution>
                    <id>consumeWsdlForStubs</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <wsdlDirectory>target/jaxws/wsgen/wsdl</wsdlDirectory>
                        <wsdlFiles>
                            <wsdlFile>HelloWorldWebServiceExperiment.wsdl</wsdlFile>
                        </wsdlFiles>
                        <keep>true</keep>
                        <destDir>target/classes</destDir>
                        <sourceDestDir>target/stubs</sourceDestDir>
                        <verbose>true</verbose>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <executions>
                <execution>
                    <id>package-wsclient-jars</id>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                    <configuration>
                        <classesDirectory>target/stubs</classesDirectory>
                        <classifier>wsclient</classifier>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

<dependencies>
    <!-- JAX-WS Annotations -->
    <dependency>
        <groupId>javax.jws</groupId>
        <artifactId>jsr181-api</artifactId>
        <version>1.0-MR1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>jboss</groupId>
        <artifactId>jbossws-spi</artifactId>
        <version>1.0.0.GA</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jboss-ejb3x</artifactId>
        <version>4.2.2</version>
        <!--<scope>provided</scope>-->
    </dependency>
    <dependency>
        <groupId>jboss</groupId>
        <artifactId>jboss-annotations-ejb3</artifactId>
        <version>4.2.2.GA</version>
        <!--<scope>provided</scope>-->
    </dependency>
    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jboss-jaxws</artifactId>
        <version>4.2.2</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

The Build with maven will generate the follwoing output and a .jar file with generated .java files:

> mvn clean install
[INFO] Scanning for projects...
[INFO]         ------------------------------------------------------------------------
[INFO] Building Unnamed - training.webservice:HelloWorldWebServiceExperiment:war:1.0-SNAPSHOT
[INFO]    task-segment: [clean, install]
[INFO]     ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory ---/HelloWorldWebServiceExperiment/target
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to ---/HelloWorldWebServiceExperiment/target/classes
[INFO] [compiler:compile {execution: default}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [jaxws:wsgen {execution: genwsdl}]
[INFO] [jaxws:wsimport {execution: consumeWsdlForStubs}]
[INFO] Processing: ---/HelloWorldWebServiceExperiment/target/jaxws/wsgen/wsdl/HelloWorldWebServiceExperiment.wsdl
[INFO] jaxws:wsimport args: [-s, ---/    /HelloWorldWebServiceExperiment/target/jaxws/wsimport/java, -d, ---/HelloWorldWebServiceExperiment/target/classes, -verbose, -Xnocompile, ---/HelloWorldWebServiceExperiment/target/jaxws/wsgen/wsdl/HelloWorldWebServiceExperiment.wsdl]
parsing WSDL...


generating code...

training/webservice/HelloWorld.java
training/webservice/HelloWorldResponse.java
training/webservice/HelloWorldWebServiceExperiment.java
training/webservice/HelloWorld_Type.java
training/webservice/ObjectFactory.java
training/webservice/package-info.java
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory ---/HelloWorldWebServiceExperiment/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp[HelloWorldWebServiceExperiment] in [---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp webResources[---/HelloWorldWebServiceExperiment/src/main/webapp/WEB-INF] to[---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT]
[INFO] Copying webapp resources[---/HelloWorldWebServiceExperiment/src/main/webapp]
[INFO] Webapp assembled in[33 msecs]
[INFO] Building war: ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT.war
[INFO] [jar:jar {execution: package-wsclient-jars}]
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT-wsclient.jar
[INFO] [install:install {execution: default-install}]
[INFO] Installing ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT.war to ~/.m2/repository/training/webservice/HelloWorldWebServiceExperiment/1.0-SNAPSHOT/HelloWorldWebServiceExperiment-1.0-SNAPSHOT.war
[INFO] Installing ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT-wsclient.jar to ~/.m2/repository/training/webservice/HelloWorldWebServiceExperiment/1.0-SNAPSHOT/HelloWorldWebServiceExperiment-1.0-SNAPSHOT-wsclient.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Aug 25 09:31:20 CEST 2015
[INFO] Final Memory: 32M/487M
[INFO] ------------------------------------------------------------------------

EDIT (for precision): When I try use the stub archive in another project to create a webclient, (i do this with intellij idea), idea automatically finds the file from my maven repository and suggests it to me, generating the following dependency:

 <dependency>
        <groupId>training.webservice</groupId>
        <artifactId>HelloWorldWebServiceExperiment</artifactId>
        <version>1.0-SNAPSHOT-wsclient</version>
 </dependency>

however none of the genereated .java files can actually be imported and used in code! E.g. idea fails on usage or import

import training.webservice.HelloWorld;

private training.webservice.HelloWorld helloWorld;

with the error message "Cannot resolve symbol 'HelloWorld'" What am I doing wrong? Is this connected to the fact that my stub only contains .java files, but no .class files? Obviously the plugin jaxws-maven-plugin runs wsimport with the -xnocompile flag, but I haven't been able to figure out how to configure maven not to do that, none of the options keep, destDir or sourceDestDir have had any effect on that! Or is this completely irrelevant, as the project importing the stubs should be able to compile them itself and the problem is somewhere else? Any help would be greatly appreciated!

1

1 Answers

0
votes

I found a temporary work arround: I generate a client stub .jar file manually. As my company still works with Java 1.5, I had to install metro in order to use wsimport (I chose version 1.6.2) and then I could call:

wsimport target/generated-sources/wsdl/HelloWorldWebServiceExperiment.wsdl -d target/generated-sources/wsdl/ -keep

afterwards I had .java and .class files which I could manually package into a .jar file, then I moved that .jar into the ressource folder of my webservice client project and manually added the dependency into my pom.xml:

        <dependency>
            <groupId>training.webservice</groupId>
            <artifactId>HelloWorldWebServiceExperiment</artifactId>
            <version>1.0</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/src/main/resources/client.jar</systemPath>
    </dependency>

I would prefer an automatic build and deploy from maven, and I am now sure that the problem must lie within my maven setup, however I have still no clue how to do it any better. At least I can continue working on the webservice client for now, and revisit the issue at a later point again!