Creating a Webservice-Client using the “maven-jaxws-tools-plugin”

Creating a Webservice-Client using the JBoss Maven Plugin is pretty straight forward.
Create a new Maven Project and make sure the pom.xml looks like this and the JBoss Maven Repository (including snaphshots) is added in your settings.xml.

    <groupId>de.test.mytests</groupId>
    <artifactId>ws-client</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.jboss.jbossas</groupId>
            <artifactId>jboss-as-client</artifactId>
            <type>pom</type>
            <version>5.1.0.GA</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.ws.native</groupId>
            <artifactId>jbossws-native-client</artifactId>
            <version>3.3.0.Beta4</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.2</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.jboss.ws.plugins</groupId>
                <artifactId>maven-jaxws-tools-plugin</artifactId>
                <version>1.0.0.GA</version>
                <configuration>
                    <wsdls>
                        <wsdl>http://*host*:*port*/*path*/WebServiceName?wsdl</wsdl>
                    </wsdls>
                    <targetPackage>de.test.generated.classes</targetPackage>
                    <sourceDirectory>src/main/java</sourceDirectory>
                    <extension>true</extension>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>wsconsume</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

The path in the <wsdl></wsdl> Tag should point to an actual existing/vaild WSDL location. In the src/resources/META-INF Folder add standard-jaxws-client-config.xml, wich should have the following entries:

<jaxws-config xmlns="urn:jboss:jaxws-config:2.0"
		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		xmlns:javaee="http://java.sun.com/xml/ns/javaee"
              	xsi:schemaLocation="urn:jboss:jaxws-config:2.0 jaxws-config_2_0.xsd">

   <client-config>
      <config-name>Standard WSSecurity Client</config-name>
      <post-handler-chains>
         <javaee:handler-chain>
            <javaee:protocol-bindings>##SOAP11_HTTP</javaee:protocol-bindings>
            <javaee:handler>
               <javaee:handler-name>WSSecurityHandlerOutbound</javaee:handler-name>
               <javaee:handler-class>
		org.jboss.ws.extensions.security.jaxws.WSSecurityHandlerClient
		</javaee:handler-class>
            </javaee:handler>
         </javaee:handler-chain>
      </post-handler-chains>
   </client-config>

</jaxws-config>

The goal “wsconsume” will create all necessary Proxy- and DTO-Classes
to use the Webservice in the folder src/main/java. Check that there is a “xyzService.java” Class in the specified target package. Create a new instance of this Class and invoke desired methods. Assuming the Webservicename was HelloService, you can then invoke a method like the “sayHello”-Method of the HelloWebservice like this:


package de.test.main;

import de.test.generated.classes.HelloService;

public class CallWebservice {
  
  public static void main(String[] args) {    
    HelloService service = new HelloService();
    service.getHelloPort().sayHello();
          
  }
Advertisements

About javacodeblog

J2EE Developer
This entry was posted in Webservice Client and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s