Skip to main content

Consuming a web service

10 replies [Last post]
leighton
Offline
Joined: 2007-07-02
Points: 0

hello
wanted to consume the following web service:
http://www.dataaccess.com/webservicesserver/numberconversion.wso

http://www.dataaccess.com/webservicesserver/numberconversion.wso?op=Numb...

so i used WSDL2Java to create client stubs n then followed it with a client program

public class XmethodsAccessor {

public static void main(String[] args) throws Exception{
org.apache.axis2.databinding.types.UnsignedLong x = new org.apache.axis2.databinding.types.UnsignedLong(10000L);
NumberConversionStub stub = new NumberConversionStub();
NumberConversionStub.NumberToWords request = new NumberConversionStub.NumberToWords();
request.setUbiNum(x);

NumberToWordsResponse response = stub.NumberToWords(request);
System.out.println("answer is : " + response.getNumberToWordsResult());

}

}

Upon running the program i get error


Exception in thread "main" org.apache.axis2.AxisFault: Connection reset
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:221)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:452)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:330)
at org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:294)
at com.dataaccess.www.webservicesserver.NumberConversionStub.NumberToWords(NumberConversionStub.java:162)
at com.dataaccess.www.webservicesserver.XmethodsAccessor.main(XmethodsAccessor.java:19)
Caused by: org.apache.axis2.AxisFault: Connection reset
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:314)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:201)
... 5 more
Caused by: org.apache.axis2.AxisFault: Connection reset
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:179)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:73)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:305)
... 6 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:77)
at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:105)
at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1115)
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1832)
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:558)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:176)
... 8 more

Can any one please tell me what im doin wrong and why is it not working.

Thanks
PS: am using Eclipse 3.2/Axis2 Eclipse plugin .. there were no compilation errors

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
leighton
Offline
Joined: 2007-07-02
Points: 0

i followed the following tutorials http://wso2.org/library/1719
and http://wso2.org/library/1986 and http://wso2.org/library/95 . Was able to successfully create, deploy and access the webservices.
then i tried creating clients for web services already existing using the client creation methods mentioned above. but to no avail. they all give the same error as i mentioned

i also want to try JAX RPC but i dont know how to generate the stubs/mapping files

any help/links/tutorials would be greatly appreciated..
thanks

karthik_cs
Offline
Joined: 2007-04-27
Points: 0

hello Friend
NumberConversionLocator s = new NumberConversionLocator();
try {
NumberConversionSoapType port = s.getNumberConversionSoap();
port.numberToDollars(new BigDecimal(10000));
System.out.println(port.numberToWords(new UnsignedLong(11111)));

I got the output. it is working for me perfectly.
eleven thousand one hundred and eleven

I have mentioned in the prev post on how to proceed. If you have any doubts. let me know or come online in Yahoo or skype
karthik_rcs@yahoo.com
karthik_rcs is my skype id

karthik_cs
Offline
Joined: 2007-04-27
Points: 0

SOAP REQUEST FOR THE ABOVE WEBSERVICE
----------------------------------------------------------------------------
BEGIN OUTGOING REQUEST
----------------------------------------------------------------------------

-
-
-
1234567



----------------------------------------------------------------------------
END OUTGOING REQUEST
----------------------------------------------------------------------------

SOAP response FOR THE ABOVE WEBSERVICE
----------------------------------------------------------------------------
BEGIN INCOMING RESPONSE
----------------------------------------------------------------------------
-
-
-
one million two hundred and thirty four thousand five hundred and sixty seven



----------------------------------------------------------------------------
END INCOMING RESPONSE
----------------------------------------------------------------------------

karthik_cs
Offline
Joined: 2007-04-27
Points: 0

Hello Friend
I generated the stubs in teh same way you generated

Three ways to generate client code
1. Generated Stub
2. Dynamic Proxy
3. DII

In the below code i have used the gen.stub mechanism , getting the stub from service locator

Kindly Check if the following works

import java.math.BigDecimal;
import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import org.apache.axis.types.UnsignedLong;

import com.dataaccess.www.webservicesserver.NumberConversionLocator;
import com.dataaccess.www.webservicesserver.NumberConversionSoapType;

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

NumberConversionLocator s = new NumberConversionLocator();
try {
NumberConversionSoapType port = s.getNumberConversionSoap();
port.numberToDollars(new BigDecimal(10000));
port.numberToWords(new UnsignedLong(10000));
}
catch(ServiceException e)
{

}
}

}

------------
In your code, kindly confirm whether end point url you refer is the correct webservice.

leighton
Offline
Joined: 2007-07-02
Points: 0

by same way u mean using Axis2 Eclipse plugin.. coz i dont have the following classes in my code
NumberConversionLocator;
NumberConversionSoapType;

also import javax.xml.rpc.*; package does'nt exist. im using java2 sdk

Could you please elaborate more on
>>Three ways to generate client code
>>1. Generated Stub
>>2. Dynamic Proxy
>>3. DII

>>In your code, kindly confirm whether end point url you refer is the correct webservice.
What is a end point url and how to check it.

karthik_cs
Offline
Joined: 2007-04-27
Points: 0

Hello Friend
i tried the wsdl with following build.xml

Use the target generate-client-stub alone to generate the stub files.
-------------------------------------------------------------------------------------------------------------






url="./wsdl/Test.wsdl" verbose="true">






-------------------------------------------------------------------------------------------------------------


name="NumberConversion"
targetNamespace="http://www.dataaccess.com/webservicesserver/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.dataaccess.com/webservicesserver/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema">










































Returns the word corresponding to the positive number passed as parameter. Limited to quadrillions.






Returns the non-zero dollar amount of the passed number.


























The Number Conversion Web Service, implemented with Visual DataFlex, provides functions that convert numbers into words or dollar amounts.






-------------------------------------------------------------------------------------------------------------------------------
I used the above wsdl which i got from the site you have given. Kindly add the following jar to your classpath
axis.jar
axis-ant.jar
commons-discovery-0.2.jar
commons-logging-1.0.4.jar
jaxrpc.jar
log4j.properties
log4j-1.2.8.jar
saaj.jar
wsdl4j-1.5.1.jar

Which is available in axis folder lib

karthik_cs
Offline
Joined: 2007-04-27
Points: 0

can you tell me how are you generating the stubs.

leighton
Offline
Joined: 2007-07-02
Points: 0

sir ji,
thanks for replying.
im experimenting with two methods
am using eclipse 3.2

in one method im using the axis2 code generator plugin http://ws.apache.org/axis2/tools/index.html to generate the stubs
that is the code iv posted.

another uses the WTP 2.0 eclipse plugin but im not having too much success with that either...

karthik_cs
Offline
Joined: 2007-04-27
Points: 0

Can i have your IM id or contact id

karthik_cs
Offline
Joined: 2007-04-27
Points: 0

1. Create a java project with src, lib, wsdl
2. Put the jar i mentioned in lib folders
3. copy the wsdl i gave to wsdl folder
4. create build.xml and put it in java project folder
5. update the axis.home folder value in build.xml and try executing the build.xml
( Generate-client-stub task alone)
6. you should be able to get the folders com.dataaccess.www.webserviceserver created
in java project folder.