All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.woorea.openstack.connector.JaxRs20Response Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. This code is licensed under the Apache License, Version 2.0
 *******************************************************************************/

package com.woorea.openstack.connector;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.core.Response;

import com.woorea.openstack.base.client.OpenStackResponse;
import com.woorea.openstack.base.client.OpenStackResponseException;

/**
 * 

Revisions

*
*
8/3/2015
*
Added reference to response object to exception
*
*/ public class JaxRs20Response implements OpenStackResponse { private Response response; public JaxRs20Response(Response response) { this.response = response; } /** * @see com.woorea.openstack.base.client.OpenStackResponse#getEntity(java.lang.Class) */ @Override public T getEntity(Class returnType) throws OpenStackResponseException { if(response.getStatus() >= 400) { throw new OpenStackResponseException(response.getStatusInfo().getReasonPhrase(), response.getStatusInfo().getStatusCode(), this); } return response.readEntity(returnType); } @Override public T getErrorEntity(Class returnType) { if(response.getStatus() >= 400 && response.hasEntity()) { return response.readEntity(returnType); } return null; } @Override public InputStream getInputStream() { return (InputStream) response.getEntity(); } @Override public String header(String name) { return response.getHeaderString(name); } @Override public Map headers() { Map headers = new HashMap(); for(String k : response.getHeaders().keySet()) { headers.put(k, response.getHeaderString(k)); } return headers; } @Override public int getStatus() { return response.getStatus(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy