Avatar of tcorigli
tcorigli
 asked on

Call a web service from java (eclipse)

How can I simply call a web service from java (eclipse)?
Java

Avatar of undefined
Last Comment
tcorigli

8/22/2022 - Mon
mrcoffee365

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
tcorigli

ASKER
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).
ASKER CERTIFIED SOLUTION
mrcoffee365

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
tcorigli

ASKER
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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
mrcoffee365

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

ASKER
Thanks mrcoffee