Link to home
Start Free TrialLog in
Avatar of thomas908
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.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;
import javax.xml.rpc.ParameterMode;

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.setTargetEndpointAddress( 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.NullPointerException
 faultActor:
 faultNode:
 faultDetail:
        {http://xml.apache.org/axis/}stackTrace: java.lang.NullPointerException
        at java.util.Hashtable.put(Unknown Source)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.setProperty(Unk
nown Source)
        at org.apache.axis.encoding.DeserializationContextImpl.parse(Deserializa
tionContextImpl.java:246)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:538)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:376)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2583)
        at org.apache.axis.client.Call.invoke(Call.java:2553)
        at org.apache.axis.client.Call.invoke(Call.java:2248)
        at org.apache.axis.client.Call.invoke(Call.java:2171)
        at org.apache.axis.client.Call.invoke(Call.java:1691)
        at com.CalcClient.main(CalcClient.java:42)


java.lang.NullPointerException
        at org.apache.axis.AxisFault.makeFault(AxisFault.java:129)
        at org.apache.axis.client.Call.invoke(Call.java:2251)
        at org.apache.axis.client.Call.invoke(Call.java:2171)
        at org.apache.axis.client.Call.invoke(Call.java:1691)
        at com.CalcClient.main(CalcClient.java:42)
Caused by: java.lang.NullPointerException
        at java.util.Hashtable.put(Unknown Source)
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.setProperty(Unk
nown Source)
        at org.apache.axis.encoding.DeserializationContextImpl.parse(Deserializa
tionContextImpl.java:246)
        at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:538)
        at org.apache.axis.Message.getSOAPEnvelope(Message.java:376)
        at org.apache.axis.client.Call.invokeEngine(Call.java:2583)
        at org.apache.axis.client.Call.invoke(Call.java:2553)
        at org.apache.axis.client.Call.invoke(Call.java:2248)
        ... 3 more


Please help me resolve this

Avatar of limaideal
limaideal

Have u tried remove -p8080 from command line?

java com.CalcClient add 3 4

Seams like your code only accept 3 command arguments.
ASKER CERTIFIED SOLUTION
Avatar of aozarov
aozarov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thomas908

ASKER

Thanks a lot for helping
You are welcome :-)