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; } }
public String doPut(String url, String charset, String jsonObj) { String resStr = null; HttpClient htpClient = new HttpClient(); PutMethod putMethod = new PutMethod(url); putMethod.getParams().setParameter( HttpMethodParams.HTTP_CONTENT_CHARSET, charset); try { putMethod.setRequestEntity(new StringRequestEntity(jsonObj, "application/json", charset)); int statusCode = htpClient.executeMethod(putMethod); if (statusCode != HttpStatus.SC_OK) { log.error("Method failed: " + putMethod.getStatusLine()); return null; } byte[] responseBody = putMethod.getResponseBody(); resStr = new String(responseBody, charset); } catch (Exception e) { log.error(e.getMessage(),e); } finally { putMethod.releaseConnection(); } return resStr; } }
@NotNull @Override public TomcatResult deployApplication(@NotNull final String contextPath, @Nullable final String version, @NotNull final String deploymentTag, @NotNull final File file) throws IOException { final FileInputStream inputStream = new FileInputStream(file); try { final StringBuilder urlBuilder = new StringBuilder(tomcatManagerUrl) .append(getURLPrefix()) .append("/deploy?path=") .append(encode(customVariableContext.substituteString(contextPath))); if (version != null) { urlBuilder.append("&version=") .append(encode(customVariableContext.substituteString(version))); } urlBuilder.append("&update=true&tag=") .append(encode(customVariableContext.substituteString(deploymentTag))); final PutMethod putMethod = new PutMethod(urlBuilder.toString()); putMethod.setRequestEntity(new InputStreamRequestEntity(inputStream, file.length())); // BAM-14883 InputStreamRequestEntity with length specified cannot be retried. putMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false)); final String result = execute(putMethod); return TomcatResult.parse(result); } finally { IOUtils.closeQuietly(inputStream); } }
protected void put(String path, NameValuePair[] data) { PutMethod req = new PutMethod(path); req.setRequestBody(EncodingUtil.formUrlEncode(data, "utf-8")); req.getParams().setContentCharset("utf-8"); send(req); }
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(); } }