Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 527
  • Last Modified:

Call a web service from java (eclipse)

How can I simply call a web service from java (eclipse)?
0
tcorigli
Asked:
tcorigli
  • 3
  • 3
1 Solution
 
mrcoffee365Commented:
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
0
 
tcorigliAuthor 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).
0
 
mrcoffee365Commented:
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
tcorigliAuthor 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
0
 
mrcoffee365Commented:
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.
0
 
tcorigliAuthor Commented:
Thanks mrcoffee
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now