Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

Although Netbeans has extensive support for integrating webservices into Java applications the support for RPC based webservices (and RPC/encoded webservices specifically) is limited.

This is why we've chosen to use Apache Axis to access an RPC/encoded webservice.

Required libraries

Generating client side classes

Axis provides a tool to generate all the required classes based on a WSDL file.

term
java -Djava.ext.dirs={path-to-axis-libdir}
        org.apache.axis.wsdl.WSDL2Java 
        -o {src-dir}
        -p {package}
           {wsdl-location}

Parameter

Value

{path-to-axis-libdir}

Path to a directory containing all the libs listed above

-o {src-dir}

Path to the directory where the source files should be placed (i.e.: src)

-p {package}

The package in which the generated classes should be placed (i.e.: com.example.ws.client)

{wsdl-location}

The location of the WSDL file, this can be either an URL, or a local file

Based on information in de WSDL file classes will be generated to support complex parameters, results, and provide a way to access the service.

Using maven to generate and compile java sources from wsdl

Code Block
titlepom.xml
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>axistools-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>ax-ws-autogen</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                        <configuration>
                            <sourceDirectory>src/main/wsdl</sourceDirectory>
                            <wsdlFiles>
                                <wsdlFile>sugarcrm.wsdl</wsdlFile>
                            </wsdlFiles>
                            <packageSpace>com.initworks.tripolis.generated.sugarcrm</packageSpace>
                            <testCases>false</testCases>
                            <serverSide>false</serverSide>
                            <subPackageByFileName>false</subPackageByFileName>
                            <outputDirectory>target/generated-sources/axis</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>add-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>target/generated-sources/axis</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Using the generated client

The webservice can now be accessed using the Locator class generated by the WSDL2Java utility.
In the example client below the WSDL identified the service as 'ExampleWebservice', which has been used to create a ExampleWebserviceLocator class.

Code Block
titleExampleWebserviceClient.java
typejava
public String doWebserviceCall(){
    //initiate the locator
    ExampleWebserviceLocator webservice = new ExampleWebserviceLocator();
    //retrieve a port to call a method on
    ExampleWebservicePortType port = webservice.getExampleWebservicePort();
    //call the doStuff method on the webservice, which should return a String
    return port.doStuff("param");
}

By default the get...Port() method connects to the webservice at the location specified in the WSDL file.
It is also possible to specify a specific URL to connect to, which can be useful in case of fail-over when the default server is unavailable.

Sources