This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Web Services and the fly likes Making a webservice call using axis2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Making a webservice call using axis2" Watch "Making a webservice call using axis2" New topic
Author

Making a webservice call using axis2

Brett Daburn
Greenhorn

Joined: Nov 25, 2008
Posts: 10
I am developing a client for a web service that is already existing. I got axis2 and created the code form the WSDL2Java from the web service's WSDL. I set all of the objects but now do not know how to make the call to the service.

The documentation provided from the web service vendor is in ASP.NET, however, I'm using Java. I was able to follow their example up until instantiating the proxy for sending the request to the web service and calling it.

This is the ASP.NET code I can't follow:



How do I send out the request to get back the response URL in Java?






My Java code so far:
Duc Vo
Ranch Hand

Joined: Nov 20, 2008
Posts: 254
Originally posted by Brett Daburn:
This is the ASP.NET code I can't follow:

In AXIS, it is service locator object. Should be something like (providing that your port name is "SingleSignOnService"


“Everything should be as simple as it is, but not simpler.” Albert Einstein
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
Originally posted by Brett Daburn:
I got axis2 and created the code form the WSDL2Java from the web service's WSDL.


Axis2 WSDL2Java supports different styles of data binding which affects the style of objects that it generates. It defaults to ADB (Axis Data Binding).

If you have a look at the Axis 2 sample clients that are included in the distribution you will notice that ADB clients follow this pattern


ADB can get a bit confusing as complex types are often mapped to one class to represent the "type" and another class to represent the "element" (which contains the "type"). Example:


In this case ADB will create a SOAPStruct class with the properties and a MyElement class which contains a SOAPStruct instance. This could potentially clash with your mental model because it wouldn't unreasonable to expect the MyElement class to have the varString, varInt, and varFloat properties, just as the myElement element has the varString, varInt, and varFloat subelements - instead you have to set the properties on a SOAPStruct instance and then place the SOAPStruct instance in the MyElement instance.
This is referred to as the "Expanded" generation mode (which is the default).
[ November 25, 2008: Message edited by: Peer Reynders ]

"Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
Brett Daburn
Greenhorn

Joined: Nov 25, 2008
Posts: 10
I really appreciate the help. I believe that I have it set up correctly and am sending the request correctly. However, I am getting a timeout. Is there anything special you need to do to send to https?


Start:
- Deploying module: metadataExchange - file:/C:/Documents and Settings/c02378/Desktop/axis2-1.4.1/lib/mex-1.4.1.jar
- I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
- Retrying request
- I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
- Retrying request
- I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: connect
- Retrying request
- Unable to sendViaPost to url[https://services.pj1.staging.printable.com/TRANS/0.9/SSO.asmx]
java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:507)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:546)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:130)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:542)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:189)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:371)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:209)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:448)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:401)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at com.printable.services._1_0.sso.SingleSignOnStub.Authenticate(SingleSignOnStub.java:463)
at com.printable.services._1_0.sso.Test.main(Test.java:47)
org.apache.axis2.AxisFault: Connection timed out: connect
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:371)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:209)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:448)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:401)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at com.printable.services._1_0.sso.SingleSignOnStub.Authenticate(SingleSignOnStub.java:463)
at com.printable.services._1_0.sso.Test.main(Test.java:47)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:507)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:546)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140)
at org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory.createSocket(SSLProtocolSocketFactory.java:130)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:542)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:189)
... 9 more
Done.




Here is my code:
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
Originally posted by Brett Daburn:
Is there anything special you need to do to send to https?



According to this document (Accessing Web Service via SSL) you have to first import the server certificate into a client truststore


and then set some client properties
Brett Daburn
Greenhorn

Joined: Nov 25, 2008
Posts: 10
Thanks for the info Peer. Does it look like this is the reason for the timeout? I mean, do you get a timeout exception when you don't have the certificate in your TrustStore? I changed it to not use https and am still getting the timeout when you can place the URL in the browser without the https and still get a response.
Brett Daburn
Greenhorn

Joined: Nov 25, 2008
Posts: 10
I just tried making a simple get request using the following code sample and got the same timeout exception. I will need to figure out what is wrong with my environment not allowing requests. Then I will look into the certificate issue. Thank you for your help!
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
Originally posted by Brett Daburn:
I just tried making a simple get request using the following code sample and got the same timeout exception.


A SOAP endpoint doesn't have to respond to GET requests. SOAP requests are POSTed to the SOAP endpoint URI.
A well behaved SOAP endpoint would return 405 "Method Not Allowed" - however some SOAP stacks have a bit of tunnel vision when it comes to following proper HTTP etiquette.

Finally http is typically served on port 80 while https (SSL/TLS) is served on port 443. So it is entirely possible that nobody is listening on port 80 even when port 443 works.

Simply point your browser to the URL that is composed of the endpoint address and a "?wsdl" suffix

If the WSDL comes up it's likely that something is listening. If it doesn't come up the WSDL is suppressed or the server is down.
[ November 28, 2008: Message edited by: Peer Reynders ]
 
Consider Paul's rocket mass heater.
 
subject: Making a webservice call using axis2
 
Similar Threads
Developing web services need help
How to Call a web service from behind a firewall/Proxy
java.net.UnknownHostException when calling a web service from Java client
Webservice client code generation using axis2 and eclipse galilio
How to create UsernameToken in Java WS client to compatble with .Net (.asmx) web service