2 Replies Latest reply on Feb 14, 2005 6:22 PM by Thomas Diesler

    Accessing web service from standalone Java client

    guptah Newbie

      Hi,

      I am trying to access a web service using standalone Java client and I get below mentioned exception. The same service works from a JSP page.

      AxisFault
      faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Client
      faultSubcode:
      faultString: java.lang.NullPointerException
      faultActor:
      faultNode:
      faultDetail:
      {http://xml.apache.org/axis/}stackTrace: java.lang.NullPointerException
      at java.util.Hashtable.put(Hashtable.java:396)
      at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:395)
      at org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:263)
      at org.apache.axis.MessagePart.getAsSOAPEnvelope(MessagePart.java:657)
      at org.apache.axis.Message.getSOAPEnvelope(Message.java:430)
      at org.apache.axis.Message.getContentType(Message.java:496)
      at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:386)
      at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:126)
      at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:73)
      at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:160)
      at org.apache.axis.SimpleChain.invoke(SimpleChain.java:123)
      at org.jboss.webservice.client.ClientEngine.invoke(ClientEngine.java:126)
      at org.apache.axis.client.Call.invokeEngine(Call.java:3029)
      at org.apache.axis.client.Call.invoke(Call.java:3014)
      at org.apache.axis.client.Call.invoke(Call.java:2608)
      at org.apache.axis.client.Call.invoke(Call.java:2513)
      at org.apache.axis.client.Call.invokeInternal(Call.java:1973)
      at org.apache.axis.client.Call.invoke(Call.java:1914)
      at org.jboss.webservice.client.CallImpl.invoke(CallImpl.java:265)
      at client.CPRWebServiceClient.main(CPRWebServiceClient.java:66)


      org.apache.axis.AxisFault: java.lang.NullPointerException
      at org.apache.axis.AxisFault.makeFault(AxisFault.java:146)
      at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:136)
      at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:73)
      at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:160)
      at org.apache.axis.SimpleChain.invoke(SimpleChain.java:123)
      at org.jboss.webservice.client.ClientEngine.invoke(ClientEngine.java:126)
      at org.apache.axis.client.Call.invokeEngine(Call.java:3029)
      at org.apache.axis.client.Call.invoke(Call.java:3014)
      at org.apache.axis.client.Call.invoke(Call.java:2608)
      at org.apache.axis.client.Call.invoke(Call.java:2513)
      at org.apache.axis.client.Call.invokeInternal(Call.java:1973)
      at org.apache.axis.client.Call.invoke(Call.java:1914)
      at org.jboss.webservice.client.CallImpl.invoke(CallImpl.java:265)
      at client.CPRWebServiceClient.main(CPRWebServiceClient.java:66)
      Caused by: java.lang.NullPointerException
      at java.util.Hashtable.put(Hashtable.java:396)
      at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:395)
      at org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:263)
      at org.apache.axis.MessagePart.getAsSOAPEnvelope(MessagePart.java:657)
      at org.apache.axis.Message.getSOAPEnvelope(Message.java:430)
      at org.apache.axis.Message.getContentType(Message.java:496)
      at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:386)
      at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:126)

      Any help is appreciated.

      Thanks,
      Himanshu

        • 1. Re: Accessing web service from standalone Java client
          guptah Newbie

          Here is the client class code.

          package client;

          import javax.xml.rpc.Service;
          import javax.xml.rpc.JAXRPCException;
          import javax.xml.namespace.QName;
          import javax.xml.rpc.Call;
          import javax.xml.rpc.ServiceFactory;
          import javax.xml.rpc.ParameterMode;

          public class CPRWebServiceClient {


          private static String qnameService = "CPRWebServices";
          private static String qnamePort = "CPRWSIF";

          private static String BODY_NAMESPACE_VALUE =
          "urn:foo";
          private static String ENCODING_STYLE_PROPERTY =
          "javax.xml.rpc.encodingstyle.namespace.uri";
          private static String NS_XSD =
          "http://www.w3.org/2001/XMLSchema";
          private static String URI_ENCODING =
          "http://schemas.xmlsoap.org/soap/encoding/";

          public static void main(String[] args) {

          String endpointAddress = "http://gupta:8080/cprwebservices/cprws";

          try {
          ServiceFactory factory = ServiceFactory.newInstance();
          Service service = factory.createService(new QName(qnameService));

          QName port = new QName(qnamePort);

          Call call = service.createCall(port);
          call.setTargetEndpointAddress(endpointAddress);

          call.setProperty(Call.SOAPACTION_USE_PROPERTY,
          new Boolean(true));
          call.setProperty(Call.SOAPACTION_URI_PROPERTY,
          "");
          call.setProperty(ENCODING_STYLE_PROPERTY,
          URI_ENCODING);
          QName QNAME_TYPE_STRING =
          new QName(NS_XSD, "string");
          call.setReturnType(QNAME_TYPE_STRING);

          call.setOperationName(
          new QName(BODY_NAMESPACE_VALUE,"sayHello"));
          call.addParameter("String_1", QNAME_TYPE_STRING,
          ParameterMode.IN);
          String[] params = { "Himanshu!" };

          String result = (String)call.invoke(params);
          System.out.println(result);

          } catch (Exception ex) {
          ex.printStackTrace();
          }
          }


          }

          • 2. Re: Accessing web service from standalone Java client
            Thomas Diesler Master

            Again, you need to provide a sample deployment in JIRA that allows me to reproduce what you are seeing? Ideally the client would be a Servlet, so that I only have to click on a link.

            http://jira.jboss.com/jira/browse/JBWS