protected void executePut(final String uri, final StringRequestEntity entity) throws NeutronRestApiException { try { validateCredentials(); } catch (NeutronInvalidCredentialsException e) { throw new NeutronRestApiException("Invalid credentials!", e); } NeutronRestFactory factory = NeutronRestFactory.getInstance(); NeutronRestApi neutronRestApi = factory.getNeutronApi(PutMethod.class); PutMethod putMethod = (PutMethod) neutronRestApi.createMethod(url, uri); try { putMethod.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE); putMethod.setRequestEntity(entity); String encodedCredentials = encodeCredentials(); putMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials); neutronRestApi.executeMethod(putMethod); if (putMethod.getStatusCode() != HttpStatus.SC_OK) { String errorMessage = responseToErrorMessage(putMethod); putMethod.releaseConnection(); s_logger.error("Failed to update object : " + errorMessage); throw new NeutronRestApiException("Failed to update object : " + errorMessage); } } catch (NeutronRestApiException e) { s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } finally { putMethod.releaseConnection(); } }
protected String executePut(final String uri) throws NeutronRestApiException { try { validateCredentials(); } catch (NeutronInvalidCredentialsException e) { throw new NeutronRestApiException("Invalid credentials!", e); } NeutronRestFactory factory = NeutronRestFactory.getInstance(); NeutronRestApi neutronRestApi = factory.getNeutronApi(PutMethod.class); PutMethod putMethod = (PutMethod) neutronRestApi.createMethod(url, uri); try { String encodedCredentials = encodeCredentials(); putMethod.setRequestHeader("Authorization", "Basic " + encodedCredentials); neutronRestApi.executeMethod(putMethod); if (putMethod.getStatusCode() != HttpStatus.SC_OK) { String errorMessage = responseToErrorMessage(putMethod); putMethod.releaseConnection(); s_logger.error("Failed to update object : " + errorMessage); throw new NeutronRestApiException("Failed to update object : " + errorMessage); } return putMethod.getResponseBodyAsString(); } catch (NeutronRestApiException e) { s_logger.error("NeutronRestApiException caught while trying to execute HTTP Method on the Neutron Controller", e); throw new NeutronRestApiException("API call to Neutron Controller Failed", e); } catch (IOException e) { throw new NeutronRestApiException("Failed to load json response body", e); } finally { putMethod.releaseConnection(); } }
protected PutMethod internalCreateOrUpdate(String encodedHref, byte[] mimeContent) throws IOException { PutMethod putmethod = new PutMethod(encodedHref); putmethod.setRequestHeader("Translate", "f"); putmethod.setRequestHeader("Overwrite", "f"); if (etag != null) { putmethod.setRequestHeader("If-Match", etag); } if (noneMatch != null) { putmethod.setRequestHeader("If-None-Match", noneMatch); } putmethod.setRequestHeader("Content-Type", "message/rfc822"); putmethod.setRequestEntity(new ByteArrayRequestEntity(mimeContent, "message/rfc822")); try { httpClient.executeMethod(putmethod); } finally { putmethod.releaseConnection(); } return putmethod; }
post.setRequestHeader("Content-Encoding", "gzip"); post.setRequestHeader("Content-Type", "application/json");
void put(String xml, String url, String contentType) throws IOException { PutMethod putMethod = httpMethodProvider.putMethod(); putMethod.setRequestHeader(CONTENT_TYPE, contentType); putMethod.setRequestEntity(new StringRequestEntity(xml, contentType, UTF_8)); execute(url, putMethod, HttpStatus.SC_OK); }
/** * Execute the PUT method for the given path. * * @param path the server relative path to put the data * @param data The byte array. * @return true if the method is succeeded. * @exception HttpException * @exception IOException */ public boolean putMethod(String path, byte[] data) throws HttpException, IOException { setClient(); PutMethod method = new PutMethod(URIUtil.encodePathQuery(path)); generateIfHeader(method); if (getGetContentType() != null && !getGetContentType().equals("")) method.setRequestHeader("Content-Type", getGetContentType()); method.setRequestHeader("Content-Length", String.valueOf(data.length)); method.setRequestBody(new ByteArrayInputStream(data)); generateTransactionHeader(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return (statusCode >= 200 && statusCode < 300) ? true : false; }
/** * Execute the PUT method for the given path from the given url. * * @param path the server relative path to put the data * @param url The URL to get a resource. * @return true if the method is succeeded. * @exception HttpException * @exception IOException */ public boolean putMethod(String path, URL url) throws HttpException, IOException { setClient(); PutMethod method = new PutMethod(URIUtil.encodePathQuery(path)); generateIfHeader(method); if (getGetContentType() != null && !getGetContentType().equals("")) method.setRequestHeader("Content-Type", getGetContentType()); method.setRequestBody(url.openStream()); generateTransactionHeader(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return (statusCode >= 200 && statusCode < 300) ? true : false; }
/** * Execute the PUT method for the given path. * * @param path the server relative path to put the given file * @param file the filename to get on local. * @return true if the method is succeeded. * @exception HttpException * @exception IOException */ public boolean putMethod(String path, File file) throws HttpException, IOException { setClient(); PutMethod method = new PutMethod(URIUtil.encodePathQuery(path)); generateIfHeader(method); if (getGetContentType() != null && !getGetContentType().equals("")) method.setRequestHeader("Content-Type", getGetContentType()); long fileLength = file.length(); method.setRequestContentLength(fileLength <= Integer.MAX_VALUE ? (int) fileLength : PutMethod.CONTENT_LENGTH_CHUNKED); method.setRequestBody(new FileInputStream(file)); generateTransactionHeader(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return (statusCode >= 200 && statusCode < 300) ? true : false; }
/** * Execute the PUT method for the given path. * * @param path the server relative path to put the data * @param data String to send. * @return true if the method is succeeded. * @exception HttpException * @exception IOException */ public boolean putMethod(String path, String data) throws HttpException, IOException { setClient(); PutMethod method = new PutMethod(URIUtil.encodePathQuery(path)); generateIfHeader(method); if (getGetContentType() != null && !getGetContentType().equals("")) method.setRequestHeader("Content-Type", getGetContentType()); method.setRequestBody(data); generateTransactionHeader(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return (statusCode >= 200 && statusCode < 300) ? true : false; }
/** * Execute the PUT method for the given path. * * @param path the server relative path to put the data * @param is The input stream. * @return true if the method is succeeded. * @exception HttpException * @exception IOException */ public boolean putMethod(String path, InputStream is) throws HttpException, IOException { setClient(); PutMethod method = new PutMethod(URIUtil.encodePathQuery(path)); generateIfHeader(method); if (getGetContentType() != null && !getGetContentType().equals("")) method.setRequestHeader("Content-Type", getGetContentType()); method.setRequestContentLength(PutMethod.CONTENT_LENGTH_CHUNKED); method.setRequestBody(is); generateTransactionHeader(method); int statusCode = client.executeMethod(method); setStatusCode(statusCode); return (statusCode >= 200 && statusCode < 300) ? true : false; }
putmethod.setRequestHeader("Translate", "f"); putmethod.setRequestHeader("Content-Type", "message/rfc822");
putmethod.setRequestHeader("Overwrite", "t"); putmethod.setRequestHeader("Content-Type", "image/jpeg"); putmethod.setRequestEntity(new ByteArrayRequestEntity(resizedImageBytes, "image/jpeg"));
putMethod.setRequestHeader(HTTPConstants.HEADER_SOAP_ACTION, soapAction);