Client for Axis2 POJO webservice

I have a WSDL from which I generated the Java Axis2 code (contract first approach). Code was generated using eclipse. Once the skeleton code was generated I filled in the methods with my business logic.
I have craeted an .aar file and deployed this service on tomcat. I am able to see the service from
http://localhost:8080/axis2/services/listServices
and also able to view the wsdl from
http://localhost:8080/axis2/services/ResumeService?wsdl

Now I need to create the client code. I did so using Eclipse. Eclipse created "ResumeServiceCallbackHandler.java" and "ResumeServiceStub.java". Then I created the "ResumeClient" class and did the following

public class ResumeClient extends ResumeServiceCallbackHandler  {

      public void receiveResultgetResumeDetails(GetResumeDetailsResponse result) {
      }
   
      public void receiveResultgetResumeId(GetResumeIdResponse result) {
      }
      
      public static void main(String args[]) {
            try {
              RPCServiceClient serviceClient = new RPCServiceClient();
          Options options = serviceClient.getOptions();
          EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/ResumeService");
          options.setTo(targetEPR);
          // Setting the resume
            QName opGetResumeDetails = new QName("http://www.examples.com", "getResumeDetails");
            Object[] opGetResumeArgs = new Object[] { "1" };
   
            Class[] returnTypes = new Class[] { GetResumeDetailsResponse.class };
            Object[] response = serviceClient.invokeBlocking(opGetResumeDetails,
                                           opGetResumeArgs, returnTypes);
            }catch(AxisFault a) {
                  a.printStackTrace();
            }
      }
}

I intend to call the "getResumeDetails" method of service and pass the resume id as parameter. But it is giving me an error
org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement arg0
      at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:517)
      at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:371)
      at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
      at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)

Can someone please guide me as to how to proceed?

Thank you

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://www.examples.com/wsdl/ResumeService.wsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ResumeService"
	targetNamespace="http://www.examples.com/wsdl/ResumeService.wsdl">
	<wsdl:types>
		<xsd:schema targetNamespace="http://www.examples.com/wsdl/ResumeService.wsdl">
			<xsd:element name="getResumeId">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="firstName" type="xsd:string" />
						<xsd:element name="lastName" type="xsd:string"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="getResumeIdResponse">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="resumeId" type="xsd:string" />
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="getResumeDetails">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="resumeId" type="xsd:string"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="getResumeDetailsResponse">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="firstName" type="xsd:string"></xsd:element>
						<xsd:element name="lastName" type="xsd:string"></xsd:element>
						<xsd:element name="address" type="tns:addressType"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>

			<xsd:complexType name="addressType"></xsd:complexType>
		</xsd:schema>
	</wsdl:types>
	<wsdl:message name="getResumeIdRequest">
		<wsdl:part element="tns:getResumeId" name="parameters" />
	</wsdl:message>
	<wsdl:message name="getResumeIdResponse">
		<wsdl:part element="tns:getResumeIdResponse" name="parameters" />
	</wsdl:message>
	<wsdl:message name="getResumeDetailsRequest">
		<wsdl:part name="parameters" element="tns:getResumeDetails"></wsdl:part>
	</wsdl:message>
	<wsdl:message name="getResumeDetailsResponse">
		<wsdl:part name="parameters" element="tns:getResumeDetailsResponse"></wsdl:part>
	</wsdl:message>
	<wsdl:portType name="ResumeService">
		<wsdl:operation name="getResumeId">
			<wsdl:input message="tns:getResumeIdRequest" />
			<wsdl:output message="tns:getResumeIdResponse" />
		</wsdl:operation>
		<wsdl:operation name="getResumeDetails">
			<wsdl:input message="tns:getResumeDetailsRequest"></wsdl:input>
			<wsdl:output message="tns:getResumeDetailsResponse"></wsdl:output>
		</wsdl:operation>
	</wsdl:portType>
	<wsdl:binding name="ResumeServiceSOAP" type="tns:ResumeService">

		<soap:binding style="document"
			transport="http://schemas.xmlsoap.org/soap/http" />
		<wsdl:operation name="getResumeId">

			<soap:operation
				soapAction="http://www.examples.com/wsdl/ResumeService.wsdl/getResumeId" />
			<wsdl:input>

				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>

				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="getResumeDetails">
			<soap:operation
				soapAction="http://www.examples.com/wsdl/ResumeService.wsdl/getResumeDetails" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>
	<wsdl:service name="ResumeService">
		<wsdl:port binding="tns:ResumeServiceSOAP" name="ResumeServiceSOAP">
			<soap:address location="http://www.example.org/" />
		</wsdl:port>
	</wsdl:service>
</wsdl:definitions>

Open in new window

ank9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Hold on it actually simple, you don't need direct invocation.

Let me help you with it. Will post a next comment with the client stubs and main class.
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Here is the client code you need to invoke the service.


import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;

import com.examples.www.wsdl.resumeservice_wsdl.ResumeServiceStub;
import com.examples.www.wsdl.resumeservice_wsdl.ResumeServiceStub.GetResumeDetails;
import com.examples.www.wsdl.resumeservice_wsdl.ResumeServiceStub.GetResumeDetailsResponse;
import com.examples.www.wsdl.resumeservice_wsdl.ResumeServiceStub.GetResumeId;
import com.examples.www.wsdl.resumeservice_wsdl.ResumeServiceStub.GetResumeIdResponse;


public class ResumeServiceClient {

	/**
	 * @param args
	 * @throws RemoteException 
	 */
	public static void main(String[] args) throws RemoteException {
		// TODO Auto-generated method stub

		ResumeServiceStub rs = new ResumeServiceStub();
	
		//to call getResumeDetails
		GetResumeDetails gd = new GetResumeDetails();
		gd.setResumeId("xyz");
		GetResumeDetailsResponse gdRes = rs.getResumeDetails(gd);
	
		//to call getResumeId
		GetResumeId id = new GetResumeId();
		id.setFirstName("siva");
		id.setLastName("Prasanna");
		GetResumeIdResponse getIdRes= rs.getResumeId(id);
	}

}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
if you have a different endpoint then use the below code @ line 21 above for setting the appropriate endpoint.
//if you have a differnt end point use this
		
rs = new ResumeServiceStub("http://localhost:8080/axis2/ResumeService");
		

Open in new window

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

ank9Author Commented:
Thanks a lot.
I did the following
But it gave the following error

[INFO] Deploying module: metadataExchange-1.5 - file:/C:/axis2-1.5/lib/mex-1.5.jar
Exception in thread "main" org.apache.axis2.AxisFault: address cannot be null!!
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:517)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:371)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.examples.www.wsdl.resumeservice_wsdl.ResumeServiceStub.getResumeDetails(ResumeServiceStub.java:180)
at com.examples.www.wsdl.resumeservice_wsdl.ResumeClient.main(ResumeClient.java:23)
 
Please let me know how to solve this.
 
Thank you

public static void main(String[] args) throws RemoteException {
		

		ResumeServiceStub rs = new ResumeServiceStub("http://localhost:8080/axis2/services/ResumeService"); 

		// to call getResumeDetails
		GetResumeDetails gd = new GetResumeDetails();
		gd.setResumeId("1");
		GetResumeDetailsResponse gdRes = rs.getResumeDetails(gd);
        System.out.println("response recieved -1"); 
		// to call getResumeId
		GetResumeId id = new GetResumeId();
		id.setFirstName("siva");
		id.setLastName("Prasanna");
		GetResumeIdResponse getIdRes = rs.getResumeId(id);
		System.out.println("response recieved -1");
	}

Open in new window

0
ank9Author Commented:
Even if I try to run the service using soapUI, I get the same error message.
Seems the problem is with the Service and not the client.
Any clue as to what could be the issue?
Thank you
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
did you implement the service and host it on the server?

whats the service location and its WSDL location?
0
ank9Author Commented:
Please find attached the service screenshot.
Thank you
 

ServiceLocation.JPG
0
ank9Author Commented:
If I click on the "ResumeService" link, I am able to see the wsdl.
 
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
My question was when a request comes to getResumeDetails(resumeid) have you implemented the code to return the result or not?
0
ank9Author Commented:
Following is the code that I wrote in the skeleton class
 

public class ResumeServiceSkeleton {

