Link to home
Start Free TrialLog in
Avatar of ank9
ank9

asked on

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

Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

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.
ASKER CERTIFIED SOLUTION
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

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
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

Avatar of ank9
ank9

ASKER

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

Avatar of ank9

ASKER

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
did you implement the service and host it on the server?

whats the service location and its WSDL location?
Avatar of ank9

ASKER

Please find attached the service screenshot.
Thank you
 

ServiceLocation.JPG
Avatar of ank9

ASKER

If I click on the "ResumeService" link, I am able to see the wsdl.
 
My question was when a request comes to getResumeDetails(resumeid) have you implemented the code to return the result or not?
Avatar of ank9

ASKER

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

Do you see those system.out on the server console ? when are request is made to the web service?
Avatar of ank9

ASKER

Yes, I can see that. Here is what I see on the server console.
Avatar of ank9

ASKER

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

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 ?
Avatar of ank9

ASKER

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
Avatar of ank9

ASKER

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
 
 
Excellent sorry, couldn't look in to it as it was pretty late here I am in NY.
an infact when it said address is null, I thought web service address and not the element address :)