thomas908
asked on
Simple Web Service using Axis
i am trying to make a simple web service using axis on tomcat 5
Here the Calculator.jws file
public class Calculator {
public int add(int i1, int i2)
{
return i1 + i2;
}
public int subtract(int i1, int i2)
{
return i1 - i2;
}
}
Here is CalcClient.java client file
package com;
import org.apache.axis.client.Cal l;
import org.apache.axis.client.Ser vice;
import org.apache.axis.encoding.X MLType;
import org.apache.axis.utils.Opti ons;
import javax.xml.rpc.ParameterMod e;
public class CalcClient
{
public static void main(String [] args) throws Exception {
Options options = new Options(args);
String endpoint = "http://localhost:" + options.getPort() +
"/axis/Calculator.jws";
args = options.getRemainingArgs() ;
if (args == null || args.length != 3) {
System.err.println("Usage: CalcClient <add|subtract> arg1 arg2");
return;
}
String method = args[0];
if (!(method.equals("add") || method.equals("subtract")) ) {
System.err.println("Usage: CalcClient <add|subtract> arg1 arg2");
return;
}
Integer i1 = new Integer(args[1]);
Integer i2 = new Integer(args[2]);
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddr ess( new java.net.URL(endpoint) );
call.setOperationName( method );
call.addParameter( "op1", XMLType.XSD_INT, ParameterMode.IN );
call.addParameter( "op2", XMLType.XSD_INT, ParameterMode.IN );
call.setReturnType( XMLType.XSD_INT );
Integer ret = (Integer) call.invoke( new Object [] { i1, i2 });
System.out.println("Got result : " + ret);
}
}
It compile fine but when i run it , i get the following error
C:\>java com.CalcClient -p8080 add 3 4
Exception in thread "main" AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.lang.NullPointerExcep tion
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace: java.lang.NullPointerExcep tion
at java.util.Hashtable.put(Un known Source)
at com.sun.org.apache.xerces. internal.j axp.SAXPar serImpl.se tProperty( Unk
nown Source)
at org.apache.axis.encoding.D eserializa tionContex tImpl.pars e(Deserial iza
tionContextImpl.java:246)
at org.apache.axis.SOAPPart.g etAsSOAPEn velope(SOA PPart.java :538)
at org.apache.axis.Message.ge tSOAPEnvel ope(Messag e.java:376 )
at org.apache.axis.client.Cal l.invokeEn gine(Call. java:2583)
at org.apache.axis.client.Cal l.invoke(C all.java:2 553)
at org.apache.axis.client.Cal l.invoke(C all.java:2 248)
at org.apache.axis.client.Cal l.invoke(C all.java:2 171)
at org.apache.axis.client.Cal l.invoke(C all.java:1 691)
at com.CalcClient.main(CalcCl ient.java: 42)
java.lang.NullPointerExcep tion
at org.apache.axis.AxisFault. makeFault( AxisFault. java:129)
at org.apache.axis.client.Cal l.invoke(C all.java:2 251)
at org.apache.axis.client.Cal l.invoke(C all.java:2 171)
at org.apache.axis.client.Cal l.invoke(C all.java:1 691)
at com.CalcClient.main(CalcCl ient.java: 42)
Caused by: java.lang.NullPointerExcep tion
at java.util.Hashtable.put(Un known Source)
at com.sun.org.apache.xerces. internal.j axp.SAXPar serImpl.se tProperty( Unk
nown Source)
at org.apache.axis.encoding.D eserializa tionContex tImpl.pars e(Deserial iza
tionContextImpl.java:246)
at org.apache.axis.SOAPPart.g etAsSOAPEn velope(SOA PPart.java :538)
at org.apache.axis.Message.ge tSOAPEnvel ope(Messag e.java:376 )
at org.apache.axis.client.Cal l.invokeEn gine(Call. java:2583)
at org.apache.axis.client.Cal l.invoke(C all.java:2 553)
at org.apache.axis.client.Cal l.invoke(C all.java:2 248)
... 3 more
Please help me resolve this
Here the Calculator.jws file
public class Calculator {
public int add(int i1, int i2)
{
return i1 + i2;
}
public int subtract(int i1, int i2)
{
return i1 - i2;
}
}
Here is CalcClient.java client file
package com;
import org.apache.axis.client.Cal
import org.apache.axis.client.Ser
import org.apache.axis.encoding.X
import org.apache.axis.utils.Opti
import javax.xml.rpc.ParameterMod
public class CalcClient
{
public static void main(String [] args) throws Exception {
Options options = new Options(args);
String endpoint = "http://localhost:" + options.getPort() +
"/axis/Calculator.jws";
args = options.getRemainingArgs()
if (args == null || args.length != 3) {
System.err.println("Usage:
return;
}
String method = args[0];
if (!(method.equals("add") || method.equals("subtract"))
System.err.println("Usage:
return;
}
Integer i1 = new Integer(args[1]);
Integer i2 = new Integer(args[2]);
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddr
call.setOperationName( method );
call.addParameter( "op1", XMLType.XSD_INT, ParameterMode.IN );
call.addParameter( "op2", XMLType.XSD_INT, ParameterMode.IN );
call.setReturnType( XMLType.XSD_INT );
Integer ret = (Integer) call.invoke( new Object [] { i1, i2 });
System.out.println("Got result : " + ret);
}
}
It compile fine but when i run it , i get the following error
C:\>java com.CalcClient -p8080 add 3 4
Exception in thread "main" AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.lang.NullPointerExcep
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace: java.lang.NullPointerExcep
at java.util.Hashtable.put(Un
at com.sun.org.apache.xerces.
nown Source)
at org.apache.axis.encoding.D
tionContextImpl.java:246)
at org.apache.axis.SOAPPart.g
at org.apache.axis.Message.ge
at org.apache.axis.client.Cal
at org.apache.axis.client.Cal
at org.apache.axis.client.Cal
at org.apache.axis.client.Cal
at org.apache.axis.client.Cal
at com.CalcClient.main(CalcCl
java.lang.NullPointerExcep
at org.apache.axis.AxisFault.
at org.apache.axis.client.Cal
at org.apache.axis.client.Cal
at org.apache.axis.client.Cal
at com.CalcClient.main(CalcCl
Caused by: java.lang.NullPointerExcep
at java.util.Hashtable.put(Un
at com.sun.org.apache.xerces.
nown Source)
at org.apache.axis.encoding.D
tionContextImpl.java:246)
at org.apache.axis.SOAPPart.g
at org.apache.axis.Message.ge
at org.apache.axis.client.Cal
at org.apache.axis.client.Cal
at org.apache.axis.client.Cal
... 3 more
Please help me resolve this
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot for helping
You are welcome :-)
java com.CalcClient add 3 4
Seams like your code only accept 3 command arguments.