aspose file tools*
The moose likes Servlets and the fly likes PUT request method not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "PUT request method not working" Watch "PUT request method not working" New topic
Author

PUT request method not working

sridhar gandikota
Ranch Hand

Joined: Jul 09, 2008
Posts: 31
Hi Ranchers,

I am fairly new to the PUT request method.

I am trying to access file from the url and write some content to the file using PUT request method.

Here is my main method



here are my questions:

1) is there any limit on number of characters to PUT request like GET
2)This program is not working can you please let me know what is the wrong with code
3)If I access the file using PUT request should I write the data in chunks(shown in comments) or can I write the data at one full stretch like I have shown above.

With Regards,
Sridhar
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61421
    
  67

sridhar gandikota wrote:
1) is there any limit on number of characters to PUT request like GET

No. Unlike a GET, the payload is in the request body, not on the URL.

2)This program is not working can you please let me know what is the wrong with code

What's wrong is your basic assumptions. It makes no sense to make a PUT request to a file. If you think that something will magically update the file, you are mistaken. The PUT request must be made to a servlet or other active element that knows how to deal with PUT requests.

3)If I access the file using PUT request should I write the data in chunks(shown in comments) or can I write the data at one full stretch like I have shown above.

The data should in the body of the request.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sridhar gandikota
Ranch Hand

Joined: Jul 09, 2008
Posts: 31
Thanks Bear Bibeault for your prompt reply.

But what I am trying to do is something like this



java.io.BufferedInputStream in = new java.io.BufferedInputStream(new java.net.URL("http://localhost:9090/test/test.txt").openStream());
java.io.FileOutputStream fos = new java.io.FileOutputStream("http://localhost:9090/test/test1.txt");

java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
byte data[] = new byte[1024];
while(in.read(data,0,1024)>=0)
{
bout.write(data);
}
bout.close();
in.close();




In other words I want to implement poster plugin for firefox browser in java program is this possible
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61421
    
  67

What are you expecting that to do? What's running at localhost:9090?
sridhar gandikota
Ranch Hand

Joined: Jul 09, 2008
Posts: 31
I just wanted to post some content to file in the URL using java. just wanted to know whether its possible ?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61421
    
  67

You have not answered by question. What's at localhost:9090?

And again, you can't just make a PUT request to a file at some URL and expect anything special to happen.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4659
    
    5

You really have to answer @bear's question.

From the small bit of code you have, you are not going to get there, no matter what you are trying to do. You have fundamental concepts all twisted. Something like your:



assumes that you have a HTTP server running and listening to 9090, and that the one line code will work. It won't. You need an Java implementation of the whole HTTP client protocols to make that work reliably, even if it was what you want to do, which I don't think it is.
sridhar gandikota
Ranch Hand

Joined: Jul 09, 2008
Posts: 31
After doing a bit of search based on Bears comments on how the PUT request works and also some stuff about the HttpURLConnection.

1) I came to know that we cannot directly access files on the servers and change its contents (magically )
2) I ran some sample programs to understand the concept.

Thanks for guidance Bear and Pat. You guys are simply super, you made my concepts about request methods to be corrected.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PUT request method not working