[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 452
  • Last Modified:

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

0
thomas908
Asked:
thomas908
  • 2
1 Solution
 
limaidealCommented:
Have u tried remove -p8080 from command line?

java com.CalcClient add 3 4

Seams like your code only accept 3 command arguments.
0
 
aozarovCommented:
I think you will find a solution to your problem here: http://www.evolutionnext.com/blog/2005/01/10.html
(basically it suggests that Axis has issue with Java 1.5 and you should use Java 1.4.2 instead
or upgrade your axis to > 1.2 RC 2 [and don't forget to replace that version on the tomcat side on tomcat
in the common/lib directory]
0
 
thomas908Author Commented:
Thanks a lot for helping
0
 
aozarovCommented:
You are welcome :-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now