Call a web service from java (eclipse)

Posted on 2012-12-24
Last Modified: 2013-01-01
How can I simply call a web service from java (eclipse)?
Question by:tcorigli
  • 3
  • 3
LVL 27

Expert Comment

ID: 38719293
You make an httpservletrequest:

Most people use the Apache commons HttpClient as a wrapping package, since it handles redirects and cookies:

Author Comment

ID: 38719735
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).
LVL 27

Accepted Solution

mrcoffee365 earned 500 total points
ID: 38733638
In that case, it's an easy online search.  For example:

We could help more if you had some code you were trying.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 38734188
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(
      at WebServiceCall.getWeather(
      at WebServiceCall.main(

The code is attached.
Your assistance is greatly appreciated.
LVL 27

Expert Comment

ID: 38734917
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 Comment

ID: 38735119
Thanks mrcoffee

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Error in @AspectJ Based AOP with Spring 2 23
java imports not found 4 47
Netbeans and org.apache.commons.lang3 issue 3 22
Java Inheritance super keyword use 8 32
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question