Call a web service from java (eclipse)

tcorigli
tcorigli used Ask the Experts™
on
How can I simply call a web service from java (eclipse)?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007

Commented:
You make an httpservletrequest:
http://docs.oracle.com/javaee/6/api/index.html?javax/servlet/http/HttpServletRequest.html

Most people use the Apache commons HttpClient as a wrapping package, since it handles redirects and cookies:
http://hc.apache.org/httpcomponents-client-ga/index.html

Author

Commented:
Thank you for you reply, but I'm looking for an example or tutorial that shows me step by step how I simply can call an external web service from java (eclipse).
Top Expert 2007
Commented:
In that case, it's an easy online search.  For example:
http://technology.amis.nl/2011/06/29/how-to-call-a-call-a-webservice-directly-from-java-without-webservice-library/

We could help more if you had some code you were trying.
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Author

Commented:
Hi mrcoffee365,
Thank you for the link. I have tried to execute the code, but I'm receiving the following error message:

Exception in thread "main" java.lang.ClassCastException: org.apache.xerces.dom.DeferredDocumentImpl cannot be cast to javax.swing.text.Document
      at WebServiceCall.parseXmlFile(WebServiceCall.java:126)
      at WebServiceCall.getWeather(WebServiceCall.java:93)
      at WebServiceCall.main(WebServiceCall.java:33)

The code is attached.
Your assistance is greatly appreciated.
WebServiceCall.java
Top Expert 2007

Commented:
The exception is pretty clear.  This line, 126 in your program:
  return (Document) db.parse(is);

is trying to cast the results of DocumentBuilder db.parse method to a Document type.  So check the return type of the db.parse method, and cast it to the correct type or convert it to what you need.

Author

Commented:
Thanks mrcoffee

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial