You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 28, 2018. It is now read-only.
@groovy.lang.Grab('com.sun.jersey:jersey-bundle:1.19.1')
importcom.sun.jersey.api.client.Clientimportcom.sun.jersey.api.client.ClientHandlerExceptionimportcom.sun.jersey.api.client.ClientRequestimportcom.sun.jersey.api.client.ClientResponseimportcom.sun.jersey.api.client.UniformInterfaceExceptionimportcom.sun.jersey.api.client.filter.ClientFilter// If PUT or POST request with any payload will cause 401 response// then ClientFilter in Jersey 1.* is not able to get response// body.// Run with: $ groovy jersey-1.19.1-PUT-401-bug.groovy// Require: nc - unix netcat utility// Setup serverdef responseFile =File.createTempFile("test-nc-response", ".txt")
responseFile.text ="""HTTP/1.1 401 UnauthorizedContent-length: 8Connection: closeContent-Type: text/plainresponse"""def nc =newProcessBuilder('nc', '-l', '5530')
.redirectInput(responseFile)
.start()
// Setup client with filter to catch response bodydef responseBody =nulldef client =Client.newInstance()
client.addFilter(newClientFilter() {
ClientResponsehandle(ClientRequestcr) throwsClientHandlerException {
def response = getNext().handle(cr)
responseBody = response.getEntity(String.class)
return response;
}
})
try {
client.resource("http://localhost:5530")
.put(String.class, "".getBytes())
thrownewRuntimeException(".put() call expected to throw UniformInterfaceException because of 401 response, but it did not!")
} catch (UniformInterfaceException e) {
assert"PUT http://localhost:5530 returned a response status of 401 Unauthorized"== e.getMessage()
}
nc.waitFor()
responseFile.delete()
assert"response"== responseBody
println"OK!"
file
jersey-1.19.1-PUT-401-bug.groovy
Expected to output
OK!
, but fails withThe text was updated successfully, but these errors were encountered: