try {
MediaType contentType = MediaType.valueOf(request.getContentType().getMediaString());
// Jersey does not allow entity value to be null.
Object content = request.getContent() != null ? request.getContent() : "";
Entity entity = Entity.entity(content, contentType);
WebTarget webTarget = newWebTarget(request.getPath());
for (HttpQueryParam queryParam : request.getQueryParameters()) {
webTarget = webTarget.queryParam(queryParam.getName(), queryParam.getValue());
}