2 * ============LICENSE_START=======================================================
\r
3 * Licensed under the Apache License, Version 2.0 (the "License");
\r
4 * you may not use this file except in compliance with the License.
\r
5 * You may obtain a copy of the License at
\r
7 * http://www.apache.org/licenses/LICENSE-2.0
\r
9 * Unless required by applicable law or agreed to in writing, software
\r
10 * distributed under the License is distributed on an "AS IS" BASIS,
\r
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 * See the License for the specific language governing permissions and
\r
13 * limitations under the License.
\r
14 * ============LICENSE_END=========================================================
\r
17 package com.woorea.openstack.connector;
\r
20 * Modifications copyright (c) 2017 AT&T Intellectual Property
\r
23 import java.io.InputStream;
\r
24 import java.util.HashMap;
\r
25 import java.util.Map;
\r
27 import com.sun.jersey.api.client.ClientResponse;
\r
28 import com.woorea.openstack.base.client.OpenStackResponse;
\r
29 import com.woorea.openstack.base.client.OpenStackResponseException;
\r
31 public class JerseyResponse implements OpenStackResponse {
\r
33 private ClientResponse response;
\r
35 public JerseyResponse(ClientResponse response) {
\r
36 this.response = response;
\r
40 public <T> T getEntity(Class<T> returnType) {
\r
41 if(response.getStatus() >= 400) {
\r
42 throw new OpenStackResponseException(response.getClientResponseStatus().getReasonPhrase(),
\r
43 response.getStatus(), this);
\r
45 if(response.hasEntity() && returnType != null && Void.class != returnType) {
\r
46 return response.getEntity(returnType);
\r
53 public <T> T getErrorEntity(Class<T> returnType) {
\r
54 if(response.getStatus() >= 400 && response.hasEntity()) {
\r
55 return response.getEntity(returnType);
\r
61 public InputStream getInputStream() {
\r
62 if(response.hasEntity()) {
\r
63 return response.getEntityInputStream();
\r
70 public String header(String name) {
\r
71 return response.getHeaders().getFirst(name);
\r
75 public Map<String, String> headers() {
\r
76 Map<String, String> headers = new HashMap<String, String>();
\r
77 for(String k : response.getHeaders().keySet()) {
\r
78 headers.put(k, response.getHeaders().getFirst(k));
\r