cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jesse Pangburn (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CXF-5267) WebClient using POST with chunking enabled (the default) can't read 401 error response stream
Date Wed, 11 Sep 2013 21:10:54 GMT

    [ https://issues.apache.org/jira/browse/CXF-5267?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13764784#comment-13764784
] 

Jesse Pangburn commented on CXF-5267:
-------------------------------------

Do you mean write a similar test using Apache HttpClient?  That's what I thought at first,
but then the WebClient line is clearly CXF.  I don't build with Maven so not sure what to
do about the dependency part you mentioned.  So I just added the line you provided right before
my invoke method call, but it didn't change anything.

Converting to HttpClient is easy enough to try.  It didn't care whether chunked or not, in
both cases the 401 response stream was available and printed out from the following code as
one would hope:
{code}
    public static void main(String[] args) throws Exception {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("http://localhost:9005/raw/customers");
        List <NameValuePair> nvps = new ArrayList <NameValuePair>();
        nvps.add(new BasicNameValuePair("username", "vip"));
        nvps.add(new BasicNameValuePair("password", "secret"));
        UrlEncodedFormEntity requestEntity = new UrlEncodedFormEntity(nvps);
        requestEntity.setChunked(true);
        httpPost.setEntity(requestEntity);
        HttpResponse response2 = httpclient.execute(httpPost);

        BufferedReader in = null;
        try {
            System.out.println(response2.getStatusLine());
            HttpEntity entity2 = response2.getEntity();
            in = new BufferedReader(new InputStreamReader(
                    entity2.getContent()));
            String response;
            while ((response = in.readLine()) != null) {
                System.out.println(response);
            }
            // ensure it is fully consumed
            EntityUtils.consume(entity2);
        } finally {
            httpPost.releaseConnection();
        }
        
    }
{code}

Has there been some other movement within CXF to convert to using Apache's HttpClient?
                
> WebClient using POST with chunking enabled (the default) can't read 401 error response
stream
> ---------------------------------------------------------------------------------------------
>
>                 Key: CXF-5267
>                 URL: https://issues.apache.org/jira/browse/CXF-5267
>             Project: CXF
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.5.3, 2.7.5
>         Environment: Linux
>            Reporter: Jesse Pangburn
>            Priority: Minor
>
> If I use WebClient to POST a message to a server, then I can't read the 401 error response
stream.  If I use GET, then I can read the response stream just fine.  If I use a HTTPConduit
and disable chunking then I can read the response content just fine in all cases.
> Here's a short grid showing the tests I performed:
> ||GET/POST||chunking||return code||result||
> |GET|disabled|401|response message ok|
> |POST|disabled|401|response message ok|
> |POST|enabled (default)|401|response message BLANK!|
> |GET|enabled (default)|401|response message ok|
> |POST|enabled (default)|200|response message ok|
> Here's the code I'm using (requestStream and webClient are initialized above.  webClient
is a WebClient and requestStream is an InputStream.):
> {code:title=TestWSClient.java|borderStyle=solid}
> String requestMethod = "POST";
> InputStream responseStream = null;
> Response response = null;
> try{
> 	responseStream = webClient.invoke(requestMethod, requestStream, InputStream.class);
> } catch (Exception e){
> 	logger.log(Level.WARNING, "caught exception using webClient to call " + webClient.getCurrentURI().toString(),
e);
> }finally{
> 	// always assign the Response object
> 	response = webClient.getResponse();
> 	// if the response entity is a LoadingByteArrayOutputStream, then we can still grab
that response content
> 	try{
> 		Object entity = response.getEntity();
> 		if (entity instanceof ByteArrayInputStream){
> 			ByteArrayInputStream bais = (ByteArrayInputStream)entity;
> 			// the stream needs to be reset before we can really use it
> 			bais.reset();
> 			responseStream = bais;
> 		}
> 	}catch (Exception e){
> 		// darn, failed to get that response entity
> 	    logger.log(Level.WARNING, "tried to get response message despite webClient exception,
but failed", e);
> 		// nothing else we can do, at least Cloverleaf will get the 500 response code and error
is in the log
> 	}
> }
> {code}
> In the failure case, when I try to read (not shown) from the response stream I get a
"-1" indicating the stream is empty.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message