Jesse Pangburn created CXF-5267: ----------------------------------- Summary: 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.7.5, 2.5.3 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