You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Uday Subbarayan <ud...@yahoo.com> on 2008/07/17 02:34:00 UTC

PUT & Expect:100-continue

Hi All,
    I am having trouble in using HTTPClient 3.1 for PUT method w/ "Expect:100-Continue" header. 

My requirement is that,
[1] client sends a PUT request to the server with header only using this Expect header and waits for the 100 response back from the server.
[2] Then client sends the body, after it received the 100 status back from the server.

The problem is that if my server sends back 100-continue, HttpClient complaints about,
"INFO: Discarding unexpected response: HTTP/1.1 100 Continue".

Here is sample code:
          String testURL="http://localhost:8080/testci/index";
          HttpClient client = new HttpClient();
          
          PutMethod put = new PutMethod(url);
          put.setUseExpectHeader(true);
          int statusCode = client.executeMethod(put);
          
          
          if(statusCode==100){
              System.out.println("server response is 100!");
              put.setRequestBody(new FileInputStream("test.txt"));
          }
----------------------------

It looks like i am making some mistake.... Can some one shed some light here?

Thanks,
-Uday.

-------------------------

I do not blog but e-write:

http://uds-web.blogspot.com


      

Re: PUT & Expect:100-continu

Posted by David Motes <da...@gmail.com>.
 You are not specifying an entity to upload.

The 100 is handled by HTTPClient, you will not see it.

This code snippet works with a 100 from the server.

        FileInputStream fStream = null;
        try {
        fStream = new FileInputStream( file );
        }
        catch (java.io.FileNotFoundException e )
        {
            System.out.println("File not Found error " + fileName );
            completionCode = "NOTFOUND";
            return false;
        }

        ProgressMonitorInputStream pmis = new
ProgressMonitorInputStream( null, "Uploading File " +
mdoFile.toString(), fStream );
        pmis.getProgressMonitor().setMaximum((int)uploadFileSize);

        InputStreamRequestEntity iRequest = new
InputStreamRequestEntity( pmis, uploadFileSize );


        PutMethod method = null;

        //create a method object
            method = new PutMethod(url);

            method.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE,
true);

            method.setFollowRedirects(false);
            method.addRequestHeader("Content-Length", xfileSize );
            method.addRequestHeader("Content-Type",
"application/octet-stream" );
            method.setContentChunked( false );
            method.setRequestEntity( iRequest);


        //execute the method

        String responseBody = null;
        try{
            client.executeMethod(method);
            responseBody = method.getResponseBodyAsString();
        } catch (HttpException he) {
            System.err.println("http exception " + he.getMessage() );
            isCorrect = false;
        }
        catch (IOException ioe){
            System.err.println("Unable to connect to '" + url + "'");
            completionCode = "COMMERR";
            isCorrect =  false;
        }

        if ( isCorrect )
        {

               Header[] responseHeaders = method.getResponseHeaders();
            for (int i=0; i<responseHeaders.length; i++){
                    String tempString = responseHeaders[i].getName();

               // Look at response headers
            }
        }




-David

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: PUT & Expect:100-continu

Posted by Uday Subbarayan <ud...@yahoo.com>.
Thanks Sam, David & Oleg for the detailed response and I appreciate it. This info is very useful to me and let me test against my server...

Thanks,
-Uday.

-------------------------

I do not blog but e-write:

http://uds-web.blogspot.com

--- On Fri, 7/18/08, Sam Berlin <sb...@gmail.com> wrote:
From: Sam Berlin <sb...@gmail.com>
Subject: Re: PUT & Expect:100-continu
To: "HttpClient User Discussion" <ht...@hc.apache.org>
Date: Friday, July 18, 2008, 3:02 PM

The difference, Uday, is that HttpClient supports it internally.  You
don't have to do anything to make it work.  Just do a normal PUT
request with a body (and specify to use EXPECT_CONTINUE, as David
shows), and HttpClient will automagically make it work.  I think
you're trying to do it yourself, which is causing problems.  As Oleg
mentioned, httpclient performs the expect-continue internally, so a
1xx response should never be seen by the user in normal program flow.

Sam