	public GetResumeDetailsResponse getResumeDetails(GetResumeDetails getResumeDetails) {
		String resumeId = getResumeDetails.localResumeId;
		System.out.println("REsume is passed by client is --"+resumeId);
		GetResumeDetailsResponse res = new GetResumeDetailsResponse();
		if(resumeId.equalsIgnoreCase("1")) {
			res.setFirstName("A");
			res.setLastName("B");
		} else {
			res.setFirstName("C");
			res.setLastName("D");
		}
		return res;
	}

	public GetResumeIdResponse getResumeId(GetResumeId getResumeId) {
		String firstName = getResumeId.getFirstName();
		System.out.println("firstName is passed by client is --"+firstName);
		GetResumeIdResponse res = new GetResumeIdResponse();
		if(firstName.equalsIgnoreCase("A")) {
			res.setResumeId("007");
			
		} else {
			res.setResumeId("009");
		}
		return res;
	}

}

Open in new window

0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Do you see those system.out on the server console ? when are request is made to the web service?
0
ank9Author Commented:
Yes, I can see that. Here is what I see on the server console.
0
ank9Author Commented:
Yes, I can see that. Here is what I see on the server console.
REsume is passed by client is --1
[ERROR] address cannot be null!!
org.apache.axis2.AxisFault: address cannot be null!!
        at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
        at org.apache.axis2.transport.http.SOAPMessageFormatter.writeTo(SOAPMess
ageFormatter.java:83)
        at org.apache.axis2.transport.http.CommonsHTTPTransportSender.sendUsingO
utputStream(CommonsHTTPTransportSender.java:355)
        at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(Com
monsHTTPTransportSender.java:232)
        at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:435)
        at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusines
sLogic(AbstractInOutMessageReceiver.java:43)
        at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMe
ssageReceiver.java:114)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:173)
        at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostReq
uest(HTTPTransportUtils.java:167)
        at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:1
42)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:286)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:845)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:44
7)
        at java.lang.Thread.run(Thread.java:595)
Caused by: org.apache.axis2.databinding.ADBException: address cannot be null!!
        at com.examples.www.wsdl.resumeservice_wsdl.GetResumeDetailsResponse.ser
ialize(GetResumeDetailsResponse.java:224)
        at com.examples.www.wsdl.resumeservice_wsdl.GetResumeDetailsResponse.ser
ialize(GetResumeDetailsResponse.java:104)
        at com.examples.www.wsdl.resumeservice_wsdl.GetResumeDetailsResponse$1.s
erialize(GetResumeDetailsResponse.java:89)
        at org.apache.axis2.databinding.ADBDataSource.serialize(ADBDataSource.ja
va:93)
        at org.apache.axiom.om.impl.llom.OMSourcedElementImpl.internalSerializeA
ndConsume(OMSourcedElementImpl.java:738)
        at org.apache.axiom.om.impl.llom.OMElementImpl.internalSerialize(OMEleme
ntImpl.java:966)

Open in new window

0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Every thing just looks perfect, for the first time I am seeing "address is null!" can you do one thing can you please upload your WAR file ?
0
ank9Author Commented:
Thank you.
Please find attached the .aar file. Please change the extention to .aar upon download.
Following files were also renamed
MANIFEST.MF --> MANIFEST.txt
ResumeService.wsdl --> ResumeService.doc
 

ResumeService.txt
0
ank9Author Commented:
Thanks for your help.
The problem was that in skeleton I was not setting the value of "address"
So first I updated the wsdl to include "city"

xsd:complexType name="addressType">
<xsd:sequence>
<xsd:element name="city" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
 
and then I updated the skeleton code to set the value of address.

AddressType at = new AddressType();

if(resumeId.equalsIgnoreCase("1")) {
at.setCity("XX");
res.setFirstName("A");
res.setLastName("B");
res.setAddress(at);
} else {
at.setCity("YY");
res.setFirstName("C");
res.setLastName("D");
res.setAddress(at);
}
 
the problem is resolved now.
Thank you
 
 
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
Excellent sorry, couldn't look in to it as it was pretty late here I am in NY.
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
an infact when it said address is null, I thought web service address and not the element address :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.