• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doPut()

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check this post
https://coderanch.com/t/354813/Servlets/java/doPut-doDelete
 
Mike Cronin
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 583
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Lupo,
Sounds good to me bud. Thanks again for your response!
Best Regards,
Mike Cronin
Data on Call :roll:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic