File localFile = new File(localFilePath); RequestEntity requestEntity = new FileRequestEntity(localFile, "application/binary"); redirectedReq.setRequestEntity(requestEntity);
public static PutMethod sendMultipartPutRequest(String url, String body) throws IOException { HttpClient httpClient = new HttpClient(); PutMethod putMethod = new PutMethod(url); // our handlers ignore key...so we can put anything here Part[] parts = {new StringPart("body", body)}; putMethod.setRequestEntity(new MultipartRequestEntity(parts, putMethod.getParams())); httpClient.executeMethod(putMethod); return putMethod; } }
protected <T> String executeUpdateObject(final T newObject, final String uri, final Map<String, String> parameters) throws BigSwitchBcfApiException, IllegalArgumentException{ checkInvariants(); PutMethod pm = (PutMethod)createMethod("put", uri, _port); setHttpHeader(pm); try { pm.setRequestEntity(new StringRequestEntity(gson.toJson(newObject), CONTENT_JSON, null)); } catch (UnsupportedEncodingException e) { throw new BigSwitchBcfApiException("Failed to encode json request body", e); } executeMethod(pm); String hash = checkResponse(pm, "BigSwitch HTTP update failed: "); pm.releaseConnection(); return hash; }
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(); } }
@Override protected void setup(PutMethod method) throws SwiftInternalStateException { method.setRequestEntity(new InputStreamRequestEntity(data, length)); setHeaders(method, requestHeaders); } });
PutMethod put = new PutMethod(url); put.setRequestEntity(new FileRequestEntity(localFile, contentType)); int responseCode = put.executeMethod();
protected PutMethod executePut(String uri, InputStream content, String mediaType, int... expectedCodes) throws Exception { PutMethod putMethod = new PutMethod(uri); RequestEntity entity = new InputStreamRequestEntity(content, mediaType); putMethod.setRequestEntity(entity); int code = this.adminHTTPClient.executeMethod(putMethod); if (!ArrayUtils.contains(expectedCodes, code)) { throw new Exception("Failed to execute put [" + uri + "] with code [" + code + "]"); } return putMethod; } }
/** Upload a file to the Sling repository * @return the HTTP status code */ public int upload(String toUrl, InputStream is) throws IOException { final PutMethod put = new PutMethod(toUrl); put.setRequestEntity(new InputStreamRequestEntity(is)); return httpClient.executeMethod(put); }
private PutMethod createPutMethod(String uriPrefix) { putMethod = new PutMethod(uriPrefix); putMethod.setRequestEntity(entity); if (cancellationRequested.get()) { putMethod.abort(); // next method will throw an exception } return putMethod; } }
/** * @since 7.3M1 */ protected PutMethod executePut(String uri, InputStream content, String mediaType) throws Exception { PutMethod putMethod = new PutMethod(uri); RequestEntity entity = new InputStreamRequestEntity(content, mediaType); putMethod.setRequestEntity(entity); this.httpClient.executeMethod(putMethod); return putMethod; }
/** * Factory method to create a {@link PutMethod} object. * * @param uri URI to upload <code>uploadFile</code> to * @param uploadFile {@link File} to be uploaded * @return a {@link PutMethod} instance * @exception IOException if an error occurs */ private PutMethod createPutMethod( final String uri, final File uploadFile ) throws IOException { final PutMethod put = new PutMethod( uri ); put.setRequestEntity(new InputStreamRequestEntity( new FileInputStream( uploadFile.getAbsolutePath() ))); return put; }
/** * WebDav transfers a local directory to the remote GDC WebDav server * * @param archiveName the name of the ZIP archive that is going to be transferred * @throws java.io.IOException in case of IO issues */ public void transferDir(String archiveName) throws IOException { l.debug("Transfering archive " + archiveName); File file = new File(archiveName); String dir = file.getName().split("\\.")[0]; MkColMethod mkdir = new MkColMethod(webdavURL.toString() + "/" + dir); executeMethodOk(mkdir); PutMethod put = new PutMethod(webdavURL.toString() + "/" + dir + "/" + DEFAULT_ARCHIVE_NAME); FileInputStream fis = new FileInputStream(file); RequestEntity requestEntity = new InputStreamRequestEntity(fis); put.setRequestEntity(requestEntity); executeMethodOk(put); fis.close(); l.debug("Transferred archive " + archiveName); }
public void uploadFile(BintrayPackage bintrayPackage, String targetPath, File file, String version, String contentType){ String url = String.format("https://api.bintray.com/content/%s/%s/%s/%s/%s?publish=1", bintrayPackage.getOwner(), bintrayPackage.getRepository(), bintrayPackage.getName(), version, targetPath); PutMethod put = new PutMethod(url); assertAuthorized(); put.addRequestHeader("Authorization", "Basic "+ new String(Base64.encodeBase64((username+":"+password).getBytes()))); put.setRequestEntity(new FileRequestEntity(file, contentType)); try{ new HttpClient().executeMethod(put); validateAuthorizedRequestResult(bintrayPackage.getOwner(), put, 201); } catch (Exception e) { throw new RuntimeException("Failed to upload files to package: "+bintrayPackage.getName(), e); } }
public String executePut(String url, Map<String, String> parameters, IProgressMonitor monitor) throws ReviewboardException { PutMethod putMethod = new PutMethod(stripSlash(location.getUrl()) + url); configureRequestForJson(putMethod); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); for ( Map.Entry<String, String> entry : parameters.entrySet() ) pairs.add(new NameValuePair(entry.getKey(), entry.getValue())); putMethod.setQueryString(pairs.toArray(new NameValuePair[0])); String queryString = putMethod.getQueryString(); putMethod.setQueryString(""); try { putMethod.setRequestEntity(new StringRequestEntity(queryString, null, "UTF-8")); } catch (UnsupportedEncodingException e) { throw new ReviewboardException(e.getMessage(), e); } return executeMethod(putMethod, monitor); }
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); }
void setcontent() { switch (this.methodclass) { case Put: if(this.content != null) ((PutMethod) method).setRequestEntity(this.content); break; case Post: if(multiparts != null && multiparts.length > 0) { MultipartRequestEntity mre = new MultipartRequestEntity(multiparts, method.getParams()); ((PostMethod) method).setRequestEntity(mre); } else if(this.content != null) ((PostMethod) method).setRequestEntity(this.content); break; case Head: case Get: case Options: default: break; } this.content = null; // do not reuse this.multiparts = null; }
public void put(String url, Header[] headers, NameValuePair[] params, RequestEntity requestEntity, AGResponseHandler handler) throws AGHttpException { PutMethod put = new PutMethod(url); setDoAuthentication(put); if (headers != null) { for (Header header : headers) { put.addRequestHeader(header); } } if (params != null) { put.setQueryString(params); } if (requestEntity != null) { put.setRequestEntity(requestEntity); } executeMethod(url, put, handler); }
public ApplicationServerManagerResult deploy(String appPath, InputStream is, int size) throws IOException { try { deploy.setQueryString(buildPathQueryArgs(appPath)); deploy.setContentChunked(true); deploy.setRequestEntity(new InputStreamRequestEntity(is)); client.executeMethod(deploy); return parseResult(deploy.getResponseBodyAsString()); } finally { deploy.releaseConnection(); deploy.setPath(deployPath); } }
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; }
public void upload(File src, URL dest, CopyProgressListener l) throws IOException { HttpClient client = getClient(); PutMethod put = new PutMethod(normalizeToString(dest)); put.setDoAuthentication(useAuthentication(dest) || useProxyAuthentication()); put.getParams().setBooleanParameter("http.protocol.expect-continue", true); try { put.setRequestEntity(new FileRequestEntity(src)); int statusCode = client.executeMethod(put); validatePutStatusCode(dest, statusCode, null); } finally { put.releaseConnection(); } }