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 was archived by the owner on May 28, 2018. It is now read-only.
Repository navigation
This repository was archived by the owner on May 28, 2018. It is now read-only.
Empty response body from 401 response caused by PUT with payload. Jersey 1.19.1. #3776
@groovy.lang.Grab('com.sun.jersey:jersey-bundle:1.19.1')
import com.sun.jersey.api.client.Client
import com.sun.jersey.api.client.ClientHandlerException
import com.sun.jersey.api.client.ClientRequest
import com.sun.jersey.api.client.ClientResponse
import com.sun.jersey.api.client.UniformInterfaceException
import com.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 server
def responseFile = File.createTempFile("test-nc-response", ".txt")
responseFile.text = """HTTP/1.1 401 Unauthorized
Content-length: 8
Connection: close
Content-Type: text/plain
response"""
def nc = new ProcessBuilder('nc', '-l', '5530')
.redirectInput(responseFile)
.start()
// Setup client with filter to catch response body
def responseBody = null
def client = Client.newInstance()
client.addFilter(new ClientFilter() {
ClientResponse handle(ClientRequest cr) throws ClientHandlerException {
def response = getNext().handle(cr)
responseBody = response.getEntity(String.class)
return response;
}
})
try {
client.resource("http://localhost:5530")
.put(String.class, "".getBytes())
throw new RuntimeException(".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!"
Activity
jansupol commentedon Feb 23, 2018
This is actually Jersey 2 Issue tracker. For Jersey 1.x (https://github.com/jersey/jersey-1.x), there is currently no plan on a new release.