Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how do transfer data from one server to another server

 
elay Raja
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to send xml from one server to another server(ie.cross domain).How can i send it through servlet.is it possible to send it using URL class by making connection to required servlet.

For example, if there are two WebApplication1 & WebApplication2. I want to send the data from webApplication1 to webapplication2 through servlet.

Please help me to resolve this issue.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, if that's the mechanism you want to use.
 
elay Raja
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you send me some example code? Now the code i'm trying like this

URL urlServlet = new URL("https://111.111.111/TestServlet");
con = (HttpsURLConnection) urlServlet.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setDefaultUseCaches(false);
con.setAllowUserInteraction(true);
con.setRequestMethod("GET");
con.setRequestProperty("Content-Length", "0");
con.setRequestProperty("Content-Type", "text/html;charset=UTF-8");
ObjectOutputStream outstream = new ObjectOutputStream(con.getOutputStream());
outstream.writeObject("hi");
outstream.flush();
outstream.close();
But the above code does not reach the requred servlet in the specified URL.
Is there any problem in the code. Please help me to solve this problem
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the above code does not reach the requred servlet in the specified URL.
Is there any problem in the code. Please help me to solve this problem


Exactly what happens?
You do not appear to be reading the response so you are missing possible error codes. Also I dont see any provision for exception handling, there are many places in your code that could be throwing an exception which would be diagnostic.

Bill
 
elay Raja
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply.I found the error.
Now i want to make connection to servlet using URL class. The above servlet is in j_security_check enabled application.
if i connect using in normal way through URL class,i am getting IOException 405 servlet response code. how to make connection using URL?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error 405 is the standard response code for "method not allowed" - you can look these up in the JavaDocs for HttpURLConnection class.

The method your code specifies is "GET" - apparently the responding servlet does not like a GET - which makes sense because you are trying to send data in the body of the request. Normally done with a POST or PUT.

Why are you setting Content-Length to zero?
Why are you trying to send a Java object instead of text like your Content-Type specifies?

Bill
 
Hendy Setyo Mulyo
Ranch Hand
Posts: 219
Firefox Browser Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Elay,

You must use PUT method. Perhaps you can see this link http://kickjava.com/996.htm
There is a brief example of using PUT method for HttpURLConnection.
[ August 20, 2008: Message edited by: Hendy Setyo Mulyo ]
 
Evgeniy Bulanov
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi elay Raja,

U may use POST method too. It's like uploading files to server. Set enctype="multipart/form-data" and parse it by org.apache.commons.fileupload.disk.DiskFileItemFactory, org.apache.commons.fileupload.servlet.ServletFileUpload (google for it).

JK
 
elay Raja
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,I found the error.Now it works fine.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you feel like sharing?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic