You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cxf.apache.org by "Jason Downey (JIRA)" <ji...@apache.org> on 2011/02/03 06:26:29 UTC

[jira] Created: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
----------------------------------------------------------------------------------------------------------

                 Key: CXF-3304
                 URL: https://issues.apache.org/jira/browse/CXF-3304
             Project: CXF
          Issue Type: Bug
          Components: JAX-RS
    Affects Versions: 2.3.2
         Environment: JDK 1.6

            Reporter: Jason Downey
            Priority: Minor
             Fix For: 2.3.3


I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.

POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().

This problem was not reproducible with GET.

Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Jason Downey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jason Downey updated CXF-3304:
------------------------------

    Attachment: cxf_jax_rs_post_401_bug_httpurlconnection.zip

> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: cxf_jax_rs_post_401_bug.zip, cxf_jax_rs_post_401_bug_httpurlconnection.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Sergey Beryozkin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12991190#comment-12991190 ] 

Sergey Beryozkin commented on CXF-3304:
---------------------------------------

I've debugged and I can see that HttpURLConnection is returning an empty stream, both for conn.getInputStream and conn.getErrorStream(), despite the fact the text is contained in the error response.

Can you please verify it on your own, first check that the server actually returns the text, using the tcptrace, and then check the streams explicitly, perhaps using Apache HttpClient or just useing HTTPURLConnection directly ?

I suspect it is just a strange error in the Java HTTPUrlConnection. I believe 401 is usually supposed to have no response body so it could be HTTPUrlConnection enforces it by ignoring the response text if any

cheers, Sergey  

> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: cxf_jax_rs_post_401_bug.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Issue Comment Edited: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Jason Downey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12992026#comment-12992026 ] 

Jason Downey edited comment on CXF-3304 at 2/8/11 4:27 PM:
-----------------------------------------------------------

As long as the HttpConduit was previously initialized, the workaround was fine. For the very first WebClient request, I found that I needed to manually register the ClientOnlyHTTPTransportFactory.

I've uploaded the final demo file illustrating this workaround.

      was (Author: jadowney):
    Final file illustrating workaround.
  
> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: WebClientTest.java, cxf_jax_rs_post_401_bug.zip, cxf_jax_rs_post_401_bug_httpurlconnection.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Sergey Beryozkin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12992467#comment-12992467 ] 

Sergey Beryozkin commented on CXF-3304:
---------------------------------------

Thanks for this test. It actually reminded me that AbstractClient had a code dealing a non-initialized ConduitSelector and it also let me resolve https://issues.apache.org/jira/browse/CXF-3124.

I've added the test, the relevant merge should be recorded here...




> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: WebClientTest.java, cxf_jax_rs_post_401_bug.zip, cxf_jax_rs_post_401_bug_httpurlconnection.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Sergey Beryozkin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12991336#comment-12991336 ] 

Sergey Beryozkin commented on CXF-3304:
---------------------------------------

Thanks for the comment but this is a different issue. HttpUrlConnection returns null for response and error streams and now the null stream is wrapped in an empty stream but the issue is about the response text available in the response body being lost, only in case of POSTs resulting in 401 - I believe it's an HTTPUrlConnection level issue.

> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: cxf_jax_rs_post_401_bug.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Resolved: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Sergey Beryozkin (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sergey Beryozkin resolved CXF-3304.
-----------------------------------

       Resolution: Not A Problem
    Fix Version/s: 2.4
         Assignee: Sergey Beryozkin

The reported side-effect with the text accompanying the 401 response is only visible if the chunking is enabled. Disabling the chunking (or possibly changing the default chunking threshold value) leads to an expected result.

> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Assignee: Sergey Beryozkin
>            Priority: Minor
>             Fix For: 2.4, 2.3.3
>
>         Attachments: WebClientTest.java, cxf_jax_rs_post_401_bug.zip, cxf_jax_rs_post_401_bug_httpurlconnection.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Sergey Beryozkin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12991469#comment-12991469 ] 

Sergey Beryozkin commented on CXF-3304:
---------------------------------------

Hi Jason - I'm clueless :-). CXF HTTP Conduit clearly shows me that after conn.getResponseCode() returns 401, conn.getErrorStream() is called next and it returns null. 

Can you give me a favor please and post a non-empty request and see if the text is lost or not ? I'm wandering may be it's something to do with the way HttpConduit handles empty post requests...

thanks  

> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: cxf_jax_rs_post_401_bug.zip, cxf_jax_rs_post_401_bug_httpurlconnection.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Jason Downey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12991805#comment-12991805 ] 

Jason Downey commented on CXF-3304:
-----------------------------------

Thanks for your hint about looking at HttpConduit. I set some break points there and found the suspect code. I'm not sure how to fix it though so I'll look to you for help on that :-)

