public void unpublishContent(String queryString) { try { HttpResponse response = httpClient.delete(queryString); if (response.statusCode() >= 400) { throw new BadResponseException( String.format( "DELETE %s: %s %s", queryString, response.statusCode(), response.statusLine())); } } catch (HttpException e) { throw new RuntimeException(String.format("%s", queryString), e); } }
public void putPerson(String queryString, Person person) { try { StringPayload data = new StringPayload(gson.get().toJson(person)); HttpResponse response = httpClient.put(queryString, data); if (response.statusCode() >= 400) { throw new BadResponseException( String.format( "PUT %s %s: %s %s", person.getUri(), person.getPublisher(), response.statusCode(), response.statusLine())); } } catch (HttpException e) { throw new RuntimeException( String.format("%s %s %s", queryString, person.getUri(), person.getPublisher()), e); } }
@Override public ContentResponse putPlaylist(String query, Playlist playlist) { try { String json = gson.get().toJson(playlist); Payload httpBody = new StringPayload(json); HttpResponse resp = httpClient.put(query, httpBody); if (resp.statusCode() >= 400) { throw new BadResponseException( "Error PUTting item: HTTP " + resp.statusCode() + " received from Atlas"); } WriteResponseWrapper responseWrapper = gson.get().fromJson(resp.body(), WriteResponseWrapper.class); return new ContentResponse(responseWrapper.getAtlasResponse(), resp.header(LOCATION)); } catch (HttpException e) { throw Throwables.propagate(e); } }
private Element getResultElement(HttpResponse res) throws ICTomorrowApiException { try { Builder builder = new Builder(); Document document = builder.build(res.body(), null); Element rootElement = document.getRootElement(); String statusCode = rootElement.getAttributeValue("status_code"); String statusMessage = rootElement.getAttributeValue("status_message"); if (statusCode.equals("200")) { return rootElement; } else { throw new ICTomorrowApiException( "Request returned an error response: " + res.body(), statusCode, statusMessage); } } catch (ParsingException e) { throw new ICTomorrowApiException("Exception while parsing response: " + res.body(), e); } catch (IOException e) { throw new ICTomorrowApiException("Exception while parsing response: " + res.body(), e); } }
@Override public TopicUpdateResponse postTopic(String queryUri, Topic topic) { try { Payload topicPayload = new StringPayload(gson.get().toJson(topic, Topic.class)); HttpResponse response = httpClient.post(queryUri, topicPayload); if (response.statusCode() >= 400) { throw new BadResponseException( "Error POSTing topic " + topic.getTitle() + " " + topic.getNamespace() + " " + topic.getValue() + " code: " + response.statusCode() + ", message: " + response.statusLine()); } WriteResponseWrapper responseWrapper = gson.get().fromJson(response.body(), WriteResponseWrapper.class); return new TopicUpdateResponse( responseWrapper.getAtlasResponse().getId(), response.header(LOCATION)); } catch (Exception e) { throw new RuntimeException(e); } }