File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Webservices - communication exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Webservices - communication exception" Watch "Webservices - communication exception" New topic

Webservices - communication exception

sriram varadharajan

Joined: Jan 03, 2007
Posts: 9
I am reading the book SOA using JWS by Mark Hansen and trying out the examples . i am stuck with the example that teaches how to post xml to a REST based webservice without using JAX-WS.

Using maven i have deployed the webservice and i am trying to post an XML file to it using the client.
This is the client code that is trying to connect to service . it is basic HTTP connection and does not involve the JAX-WS API

public class PostCustomerHistory {

//! <example xn="PostCustomerHistory_Client_HTTP">
//! <c>chap03</c>rest-post
public static void main(String[] args) throws Exception {
if (args.length != 2) {
("Usage: java PostCustomerHistory <XML file name> "
+ "<Web Service URL>");
FileInputStream in = new FileInputStream(args[0]);
URL url = new URL(args[1]);
HttpURLConnection con =
(HttpURLConnection) url.openConnection();
System.out.println("Before connectionggggggg"+args[1]);

OutputStream out = con.getOutputStream();

// write the XML doc from file to the HTTP connection
byte[] b = new byte[1024]; // 1K buffer
int result =;
while (result != -1) {
result =;
System.out.println("After connectionggggggg");
// write HTTP response to console
System.out.println(con.getResponseCode() +
" srirammmmmmmmmmmmmmm" + con.getResponseMessage());
//! </example>

the exception i get is

[java] Before connectionggggggghttp://localhost:8080/chap03-restpost-endpoi
[java] After connectionggggggg
[java] 500 srirammmmmmmmmmmmmmmThe system cannot find the path specified
[INFO] Executed tasks
[INFO] [install:install {execution: default-install}]
[INFO] Installing C:\webservicesCodeSamples\chap03\rest-post\client-http\target\
chap03-restpost-client-http-1.0.jar to C:\Documents and Settings\svaradharajan\.

please let me know where i am going wrong.Both the client and server are in the same machine.

I agree. Here's the link:
subject: Webservices - communication exception
jQuery in Action, 3rd edition