On Fri, Jul 18, 2008 at 12:00 AM, Uday Subbarayan
<ud...@yahoo.com> wrote:
> Hi Oleg,
>     I disagree with you. This 100 status from HTTP Servers are valid
response, to indicate to the client to continue sending the body.
>
> The HTTP 1.1 spec says,
>
> "This interim response is
>   used to inform the client that the initial part of the request has
>   been received and has not yet been rejected by the server. The client
>   SHOULD continue by sending the remainder of the request or, if the
>   request has already been completed, ignore this response. The server
>   MUST send a final response after the request has been completed."
>
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1.1
>
> A good example is Amzon's S3:
> http://docs.amazonwebservices.com/AmazonS3/2006-03-01/
>
> Here client will send the header first and S3 authenticates request based
on header. Then if auth succeeds it will respond with 100 to indicate to the
client to continue with the body OR 417 OT to send the body.
>
> So,
>    Is it safe to assume that Apache's HTTPClient is NOT supporting
this "Expect:100-Continue" header in HTTP1.1?
>
> Thanks,
> -Uday.
> -------------------------
>
> I do not blog but e-write:
>
> http://uds-web.blogspot.com
>
> --- On Thu, 7/17/08, Oleg Kalnichevski <ol...@apache.org> wrote:
> From: Oleg Kalnichevski <ol...@apache.org>
> Subject: Re: PUT & Expect:100-continue
> To: "HttpClient User Discussion"
<ht...@hc.apache.org>
> Date: Thursday, July 17, 2008, 10:03 PM
>
> On Wed, 2008-07-16 at 17:34 -0700, Uday Subbarayan wrote:
>> Hi All,
>>     I am having trouble in using HTTPClient 3.1 for PUT method w/
> "Expect:100-Continue" header.
>>
>> My requirement is that,
>> [1] client sends a PUT request to the server with header only using
this
> Expect header and waits for the 100 response back from the server.
>> [2] Then client sends the body, after it received the 100 status back
from
> the server.
>>
>> The problem is that if my server sends back 100-continue, HttpClient
> complaints about,
>> "INFO: Discarding unexpected response: HTTP/1.1 100
Continue".
>>
>> Here is sample code:
>>           String
testURL="http://localhost:8080/testci/index";
>>           HttpClient client = new HttpClient();
>>
>>           PutMethod put = new PutMethod(url);
>>           put.setUseExpectHeader(true);
>>           int statusCode = client.executeMethod(put);
>>
>>
>>           if(statusCode==100){
>>               System.out.println("server response is 100!");
>>               put.setRequestBody(new
> FileInputStream("test.txt"));
>>           }
>> ----------------------------
>>
>> It looks like i am making some mistake.... Can some one shed some
light
> here?
>>
>
> Uday,
>
> HTTP agents are not supposed to return 1xx status codes to the caller.
> These are special purpose codes that are meant to be used internally
> Just let HttpClient handle the expect-continue handshaking.
>
>
http://hc.apache.org/httpclient-3.x/performance.html#Expect-continue_handshake
>
> You can see exactly what gets transferred across the wire by turning on
> the wire logging on the client side.
>
> http://hc.apache.org/httpclient-3.x/logging.html
>
> Hope this helps
>
> Oleg
>
>
>> Thanks,
>> -Uday.
>>
>> -------------------------
>>
>> I do not blog but e-write:
>>
>> http://uds-web.blogspot.com
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
>


      

Re: PUT & Expect:100-continu

Posted by Sam Berlin <sb...@gmail.com>.
The difference, Uday, is that HttpClient supports it internally.  You
don't have to do anything to make it work.  Just do a normal PUT
request with a body (and specify to use EXPECT_CONTINUE, as David
shows), and HttpClient will automagically make it work.  I think
you're trying to do it yourself, which is causing problems.  As Oleg
mentioned, httpclient performs the expect-continue internally, so a
1xx response should never be seen by the user in normal program flow.

Sam

On Fri, Jul 18, 2008 at 12:00 AM, Uday Subbarayan
<ud...@yahoo.com> wrote:
> Hi Oleg,
>     I disagree with you. This 100 status from HTTP Servers are valid response, to indicate to the client to continue sending the body.
>
> The HTTP 1.1 spec says,
>
> "This interim response is
>   used to inform the client that the initial part of the request has
>   been received and has not yet been rejected by the server. The client
>   SHOULD continue by sending the remainder of the request or, if the
>   request has already been completed, ignore this response. The server
>   MUST send a final response after the request has been completed."
>
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1.1
>
> A good example is Amzon's S3:
> http://docs.amazonwebservices.com/AmazonS3/2006-03-01/
>
> Here client will send the header first and S3 authenticates request based on header. Then if auth succeeds it will respond with 100 to indicate to the client to continue with the body OR 417 OT to send the body.
>
> So,
>    Is it safe to assume that Apache's HTTPClient is NOT supporting this "Expect:100-Continue" header in HTTP1.1?
>
> Thanks,
> -Uday.
> -------------------------
>
> I do not blog but e-write:
>
> http://uds-web.blogspot.com
>
> --- On Thu, 7/17/08, Oleg Kalnichevski <ol...@apache.org> wrote:
> From: Oleg Kalnichevski <ol...@apache.org>
> Subject: Re: PUT & Expect:100-continue
> To: "HttpClient User Discussion" <ht...@hc.apache.org>
> Date: Thursday, July 17, 2008, 10:03 PM
>
> On Wed, 2008-07-16 at 17:34 -0700, Uday Subbarayan wrote:
>> Hi All,
>>     I am having trouble in using HTTPClient 3.1 for PUT method w/
> "Expect:100-Continue" header.
>>
>> My requirement is that,
>> [1] client sends a PUT request to the server with header only using this
> Expect header and waits for the 100 response back from the server.
>> [2] Then client sends the body, after it received the 100 status back from
> the server.
>>
>> The problem is that if my server sends back 100-continue, HttpClient
> complaints about,
>> "INFO: Discarding unexpected response: HTTP/1.1 100 Continue".
>>
>> Here is sample code:
>>           String testURL="http://localhost:8080/testci/index";
>>           HttpClient client = new HttpClient();
>>
>>           PutMethod put = new PutMethod(url);
>>           put.setUseExpectHeader(true);
>>           int statusCode = client.executeMethod(put);
>>
>>
>>           if(statusCode==100){
>>               System.out.println("server response is 100!");
>>               put.setRequestBody(new
> FileInputStream("test.txt"));
>>           }
>> ----------------------------
>>
>> It looks like i am making some mistake.... Can some one shed some light
> here?
>>
>
> Uday,
>
> HTTP agents are not supposed to return 1xx status codes to the caller.
> These are special purpose codes that are meant to be used internally
> Just let HttpClient handle the expect-continue handshaking.
>
> http://hc.apache.org/httpclient-3.x/performance.html#Expect-continue_handshake
>
> You can see exactly what gets transferred across the wire by turning on
> the wire logging on the client side.
>
> http://hc.apache.org/httpclient-3.x/logging.html
>
> Hope this helps
>
> Oleg
>
>
>> Thanks,
>> -Uday.
>>
>> -------------------------
>>
>> I do not blog but e-write:
>>
>> http://uds-web.blogspot.com
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
>

Re: PUT & Expect:100-continue

Posted by Oleg Kalnichevski <ol...@apache.org>.
Uday Subbarayan wrote:
> Hi Oleg,
>     I disagree with you. This 100 status from HTTP Servers are valid response, to indicate to the client to continue sending the body. 
> 

You are very welcome to disagree.


RFC 2616, section 10.1
"
10.1 Informational 1xx

    This class of status code indicates a _provisional_ response,
...
    A client MUST be prepared to accept one or _more_ 1xx status 
responses prior to a _regular_ response
...
"



> The HTTP 1.1 spec says,
> 
> "This interim response is
>    used to inform the client that the initial part of the request has
>    been received and has not yet been rejected by the server. The client
>    SHOULD continue by sending the remainder of the request or, if the
>    request has already been completed, ignore this response. The server
>    MUST send a final response after the request has been completed."
> 
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1.1
> 
> A good example is Amzon's S3:
> http://docs.amazonwebservices.com/AmazonS3/2006-03-01/
> 
> Here client will send the header first and S3 authenticates request based on header. Then if auth succeeds it will respond with 100 to indicate to the client to continue with the body OR 417 OT to send the body.
> 
> So,
>    Is it safe to assume that Apache's HTTPClient is NOT supporting this "Expect:100-Continue" header in HTTP1.1?
> 

You can assume whatever you please. HttpClient is fully RFC 2616 
compliant with regards to the expect:continue handshaking.

Oleg


> Thanks,
> -Uday.
> -------------------------
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Re: PUT & Expect:100-continue

Posted by Uday Subbarayan <ud...@yahoo.com>.
Hi Oleg,
    I disagree with you. This 100 status from HTTP Servers are valid response, to indicate to the client to continue sending the body. 

The HTTP 1.1 spec says,

"This interim response is
   used to inform the client that the initial part of the request has
   been received and has not yet been rejected by the server. The client
   SHOULD continue by sending the remainder of the request or, if the
   request has already been completed, ignore this response. The server
   MUST send a final response after the request has been completed."

