The Kat's Work - Blog
Main | Blog | Registration | Login
4:27 PM
Welcome Guest | RSS
Main » 2011 » March » 30

Following on from my guide to Web service in Lotus Notes, I will now discuss the ins and outs of consuming them in java. Specfically Java spring and Jax-WS.

First off a few pre-cursors in this guide I will not explain wsdl in any great detail so for some background please read the excellent guides from w3c. Also the eclipse plugin "SoapUI” is amazingly useful for working with webservices.

The JAX-WS classes are bundled in with the springframework so no need to go find them.

Firstly lets set up a very basic consumer service.

In your applicationContext-servlet.xml you’ll need to set up your JAX-WS bean. As below.

<bean id="TestNotesService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
        <property name="wsdlDocumentUrl"  value="http://<url>/TestService?wsdl" />
        <property name="namespaceUri"     value="urn:DefaultNamespace" />
        <property name="serviceName"      value="Test" />
        <property name="portName"         value="domino" />
        <property name="serviceInterface" value="testweb.webservice.TestService" />

As can be seen its very basic functionality. The wsdl url, default namespace, service and port names as specified in the wsdl. The only thing "java” is the definition of a service Interface.

The service interface is what it says on the tin. It is an interface in which we are telling java how to deal with the services methods.

package testweb.webservice;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.ParameterStyle;

@WebService(name = "Test",
        targetNamespace = "urn:DefaultNamespace")
public interface TestService {
    @WebMethod(operationName = "SAYHELLO",
            action = "http://<url>/TestService")
            public String SayHello();
    @WebMethod(operationName = "SAYMESSAGE",
            action = "http://<url>/TestService")
            public String SayMessage(@WebParam(name = "MESSAGE",
                    targetNamespace = "urn:DefaultNamespace")String message);   


The sample above shows the setup for simple calls to simple methods of the webservice.

·    @WebService annotataion sets simple information about the service.
·    @SOAPBinding annotation sets the parameter style of the service. In simple methods such as those above where the most being passed in the soap message is a simple string. Than use Bare.
·    @WebMethod() annotation assigns the webservice method and url.
·    @WebParam() annotation specifies a parameter to be sent to the webservice.

So in this example we have a webservice called test. It has at least two methods (SAYHELLO and SAYMESSAGE). SAYHELLO is a very basic method that is called and returns a string. SAYMESSAGE accepts a single parameter and returns a single string.


public class TestController {

    @Autowired private transient TestService testService;

    public void sayHello (HttpServletRequest request, HttpServletResponse response){
try {
            if(testService!=null) {
                monthStr = testService.SayHello();
} catch (Exception e) {

As you can see after the work to set it up the usage is simple. You may also notice we never set up a class for TestService, we don’t have to JAX-WS has done it for us.

Next up consuming complex webservices. Including creation of xml wrappers for soap messages. Exciting!!!

Views: 14173 | Added by: The_Kat | Date: 2011-03-30

Login form
«  March 2011  »
Entries archive
Site friends
  • Create your own site
  • My Blog
  • Statistics

    Total online: 1
    Guests: 1
    Users: 0
    Copyright MyCorp © 2020
    Website builderuCoz