The cause for my grief is in HttpConduit.prepare (lines 634 to 645 in 2.3.2's source). By default, csPolicy.isAllowChunking is true and this causes the HttpURLConnection.setChunkedStreamingMode to be set to -1. If it is set (as it currently is), havoc ensues. If setChunckedStreamingMode isn't set, getErrorStream works as it's supposed to. 

Now that we now what causes the issue, is there a way in WebClient to specify the HTTPClientPolicy for a request? I briefly looked at the methods and couldn't find any.

By the way, WebClient behaves the same whether or not there is actual data in the post. 





> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: cxf_jax_rs_post_401_bug.zip, cxf_jax_rs_post_401_bug_httpurlconnection.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Jason Downey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jason Downey updated CXF-3304:
------------------------------

    Attachment:     (was: cxf_jax_rs_post_401_bug_httpurlconnection.zip)

> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: cxf_jax_rs_post_401_bug.zip, cxf_jax_rs_post_401_bug_httpurlconnection.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Sergey Beryozkin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12991879#comment-12991879 ] 

Sergey Beryozkin commented on CXF-3304:
---------------------------------------

Hi Jason - thanks for spending the time on it and finding the cause of this issue. 
HttpURLConnection.setChunkedStreamingMode(-1) works well for the usual cases, so I guess what we can do is to configure the policy: either disable the chunking or set the chunkedStreamingMode to something different, to 2048 or similar...

You can do it like this:

WebClient.getConfig(client).getHttpConduit().getClient().setAllowChunking(false);

WebClient.getConfig(client).getHttpConduit().getClient().setChunkedStreamingMode(2048);


WebClient.getConfig(client) works for web clients and proxies.

So may be if you can confirm configuring the policy fixes the issue then we close this JIRA :-) ?


> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: cxf_jax_rs_post_401_bug.zip, cxf_jax_rs_post_401_bug_httpurlconnection.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Jason Downey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jason Downey updated CXF-3304:
------------------------------

    Attachment: cxf_jax_rs_post_401_bug.zip

> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: cxf_jax_rs_post_401_bug.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Jason Downey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12991449#comment-12991449 ] 

Jason Downey commented on CXF-3304:
-----------------------------------

The text is definitely returned to the client. I can see the error message using browser-based REST test tools such as RESTClient in FireFox.

I added more code to cxf_jax_rs_post_401_bug_httpurlconnection.zip to test HttpURLConnection directly and it worked. However, in order for the error message to appear in getErrorStream() I had to either 1) check the response code of the message first or 2) call getInputStream() (which results in a FileNotFoundException) and then call getErrorStream().

Would it be possible to do something similar in WebClient?

> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: cxf_jax_rs_post_401_bug.zip, cxf_jax_rs_post_401_bug_httpurlconnection.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Issue Comment Edited: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Sergey Beryozkin (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12991879#comment-12991879 ] 

Sergey Beryozkin edited comment on CXF-3304 at 2/8/11 10:03 AM:
----------------------------------------------------------------

Hi Jason - thanks for spending the time on it and finding the cause of this issue. 
HttpURLConnection.setChunkedStreamingMode(-1) works well for the usual cases, so I guess what we can do is to configure the policy: either disable the chunking or set the chunkedStreamingMode to something different, to 2048 or similar...

You can do it like this:

WebClient.getConfig(client).getHttpConduit().getClient().setAllowChunking(false);

or

WebClient.getConfig(client).getHttpConduit().getClient().setChunkedStreamingMode(2048);


WebClient.getConfig(client) works for web clients and proxies.

So may be if you can confirm configuring the policy fixes the issue then we close this JIRA :-) ?


      was (Author: sergey_beryozkin):
    Hi Jason - thanks for spending the time on it and finding the cause of this issue. 
