OK. Is it me? I know I'm 1) not understanding Axis2's API and therefore 2)
not using it correctly.
For the past three weeks I have been unable to get anything but the simplist
web service to work. By simplest I mean a web service that passes and returns
only primitives (i.e. int, float, String, etc....). I have been following the
examples I found on the web (bottom-up web services with Axis2) and on the
Apache Axis2 web site ( bottom-up development web services with Axis2 and
POJO's). Here is some of what I've tried. Can anyone tell me what I'm missing?
Bottom-Up Web Service Using Java Objects As Parameters And/Or Return Values
public class WSDataOnlyObj
{
public String str = "This is a data only object";
public int num = 1;
}
public class WS
{
private String str;
private WSDataOnlyObj objDataOnly;
public String GetString( )
{
str = "This is a string";
return str;
}
public WSDataOnlyObj GetDataOnlyObj( )
{
objDataOnly = new WSDataOnlyObj( );
return objDataOnly;
}
}
CLIENT CODE
-----------
import java.rmi.RemoteException;
import org.apache.axis2.AxisFault;
public class WSClient
{
public static void main(String[] args)
{
try
{
WSStub.GetStringResponse getStringResp;
WSStub.GetDataOnlyObjResponse getDOObjResp;
WSStub stub = new
WSStub("http://localhost:8080/Webservice/services/WS/ws/pojo/service");
getStringResp = stub.GetString();
getDOObjResp = stub.GetDataOnlyObj();
System.out.println("RESULT Of Call To Web Service GetSting(): " +
getStringResp.get_return());
System.out.println("RESULT Of Call To Web Service GetDataOnlyObj().getStr():
" +
getDOObjResp.get_return().getStr());
System.out.println("RESULT Of Call To Web Service GetDataOnlyObj().getNum():
" +
getDOObjResp.get_return().getNum());
}
catch(AxisFault axisEx)
{
System.out.println(axisEx.getMessage());
}
catch(RemoteException remEx)
{
System.out.println(remEx.getMessage());
}
}
}
RESULTS
-------
RESULT Of Call To Web Service GetSting(): This is a string
RESULT Of Call To Web Service GetDataOnlyObj().getStr(): null
RESULT Of Call To Web Service GetDataOnlyObj().getNum(): -2147483648
You see!!!! Getting the String return value works fine with this method but
not getting the object return value.
Now let's look at trying the POJO example given in the Axis2 documentation.
Bottom-Up Web Service Using Java Objects As Parameters And/Or Return Values -
POJO Client Example
public class WSDataOnlyObj
{
private String str = "This is a data only object";
public String GetString( )
{
return str;
}
public void SetString(String aStr)
{
str = aStr;
}
}
public class WS
{
public WSDataOnlyObj GetDataOnlyObj( )
{
WSDataOnlyObj objDataOnly = new WSDataOnlyObj( );
return objDataOnly;
}
}
import javax.xml.namespace.QName;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class WSTestClientApp
{
public static void main(String[] args)
{
try
{
RPCServiceClient serviceClient = new RPCServiceClient( );
Options options = serviceClient.getOptions( );
EndpointReference epr = new
EndpointReference("http://localhost:8080/WSTest/services/WS");
options.setTo(epr);
Object[ ] opWSDataOnlyObjArgs = new Object [ ] { };
Class [ ] returnTypes = new Class [ ] {WSDataOnlyObj.class};
.....
}
catch(AxisFault axisEx)
{
System.out.println(axisEx.getMessage());
}
catch(RemoteException remEx)
{
System.out.println(remEx.getMessage());
}
}
}
Here's my problem with this example, this code (adapted from the "weather"
example) requires an import of the package containing the WSDataOnlyObj. You
can make this work for this example but unless I'm wrong the client should get
all objects from the stub and should not have to access the development package
of the web service object!!!!!
These appear to be some serious problems with the Axis2 API.
Can anyone explain what I might be missing?
Thanks