0

I have a EJB project (to run In Websphere), which is also a WebService client. Previously, we created the client classes manually, using the wsimport command. Now we want to automate the process using the JAX-WS Maven Plugin, goal jaxws:wsimport .

The generation is almost perfect except for a fact: the webservice classes (with the annotation @WebService) should have also the @Stateless annotation. Without this, Eclipse complains that @WebService annotation in EJB modules can be only used on stateless session beans. Actually, the prior versions of these classes (presumably created using manually wsimport), had the @Stateless annotation.

I suppose that it should have some configuration telling to wsimport to generate the classes as Stateless. However, I did not find it neither in wsimport documentation nor in the Maven Plugin one.

Below I show my POM configuration:

<properties>
    <wsdl.dirs>${basedir}/src/main/resources/META-INF</wsdl.dirs>
    <wsdl.package.basic>com.porto.sinistro.orcamentomultiempresa</wsdl.package.basic>
</properties>

<plugin>
    <groupId>org.jvnet.jax-ws-commons</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.3</version>
    <executions>

        <!--
        Other executions, using other WSDL files.
        -->

        <execution>
            <id>wsdl-cartaAutorizacao-exec</id>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <packageName>${wsdl.package.basic}.upload.cartaAutorizacao.client</packageName>
                <wsdlFiles>
                    <wsdlFile>${wsdl.dirs}/CartaAutorizacaoWSService.wsdl</wsdlFile>
                </wsdlFiles>
                <wsdlLocation>META-INF/CartaAutorizacaoWSService.wsdl</wsdlLocation>
            </configuration>
        </execution> 

    </executions>

    <configuration> 
        <bindingDirectory>${basedir}/src/main/java</bindingDirectory>
        <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
        <verbose>true</verbose>
        <target>2.0</target>
        <xnocompile>true</xnocompile>
    </configuration>

    </plugin>
</plugins>

For the WSDL mentioned above, the Webservice class has this form:

@WebService(name = "CartaAutorizacaoWS", targetNamespace = "http://client.ws.soma.upload.sinistro.porto.com/cartaautorizacao")
// Where is the @Stateless?
public interface CartaAutorizacaoWS {
    // ...
}

Which configuration should I do to generate @Stateless WebServices?

Thanks,

Rafael Afonso

Rafael Afonso
  • 595
  • 1
  • 10
  • 28

1 Answers1

0

I found my solution using ANT.

My POM file was changed to:

<plugin>
    <groupId>org.jvnet.jax-ws-commons</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <version>2.3</version>
    <executions>

        <!--
        Other executions, using other WSDL files.
        -->

        <execution>
            <id>wsdl-cartaAutorizacao-exec</id>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <packageName>${wsdl.package.basic}.upload.cartaAutorizacao.client</packageName>
                <wsdlFiles>
                    <wsdlFile>${wsdl.dirs}/CartaAutorizacaoWSService.wsdl</wsdlFile>
                </wsdlFiles>
                <wsdlLocation>META-INF/CartaAutorizacaoWSService.wsdl</wsdlLocation>
            </configuration>
        </execution> 

    </executions>

    <configuration> 
        <bindingDirectory>${basedir}/src/main/java</bindingDirectory>
        <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
        <verbose>true</verbose>
        <target>2.0</target>
        <xnocompile>true</xnocompile>
    </configuration>

    </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution> <!-- Eclipse error message. See below. -->
                    <id>inject-stateless</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <ant antfile="${basedir}/inject-stateless.xml" target="main" />
                        </tasks>
                    </configuration>
                </execution>
            </executions>
        </plugin>

</plugins>

My ANT Script:

<?xml version="1.0"?>
<project default="main" basedir=".">
    <property name="base.source.dir" value="./src/main/java/com/porto/sinistro/orcamentomultiempresa"/>

    <target name="main" >
        <antcall target="replace">
            <param name="file.path" value="client/controlevagas/ControleVagasWeb.java"/>
        </antcall>
        <antcall target="replace">
            <param name="file.path" value="client/somavistoriaweb/VistoriaWeb.java"/>
        </antcall>
        <!-- Other java files ... -->
    </target>

    <target name="replace">
        <property name="java.file" location="${base.source.dir}/${file.path}"/>
        <echo message="Ajustando classe ${java.file}"/>
        <replace file="${java.file}">
            <replacetoken><![CDATA[import javax.jws.WebMethod;]]></replacetoken>
            <replacevalue><![CDATA[import javax.ejb.Stateless;
import javax.jws.WebMethod;]]></replacevalue>
        </replace>
        <replace file="${java.file}">
            <replacetoken><![CDATA[public interface]]></replacetoken>
            <replacevalue><![CDATA[@Stateless
public interface]]></replacevalue>
        </replace>
    </target>

</project>

Although my Eclipse shows a error message Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-antrun-plugin:1.8:run (execution: inject-stateless, phase: generate-sources), I discovered that it had no effect on Maven execution. See my post Maven (m2e) is not executing ant task .

Community
  • 1
  • 1
Rafael Afonso
  • 595
  • 1
  • 10
  • 28