http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.1.1

A good example is Amzon's S3:
http://docs.amazonwebservices.com/AmazonS3/2006-03-01/

Here client will send the header first and S3 authenticates request based on header. Then if auth succeeds it will respond with 100 to indicate to the client to continue with the body OR 417 OT to send the body.

So,
   Is it safe to assume that Apache's HTTPClient is NOT supporting this "Expect:100-Continue" header in HTTP1.1?

Thanks,
-Uday.
-------------------------

I do not blog but e-write:

http://uds-web.blogspot.com

--- On Thu, 7/17/08, Oleg Kalnichevski <ol...@apache.org> wrote:
From: Oleg Kalnichevski <ol...@apache.org>
Subject: Re: PUT & Expect:100-continue
To: "HttpClient User Discussion" <ht...@hc.apache.org>
Date: Thursday, July 17, 2008, 10:03 PM

On Wed, 2008-07-16 at 17:34 -0700, Uday Subbarayan wrote:
> Hi All,
>     I am having trouble in using HTTPClient 3.1 for PUT method w/
"Expect:100-Continue" header. 
> 
> My requirement is that,
> [1] client sends a PUT request to the server with header only using this
Expect header and waits for the 100 response back from the server.
> [2] Then client sends the body, after it received the 100 status back from
the server.
> 
> The problem is that if my server sends back 100-continue, HttpClient
complaints about,
> "INFO: Discarding unexpected response: HTTP/1.1 100 Continue".
> 
> Here is sample code:
>           String testURL="http://localhost:8080/testci/index";
>           HttpClient client = new HttpClient();
>           
>           PutMethod put = new PutMethod(url);
>           put.setUseExpectHeader(true);
>           int statusCode = client.executeMethod(put);
>           
>           
>           if(statusCode==100){
>               System.out.println("server response is 100!");
>               put.setRequestBody(new
FileInputStream("test.txt"));
>           }
> ----------------------------
> 
> It looks like i am making some mistake.... Can some one shed some light
here?
> 

Uday,

HTTP agents are not supposed to return 1xx status codes to the caller.
These are special purpose codes that are meant to be used internally
Just let HttpClient handle the expect-continue handshaking.  

http://hc.apache.org/httpclient-3.x/performance.html#Expect-continue_handshake

You can see exactly what gets transferred across the wire by turning on
the wire logging on the client side.

http://hc.apache.org/httpclient-3.x/logging.html

Hope this helps

Oleg


> Thanks,
> -Uday.
> 
> -------------------------
> 
> I do not blog but e-write:
> 
> http://uds-web.blogspot.com
> 
> 
>       


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


      

Re: PUT & Expect:100-continue

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2008-07-16 at 17:34 -0700, Uday Subbarayan wrote:
> Hi All,
>     I am having trouble in using HTTPClient 3.1 for PUT method w/ "Expect:100-Continue" header. 
> 
> My requirement is that,
> [1] client sends a PUT request to the server with header only using this Expect header and waits for the 100 response back from the server.
> [2] Then client sends the body, after it received the 100 status back from the server.
> 
> The problem is that if my server sends back 100-continue, HttpClient complaints about,
> "INFO: Discarding unexpected response: HTTP/1.1 100 Continue".
> 
> Here is sample code:
>           String testURL="http://localhost:8080/testci/index";
>           HttpClient client = new HttpClient();
>           
>           PutMethod put = new PutMethod(url);
>           put.setUseExpectHeader(true);
>           int statusCode = client.executeMethod(put);
>           
>           
>           if(statusCode==100){
>               System.out.println("server response is 100!");
>               put.setRequestBody(new FileInputStream("test.txt"));
>           }
> ----------------------------
> 
> It looks like i am making some mistake.... Can some one shed some light here?
> 

Uday,

HTTP agents are not supposed to return 1xx status codes to the caller.
These are special purpose codes that are meant to be used internally
Just let HttpClient handle the expect-continue handshaking.  

http://hc.apache.org/httpclient-3.x/performance.html#Expect-continue_handshake

You can see exactly what gets transferred across the wire by turning on
the wire logging on the client side.

http://hc.apache.org/httpclient-3.x/logging.html

Hope this helps

Oleg


> Thanks,
> -Uday.
> 
> -------------------------
> 
> I do not blog but e-write:
> 
> http://uds-web.blogspot.com
> 
> 
>       


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org