eclipse-ee4j / eclipse-ee4j/jersey
Jersey-client: No way to put non-retryable with digest auth
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
I see no way to put a stream or other non-retryable payload while using DIGEST auth. This is something we could do with Jersey 1.17 client.
Since digest requires a challenge-response, we have two choices for non-retryable payloads:
1) buffer the stream and send it with both the first and second request
2) make a separate auth-only request first to get the Authorization token then use it to put the non-retryable payload
I see no way to do either using Jersey/Jax-RS 2.17, even when using httpclient as the connector. httpclient offers AuthCache but I see no way to access that via Jersey/JAX-RS.
Am I right to consider it a MUST requirement for Jersey/JAX-RS to support digest auth and non-retryable payloads (such as InputStream)?
Here's the code that fails with "IOException: Stream closed". I'm testing it against MarkLogic server but any web service which supports digest would have the same problem.
```
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.RequestEntityProcessing;
import java.io.StringReader;
public class Jersey217Test {
public static void main(String[] args) {
String user = "admin";
String pass = "admin";
ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED);
Client client = ClientBuilder.newClient(clientConfig);
client.register(HttpAuthenticationFeature.digest(user, pass));
StringReader reader = new StringReader("test");
WebTarget connection = client.target("http://localhost:8000/v1/documents");
connection
.queryParam("uri", "test.txt")
.request((String) null)
.put(Entity.entity(reader, "text/plain"));
Response response = connection
.queryParam("uri", "test.txt")
.request("text/plain").get();
String body = response.readEntity(String.class);
System.out.println("Body=[" + body + "]");
}
}
```
#### Environment
java 1.8, Win8.1
#### Affected Versions
[2.17]
Contributor guide
Assessment
This issue has not been assessed yet.