wood burning stoves 2.0*
The moose likes Servlets and the fly likes doPut() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "doPut()" Watch "doPut()" New topic
Author

doPut()

Mike Cronin
Greenhorn

Joined: Apr 17, 2002
Posts: 25
Hi all,
Does anyone have example code for performing a doPut() from a servlet?
I need to be able to send a file from our server to a clients secure (HTTPS) URL.
Any comments will be most welcome!
Thank you in advance.
Mike Cronin
Data On Call
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
check this post
http://www.coderanch.com/t/354813/Servlets/java/doPut-doDelete


"In the country of the blind, the one eyed man is the King"
Gautham Kasinath CV at : http://www.geocities.com/gkasinath
Mike Cronin
Greenhorn

Joined: Apr 17, 2002
Posts: 25
Thanks Gautham,
I've already checked out those links. I'm at the point where instead of performing a doPut() method, I am doing the following (still not getting the desired results though)
Within the doPost() method I am messing with the following code...

URL url = new URL(PROTOCOL + "://" + HOSTNAME);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("PUT");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.connect();
FileInputStream fis = new FileInputStream(new File("C:\\MyStuff\\testWordDoc.doc"));
int noOfBytes = fis.available();
byte b[] = new byte[noOfBytes];
fis.read(b, 0, noOfBytes);
try {
fis.close();
}
catch(Exception e) {}
OutputStream out = connection.getOutputStream();
int code = connection.getResponseCode();
if ((code >= 200) && (code < 300)) {
BufferedOutputStream bos = new BufferedOutputStream(out);
bos.write(b);
bos.flush();
bos.close();
}
out.close();
connection.disconnect();

Thanks so much for your reply though!!!
Mike Cronin
Data On Call
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
Originally posted by Mike Cronin:
Thanks Gautham,

Mate.. thats Lupo.. Lupo is my call sign on the Net.
Anyway, I did read somewhere that normally webservers do not support PUT request since they will need to change the security permissions on the Server, which is a bad idea if you are looking @ good secure site..
But a small architecture just struck me.
Have two servers, one in a secure network ( guarded by a firewall) and one on the unsecure ( on the net )
The put request is given only to the Server on the Net ( unsecure ) since only that is exposed to the internet.. the request is then forwarded to the secure server within the firewall for processing.. and the respective success/failure is sent to the unsecure server.. which inturn sends it to the client browser.. Phew...
Well that way the *put*ting will be secure and nothing much malicious can happen.
What say??
Lupo
Mike Cronin
Greenhorn

Joined: Apr 17, 2002
Posts: 25
Hey Lupo,
Sounds good to me bud. Thanks again for your response!
Best Regards,
Mike Cronin
Data on Call :roll:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doPut()
 
Similar Threads
How to call HEAD method ?
IDEMPOTENT or not ?
Is Put Idempotent or Not?
file upload using doPut()
doPost() vs doPut()