/** * Performs a HTTP PUT request, saves an attachment. * * @return {@link Response} */ Response put(URI uri, InputStream instream, String contentType) { HttpResponse response = null; try { HttpPut httpPut = new HttpPut(uri); InputStreamEntity entity = new InputStreamEntity(instream, -1); entity.setContentType(contentType); httpPut.setEntity(entity); response = executeRequest(httpPut); return getResponse(response); } finally { close(response); } }
/** * Sends a POST request and returns the response. * * @param endpoint The endpoint to send the request to. * @param requestMessage A message to send in the request body. Can be null. * @param responseClass The class to deserialise the Json response to. Can be null if no response * message is expected. * @param headers Any additional headers to send with this request. You can use {@link * org.apache.http.HttpHeaders} constants for header names. * @param <T> The type to deserialise the response to. * @return A {@link Response} containing the deserialised body, if any. * @throws IOException If an error occurs. */ public <T> Response<T> put( Endpoint endpoint, Object requestMessage, Class<T> responseClass, NameValuePair... headers) throws IOException { // Create the request HttpPut put = new HttpPut(endpoint.url()); put.setHeaders(combineHeaders(headers)); // Add the request message if there is one put.setEntity(serialiseRequestMessage(requestMessage)); // Send the request and process the response try (CloseableHttpResponse response = httpClient().execute(put)) { T body = deserialiseResponseMessage(response, responseClass); return new Response<>(response.getStatusLine(), body); } }