HttpURLConnection.setChunkedStreamingMode(-1) works well for the usual cases, so I guess what we can do is to configure the policy: either disable the chunking or set the chunkedStreamingMode to something different, to 2048 or similar...

You can do it like this:

WebClient.getConfig(client).getHttpConduit().getClient().setAllowChunking(false);

WebClient.getConfig(client).getHttpConduit().getClient().setChunkedStreamingMode(2048);


WebClient.getConfig(client) works for web clients and proxies.

So may be if you can confirm configuring the policy fixes the issue then we close this JIRA :-) ?

  
> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: cxf_jax_rs_post_401_bug.zip, cxf_jax_rs_post_401_bug_httpurlconnection.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Jason Downey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jason Downey updated CXF-3304:
------------------------------

    Attachment: WebClientTest.java

Final file illustrating workaround.

> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: WebClientTest.java, cxf_jax_rs_post_401_bug.zip, cxf_jax_rs_post_401_bug_httpurlconnection.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Issue Comment Edited: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "Jason Downey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12991805#comment-12991805 ] 

Jason Downey edited comment on CXF-3304 at 2/8/11 5:20 AM:
-----------------------------------------------------------

Thanks for your hint about looking at HTTPConduit. I set some break points there and found the suspect code. I'm not sure how to fix it though so I'll look to you for help on that :-)

The cause for my grief is in HTTPConduit.prepare (lines 634 to 645 in 2.3.2's source). By default, csPolicy.isAllowChunking is true and this causes the HttpURLConnection.setChunkedStreamingMode to be set to -1. If it is set (as it currently is), havoc ensues. If setChunckedStreamingMode isn't set, getErrorStream works as it's supposed to. 

Now that we now what causes the issue, is there a way in WebClient to specify the HTTPClientPolicy for a request? I briefly looked at the methods and couldn't find any.

By the way, WebClient behaves the same whether or not there is actual data in the post. 





      was (Author: jadowney):
    Thanks for your hint about looking at HttpConduit. I set some break points there and found the suspect code. I'm not sure how to fix it though so I'll look to you for help on that :-)

The cause for my grief is in HttpConduit.prepare (lines 634 to 645 in 2.3.2's source). By default, csPolicy.isAllowChunking is true and this causes the HttpURLConnection.setChunkedStreamingMode to be set to -1. If it is set (as it currently is), havoc ensues. If setChunckedStreamingMode isn't set, getErrorStream works as it's supposed to. 

Now that we now what causes the issue, is there a way in WebClient to specify the HTTPClientPolicy for a request? I briefly looked at the methods and couldn't find any.

By the way, WebClient behaves the same whether or not there is actual data in the post. 




  
> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: cxf_jax_rs_post_401_bug.zip, cxf_jax_rs_post_401_bug_httpurlconnection.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (CXF-3304) WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text

Posted by "CXF User (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CXF-3304?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12991218#comment-12991218 ] 

CXF User commented on CXF-3304:
-------------------------------

This is just a FYI.
With JAX-WS we had similar situation with CXF 2.3.1 release which was patched in 2.3.2.
https://issues.apache.org/jira/browse/CXF-3249


> WebClient POST to a resource that returns 401 returns a blank InputStream when there's supposed to be text
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: CXF-3304
>                 URL: https://issues.apache.org/jira/browse/CXF-3304
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.3.2
>         Environment: JDK 1.6
>            Reporter: Jason Downey
>            Priority: Minor
>             Fix For: 2.3.3
>
>         Attachments: cxf_jax_rs_post_401_bug.zip
>
>
> I have two methods that return the same error message upon POST. The only difference is that one returns a 404 response status, the other returns a 401 response status.
> POSTing to the resource that returns 404 returns an InputStream containing the error message when you call Response.getEntity(). However, POSTing to the resource that returns 401 returns a blank InputStream when you call Response.getEntity().
> This problem was not reproducible with GET.
> Test case code attached. Launch the server using JettyServer. Then run the WebClient test in WebClientTest.

-- 
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira