I have \"users\" resource defined as follows:
@Path(\"/api/users\")
public class UserResource {
@POST
@Consumes(MediaType.APPLICATION_JSON)
publ
Follow redirects means following 30x status code redirects. What you have there is a 201 response, that is not a redirect. You can write a ClientFilter that will follow the location header if 201 is returned.
I was facing the same issue and resolved it by following client filter
package YourPackageName;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientResponseContext;
import javax.ws.rs.client.ClientResponseFilter;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.InputStream;
public class RedirectFilterWorkAround implements ClientResponseFilter {
@Override
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
if (responseContext.getStatusInfo().getFamily() != Response.Status.Family.REDIRECTION)
return;
Response resp = requestContext.getClient().target(responseContext.getLocation()).request().method(requestContext.getMethod());
responseContext.setEntityStream((InputStream) resp.getEntity());
responseContext.setStatusInfo(resp.getStatusInfo());
responseContext.setStatus(resp.getStatus());
}
}
Now while in other class where you are creating Client as
Client client = ClientBuilder.newClient();
Apply this filter class as
client.register(RedirectFilterWorkAround.class);
This is working with Jersey 2.x Found these pointers on SO :p