Hi All,

Im Thiyagu, a junior software developer(Java/J2ee). I have assigned to access Webservice (sending request and receiving response from a WSDL). can any tell me the steps involved to convert Java code from a WSDL file using Axis(with ant build script).
please very urgent.

Note : I already tried with Aixs and generated Java code from WSDL , but I got some error while sending request, i.e

Exception in thread "main" AxisFault
faultCode: {
faultSubcode:
faultString: Server was unable to process request. ---> Object reference not set to an instance of an object.
faultActor:
faultNode:
faultDetail:
{ AxisFault
faultCode: {
faultSubcode:
faultString: Server was unable to process request. ---> Object reference not set to an instance of an object.
faultActor:
faultNode:
faultDetail:
Server was unable to process request. ---> Object reference not set to an instance of an object.

Thank,
Thiyagu.

Dani AI

Generated

Short summary and cause

The Axis-generated stubs/Ant approach that described is fine; the AxisFault shown in the first post — “Server was unable to process request. Object reference not set to an instance of an object.” — is a server-side NullReferenceException (not an Axis client bug) and typically means the server expected a value (often a SOAP header) that it did not receive. (learn.microsoft.com)

Recommended debug / fix workflow

  1. Regenerate stubs with wsdl2java (or the Ant task @ksaxena suggested) and inspect the generated signatures. If the WSDL declares an explicit header, Axis may generate stub methods that include the header; otherwise the header must be added manually. 2) Compile/run the client with the same Axis libraries used at generation time. 3) If a header is required, attach it to the generated stub (or Call) before invoking the operation. (axis.apache.org)

Small, practical Axis 1.x example

// locator and stub are the classes wsdl2java produced
FooServiceLocator loc = new FooServiceLocator();
FooPortBindingStub stub = (FooPortBindingStub) loc.getFooPort();

// simple header API (namespace, partName, value)
((org.apache.axis.client.Stub)stub).setHeader("urn:AuthNS", "AuthToken", "my-token");

// or build a SOAPHeaderElement for mustUnderstand / richer XML
org.apache.axis.message.SOAPHeaderElement hdr =
    new org.apache.axis.message.SOAPHeaderElement(new javax.xml.namespace.QName("urn:AuthNS","AuthToken"), "my-token");
hdr.setMustUnderstand(true);
((org.apache.axis.client.Stub)stub).setHeader(hdr);

MyResponse r = stub.someOperation(...);

The stub supports both the simple setHeader(namespace, partName, value) and the setHeader(SOAPHeaderElement) forms. (axis.apache.org)

Inspecting the wire and extra tips

Run Axis tcpmon (the Axis TCP monitor) and point the client to tcpmon’s listen port so you can see the raw request/response and confirm the header, namespaces, SOAPAction and SOAP version (1.1 vs 1.2). Example invocation is available in the Axis docs. If the server still throws the NullReferenceException, check the server logs (it’s a server-side null) and verify SOAPAction / encoding settings on the client (Call can set soapAction and encoding if needed). (svn.apache.org)

Notes: confirm the header element name and namespace exactly match the WSDL/binding, and set mustUnderstand if the WSDL/handler requires it.

Recommended Answers

All 5 Replies

Two things you need to define in your ant properties or build.xml file:
1. Define typeDef for your WSDL to Java utility so as to use in ant target

<typedef name="wsdl2java" classname="org.apache.axis.tools.ant.wsdl.Wsdl2javaAntTask" classpathref="axisclasspath"/>

2. Within your desired target say

<wsdl2java verbose="true" output="${yourOutputDir}/wsdl" url="${wsdlFileName}.wsdl" deployScope="Session">
	<mapping package="${package}" namespace="urn:${service.name}"/>
</wsdl2java>

Make sure you have mentioned axisclasspath using <path id="axisclasspath">....</path>, which is required by step 1, this is the classpath which ant will internally use to compile WSDL to generate stubs and impl files, so make sure you have mentioned all necessary Axis jars in it.

Hope this will help.

no, it is NOT urgent.

The thing to do is to read the documentation, which explains it all in detail.
The steps for using ANT to retrieve the WSDL and generate your classes has already been outlined above though not every option you could use mentioned, use the manual to find out about those.

Two things you need to define in your ant properties or build.xml file:
1. Define typeDef for your WSDL to Java utility so as to use in ant target

<typedef name="wsdl2java" classname="org.apache.axis.tools.ant.wsdl.Wsdl2javaAntTask" classpathref="axisclasspath"/>

2. Within your desired target say

<wsdl2java verbose="true" output="${yourOutputDir}/wsdl" url="${wsdlFileName}.wsdl" deployScope="Session">
    <mapping package="${package}" namespace="urn:${service.name}"/>
</wsdl2java>

Make sure you have mentioned axisclasspath using <path id="axisclasspath">....</path>, which is required by step 1, this is the classpath which ant will internally use to compile WSDL to generate stubs and impl files, so make sure you have mentioned all necessary Axis jars in it.

Hope this will help.

Dear ksaxena,

Thank you very much for your kind information. The problem I faced was, the Webservice need the Client to send SOAPHeader along with request. I tried it to set SOAPHeaderElement before I invoking service using setHeader(SOAPHeaderElemet). Its working fine now , and I can send and receive response well.

Thanks,
Thiyagu.

no, it is NOT urgent.

The thing to do is to read the documentation, which explains it all in detail.
The steps for using ANT to retrieve the WSDL and generate your classes has already been outlined above though not every option you could use mentioned, use the manual to find out about those.

Dear jwenting,

Thank you very much for your kind information. The problem I faced was, the Webservice need the Client to send SOAPHeader along with request. I tried it to set SOAPHeaderElement before I invoking service using setHeader(SOAPHeaderElemet). Its working fine now , and I can send and receive response well.

Thanks,
Thiyagu.

Hi Thiyagu.,

It seems header part is missing from your request.
To make it sure you can use TCP Monitor to see
what is exact request xml you are creating from your end.

Regards
Mudassar

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.