In my Eclipse client I generated the web service stubs and proxy by creating a 
new project, then right clicking on the project selecting new->other->web 
service->web service client. When setting up the client I pointed it to my web 
service WSDL file ex:(http://localhost:8280/PSDynamicWebProject/TestWs?wsdl).  
I then just setup a simple test class to call the web service (code below):

package service.client;

import java.rmi.RemoteException;

import org.domain.PSDynamicWebProject.pojo.TestWs;
import org.domain.PSDynamicWebProject.pojo.TestWsProxy;

public class RunnerOld
{
    public static void main(String[] args)
    {
        TestWs tw = new TestWsProxy();
        try
        {
            System.out.println(tw.greet("1"));
        }
        catch (RemoteException e)
        {
            System.out.println(e.getMessage());
        }
    }
}

This code worked fine (called the web service and received the correct response 
back).  

Now I wanted to create the web service client using the annotations from 
JSR-181.  I looked a several different examples and the best that I can 
conclude is that I still need to generate the stubs and proxy files so I set 
them up in my project in the same way as I did above.  I then create a simple 
class to call my web service (code below):

package service.client;

import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import javax.xml.ws.WebServiceRef;
import org.domain.PSDynamicWebProject.pojo.TestWs;
import org.domain.PSDynamicWebProject.pojo.TestWsService;

public class Runner
{
@WebServiceRef(wsdlLocation="http://127.0.0.1:8280/PSDynamicWebProject/TestWs?wsdl";)
private static TestWsService service;

   public static void main(String[] args)
    {
        try
        {
            TestWs tw = service.getTestWsPort();
            System.out.println(tw.greet("1"));
        }
        catch (RemoteException e)
        {
            System.out.println(e.getMessage());
        }
        catch (ServiceException e)
        {
            System.out.println(e.getMessage());
        }
    }
}

This client however failed.  It got a java null pointer exception on this 
statement:  TestWs tw = service.getTestWsPort();  I debugged it and found tha 
the service object was null.

I have several questions regarding this approach:

1) I am curious why the service object was null and I got a null pointer 
exception?

2) Is this the correct way to setup and use the JSR-181?  I find it interesting 
that if we still must generate the stubs and prox from the WSDL before we can 
use the annotations then what advantage is there to using the annotations?

Any clarity and help would be greatly appreciated.  I can see the benefit in 
using JSR-181 to setup the web services from previous web services that I setup 
and the advantage of the annotations.  However, I don't see any benefits in the 
annotations on the client if I'm doing this correctly (which I may not be).

Here is the simple code from my web serivce for review (this works):

package org.domain.PSDynamicWebClient.pojo;

import java.io.StringWriter;
import java.util.Date;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.transform.stream.StreamResult;

import org.domain.PSDynamicWebClient.entity.Employee;
import org.domain.PSDynamicWebClient.session.SelectEmployee;
import org.jboss.seam.Component;


/**
 * This is a webservice class exposing a method called greet which takes a
 * input parameter and greets the parameter with hello.
 *
 * @author dhanago
 */

/*
 * @WebService indicates that this is webservice interface and the name
 * indicates the webservice name.
 */
@WebService(name = "TestWs", serviceName = "TestWsService")
/*
 * @SOAPBinding indicates binding information of soap messages. Here we have
 * document-literal style of webservice and the parameter style is wrapped.
 */
@SOAPBinding
   (
         style = SOAPBinding.Style.DOCUMENT,
         use = SOAPBinding.Use.LITERAL,
         parameterStyle = SOAPBinding.ParameterStyle.WRAPPED
    )    
public class TestWs
{
   @WebMethod
   public String greet( @WebParam(name = "emplid")
   String emplid )
   {
       try
       {
           
/**************************************************************************
            * The following example marshals an object class into an XML string 
which
            * is returned to the caller.  The object is an entity representing 
a 
            * row on the database.
            
**************************************************************************/
           // Query the database for an employee's information
           SelectEmployee selectEmployee =  (SelectEmployee) 
Component.getInstance("selectEmployee");
           selectEmployee.setId(emplid);
           Employee e = selectEmployee.getInstance();
           
           // Marshal the employee information into an xml string and return it
           JAXBContext context = JAXBContext.newInstance(Employee.class);    
           Marshaller marshaller = context.createMarshaller();    
           StreamResult result = new StreamResult( new StringWriter());
           marshaller.marshal(e, result);
           return result.getWriter().toString();           
       }
       catch (Exception e)
       {
           return e.getMessage();
       }
   }
}   


View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4149858#4149858

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4149858
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to