2 * ============LICENSE_START=======================================================
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 * ============LICENSE_END=========================================================
17 package com.woorea.openstack.connector;
20 * Modifications copyright (c) 2017 AT&T Intellectual Property
23 import java.io.InputStream;
24 import java.util.HashMap;
27 import javax.ws.rs.core.Response;
29 import com.woorea.openstack.base.client.OpenStackResponse;
30 import com.woorea.openstack.base.client.OpenStackResponseException;
32 public class JaxRs20Response implements OpenStackResponse {
34 private Response response;
36 public JaxRs20Response(Response response) {
37 this.response = response;
41 public <T> T getEntity(Class<T> returnType) {
42 if(response.getStatus() >= 400) {
43 throw new OpenStackResponseException(response.getStatusInfo().getReasonPhrase(),
44 response.getStatusInfo().getStatusCode(), this);
46 return response.readEntity(returnType);
50 public <T> T getErrorEntity(Class<T> returnType) {
51 if(response.getStatus() >= 400 && response.hasEntity()) {
52 return response.readEntity(returnType);
59 public InputStream getInputStream() {
60 return (InputStream) response.getEntity();
64 public String header(String name) {
65 return response.getHeaderString(name);
69 public Map<String, String> headers() {
70 Map<String, String> headers = new HashMap<>();
71 for(String k : response.getHeaders().keySet()) {
72 headers.put(k, response.getHeaderString(k));