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

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

/*******************************************************************************
 * Copyright (C) 2016 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 com.sun.jersey.api.client.ClientResponse;
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 JerseyResponse implements OpenStackResponse { private ClientResponse response; public JerseyResponse(ClientResponse 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.getClientResponseStatus().getReasonPhrase(), response.getStatus(), this); } if(response.hasEntity() && returnType != null && Void.class != returnType) { return response.getEntity(returnType); } return null; } @Override public T getErrorEntity(Class returnType) { if(response.getStatus() >= 400 && response.hasEntity()) { return response.getEntity(returnType); } return null; } @Override public InputStream getInputStream() { if(response.hasEntity()) { return response.getEntityInputStream(); } return null; } @Override public String header(String name) { return response.getHeaders().getFirst(name); } @Override public Map headers() { Map headers = new HashMap(); for(String k : response.getHeaders().keySet()) { headers.put(k, response.getHeaders().getFirst(k)); } return headers; } @Override public int getStatus() { return response.getStatus(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy