001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * André Justo 016 */ 017 018package org.nuxeo.ecm.media.publishing.wistia.rest; 019 020import com.sun.jersey.api.client.ClientResponse; 021import org.codehaus.jackson.JsonNode; 022import org.codehaus.jackson.map.ObjectMapper; 023 024import java.io.IOException; 025 026public class RestResponse { 027 028 protected ClientResponse clientResponse; 029 030 protected JsonNode responseAsJson; 031 032 protected ObjectMapper objectMapper = new ObjectMapper(); 033 034 public RestResponse(ClientResponse clientResponse) { 035 this.clientResponse = clientResponse; 036 } 037 038 public ClientResponse getClientResponse() { 039 return this.clientResponse; 040 } 041 042 public int getStatus() { 043 return this.clientResponse.getStatus(); 044 } 045 046 public JsonNode asJson() { 047 if (responseAsJson == null) { 048 try { 049 responseAsJson = objectMapper.readTree(clientResponse.getEntityInputStream()); 050 } catch (IOException e) { 051 throw new RuntimeException(e); 052 } 053 } 054 return responseAsJson; 055 } 056}