client = Client.create(clientConfig);
}
@Override
public <T> OpenStackResponse request(OpenStackRequest<T> request) {
WebResource target = client.resource(request.endpoint()).path(request.path());
for(Map.Entry<String, List<Object> > entry : request.queryParams().entrySet()) {
for (Object o : entry.getValue()) {
target = target.queryParam(entry.getKey(), String.valueOf(o));
}
}
target.addFilter(logger);
MultivaluedMap<String, Object> headers = new OutBoundHeaders();
for(Map.Entry<String, List<Object>> h : request.headers().entrySet()) {
for(Object v : h.getValue()) {
headers.add(h.getKey(), v);
}
}
if(request.entity() != null && request.entity().getContentType() != null) {
headers.add("Content-Type", request.entity().getContentType());
} else {
headers.add("Content-Type", "application/json");
}
try {
ClientResponse response = null;
if (request.entity() != null && request.entity().getEntity() != null) {
response = target.getHeadHandler().handle(new ClientRequestImpl(target.getURI(), request.method().name(), request.entity().getEntity(), headers));
} else {
response = target.getHeadHandler().handle(new ClientRequestImpl(target.getURI(), request.method().name(), null, headers));
}
return new JerseyResponse(response);
} catch (UniformInterfaceException e) {
throw new OpenStackResponseException(e.getResponse().getClientResponseStatus().getReasonPhrase(), e.getResponse().getStatus());
}