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 org.jboss.resteasy.client.ClientRequest;
24 import org.jboss.resteasy.client.ClientResponse;
25 import com.woorea.openstack.base.client.OpenStackResponse;
27 import javax.ws.rs.core.MultivaluedMap;
28 import java.io.InputStream;
29 import java.util.HashMap;
32 public class RESTEasyResponse implements OpenStackResponse {
34 private ClientRequest client;
36 private ClientResponse response;
38 public RESTEasyResponse(ClientRequest client, ClientResponse response) {
40 this.response = response;
44 public <T> T getEntity(Class<T> returnType) {
45 return (T) response.getEntity(returnType);
49 public <T> T getErrorEntity(Class<T> returnType) {
50 return (T) response.getEntity(returnType);
54 public InputStream getInputStream() {
55 return new RESTEasyInputStream((InputStream) response.getEntity(InputStream.class), client.getExecutor());
59 public String header(String name) {
60 return response.getHeaders().getFirst(name).toString();
64 public Map<String, String> headers() {
65 Map<String, String> headers = new HashMap<>();
66 MultivaluedMap<String, Object> responseHeaders = response.getHeaders();
68 for (String key : responseHeaders.keySet()) {
69 headers.put(key, responseHeaders.getFirst(key).toString());