private HttpPut createPut(final String path) { final URI url = getUri(path); final HttpPut put = new HttpPut(url); put.setConfig(getRequestConfig()); return put; }
JsonObject httpPut(String url, String body, User registrar) throws Exception { String authHTTPCert = getHTTPAuthCertificate(registrar.getEnrollment(), "PUT", url, body); String putURL = addCAToURL(url); HttpPut httpPut = new HttpPut(putURL); httpPut.setConfig(getRequestConfig()); logger.debug(format("httpPutt %s, body:%s, authHTTPCert: %s", url, body, authHTTPCert)); final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); if (registry != null) { httpClientBuilder.setConnectionManager(new PoolingHttpClientConnectionManager(registry)); } HttpClient client = httpClientBuilder.build(); final HttpClientContext context = HttpClientContext.create(); httpPut.setEntity(new StringEntity(body)); httpPut.addHeader("Authorization", authHTTPCert); HttpResponse response = client.execute(httpPut, context); return getResult(response, body, "PUT"); }
HttpPut httpPut = new HttpPut("..."); httpPut.setConfig(requestConfig); ... HttpClientContext context = HttpClientContext.create(); .... httpclient.execute(httpPut, context);
private HttpPut createPutRequest(String command, String deploymentId, String packageId, String unitId, byte[] payload) { StringBuilder sb = new StringBuilder("/"); sb.append(deploymentId).append("/"); if (!"clean".equals(command)) { sb.append("packages").append("/").append(packageId).append("/"); sb.append("units").append("/").append(unitId != null ? unitId + "/" : ""); } String paramsPart = sb.toString(); URIBuilder uriBuilder = getUriBuilder(); String path = String.format("/%s%s%s", PATH_ROOT, paramsPart, command); uriBuilder.setPath(path); URI uri; try { uri = uriBuilder.build(); } catch (URISyntaxException e) { throw new RuntimeException(e); } HttpPut put = new HttpPut(uri); if (payload != null && payload.length>0) { put.setEntity(new ByteArrayEntity(payload)); } if (requestConfig != null) { put.setConfig(requestConfig); } return put; }
HttpPut httpput = new HttpPut(url+"/api/users/"+id); RequestConfig timeout = RequestConfig.custom().setConnectTimeout(2500).setSocketTimeout(2500).build(); httpput.setConfig(timeout);
public HttpUriRequest buildHttpUriRequest(Commands command, Id<DeploymentId> deploymentId, Id<UnitId> unitId, Id<PackageId> packageId, Map<String, byte[]> executionProperties) { Validate.isTrue(executionProperties != null && !executionProperties.isEmpty()); StringBuilder sb = new StringBuilder("/"); sb.append(PATH_ROOT).append("/"); sb.append(deploymentId).append("/"); sb.append("packages").append("/").append(packageId).append("/"); sb.append("units").append("/").append(unitId).append("/"); sb.append(command); String path = sb.toString(); URIBuilder uriBuilder = createUriBuilder(); uriBuilder.setPath(path); URI uri; try { uri = uriBuilder.build(); } catch (URISyntaxException e) { throw new RuntimeException(e); } HttpPut put = new HttpPut(uri); final MultipartEntityBuilder multipartBuilder = MultipartEntityBuilder.create(); for (Map.Entry<String, byte[]> entry : executionProperties.entrySet()) { multipartBuilder.addBinaryBody(entry.getKey(), entry.getValue()); } put.setEntity(multipartBuilder.build()); if (requestConfig != null) { put.setConfig(requestConfig); } return put; }
private static HttpPut getHttpPut(ClientConfiguration config , String url, String cookie, String userAgent, Map<String, String> headers) { HttpPut httpPut = new HttpPut(url); RequestConfig requestConfig = config .getRequestConfig(); httpPut.setConfig(requestConfig); // httpDelete.addHeader("Host", "www.bbossgroups.com"); if(config.getKeepAlive()>0) httpPut.addHeader("Connection", "Keep-Alive"); // if (cookie != null) // httpPut.addHeader("Cookie", cookie); // if (userAgent != null) // httpPut.addHeader("User-Agent", userAgent); if (headers != null && headers.size() > 0) { Iterator<Entry<String, String>> entries = headers.entrySet().iterator(); while (entries.hasNext()) { Entry<String, String> entry = entries.next(); httpPut.addHeader(entry.getKey(), entry.getValue()); } } return httpPut; }
public static int putData(final HttpClient httpClient, final RequestConfig requestConfig, final String host, final int port, final String path, final JSONObject entity) throws IOException, URISyntaxException { URI uri = new URIBuilder() .setScheme("http") .setHost(host) .setPort(port) .setPath(path) .build(); HttpPut httpPut = new HttpPut(uri); httpPut.setConfig(requestConfig); StringEntity params =new StringEntity(entity.toJSONString()); httpPut.setEntity(params); return httpClient.execute(httpPut, HttpClientUtils.createResponseCodeExtractor()); }
JsonObject httpPut(String url, String body, User registrar) throws Exception { String authHTTPCert = getHTTPAuthCertificate(registrar.getEnrollment(), "PUT", url, body); String putURL = addCAToURL(url); HttpPut httpPut = new HttpPut(putURL); httpPut.setConfig(getRequestConfig()); logger.debug(format("httpPutt %s, body:%s, authHTTPCert: %s", url, body, authHTTPCert)); final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); if (registry != null) { httpClientBuilder.setConnectionManager(new PoolingHttpClientConnectionManager(registry)); } HttpClient client = httpClientBuilder.build(); final HttpClientContext context = HttpClientContext.create(); httpPut.setEntity(new StringEntity(body)); httpPut.addHeader("Authorization", authHTTPCert); HttpResponse response = client.execute(httpPut, context); return getResult(response, body, "PUT"); }
/** * 发送put请求;带请求参数 * * @param url 请求地址 * @param params 参数集合 * @return * @throws Exception */ public static HttpClientResult doPut(String url, Map<String, String> params) throws Exception { CloseableHttpClient httpClient = HttpClients.createDefault(); HttpPut httpPut = new HttpPut(url); RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(CONNECT_TIMEOUT).setSocketTimeout(SOCKET_TIMEOUT).build(); httpPut.setConfig(requestConfig); packageParam(params, httpPut); CloseableHttpResponse httpResponse = null; try { return getHttpClientResult(httpResponse, httpClient, httpPut); } finally { release(httpResponse, httpClient); } }
HttpPut httpput = new HttpPut(URL + "/api/users/compilation/" + id); RequestConfig timeout = RequestConfig.custom().setConnectTimeout(2500).setSocketTimeout(2500).build(); httpput.setConfig(timeout);
httpPut.setConfig(config); final InputStreamEntity entity = new InputStreamEntity(inputStream, size); httpPut.setEntity(entity);
httpPut.setConfig(config); final InputStreamEntity entity = new InputStreamEntity(inputStream, size); httpPut.setEntity(entity);
case PUT: HttpPut httpPut = new HttpPut(url); httpPut.setConfig(reqConf); addHeader(httpPut, headerMap); httpPut.setEntity(new StringEntity(content, contentCharset));
private static final String putBinary(String url, HttpClientRequestOptions httpClientRequestOptions) throws IOException { RequestConfig config = prepareConfig(httpClientRequestOptions); CloseableHttpClient httpClient = HttpClientProxyUtils.getHttpClient(httpClientRequestOptions.isSslTrustAllEnabled()); HttpPut httpPut = new HttpPut(url); httpPut.setConfig(config); prepareHeaders(httpClientRequestOptions, httpPut); HttpEntity entity = EntityBuilder.create().setBinary(httpClientRequestOptions.getData()).setContentType(ContentType.APPLICATION_OCTET_STREAM) .build(); httpPut.setEntity(entity); CloseableHttpResponse response = httpClient.execute(httpPut); return processResponse(response, httpClientRequestOptions.isBinary()); }
private static final String putBinary(String url, HttpClientRequestOptions httpClientRequestOptions) throws IOException { RequestConfig config = prepareConfig(httpClientRequestOptions); CloseableHttpClient httpClient = HttpClientProxyUtils.getHttpClient(httpClientRequestOptions.isSslTrustAllEnabled()); HttpPut httpPut = new HttpPut(url); httpPut.setConfig(config); prepareHeaders(httpClientRequestOptions, httpPut); HttpEntity entity = EntityBuilder.create().setBinary(httpClientRequestOptions.getData()).setContentType(ContentType.APPLICATION_OCTET_STREAM) .build(); httpPut.setEntity(entity); CloseableHttpResponse response = httpClient.execute(httpPut); return processResponse(response, httpClientRequestOptions.isBinary()); }
private static final String putText(String url, HttpClientRequestOptions httpClientRequestOptions) throws IOException { if (httpClientRequestOptions.getText() == null) { throw new IllegalArgumentException("The element [text] in [options] cannot be null for POST requests in [text] mode"); } RequestConfig config = prepareConfig(httpClientRequestOptions); CloseableHttpClient httpClient = HttpClientProxyUtils.getHttpClient(httpClientRequestOptions.isSslTrustAllEnabled()); HttpPut httpPut = new HttpPut(url); httpPut.setConfig(config); prepareHeaders(httpClientRequestOptions, httpPut); HttpEntity entity = EntityBuilder.create().setText(httpClientRequestOptions.getText()) .setContentEncoding(httpClientRequestOptions.getCharacterEncoding()) .setContentType(ContentType.create(httpClientRequestOptions.getContentType())).build(); httpPut.setEntity(entity); CloseableHttpResponse response = httpClient.execute(httpPut); return processResponse(response, httpClientRequestOptions.isBinary()); }
private static final String putText(String url, HttpClientRequestOptions httpClientRequestOptions) throws IOException { if (httpClientRequestOptions.getText() == null) { throw new IllegalArgumentException("The element [text] in [options] cannot be null for POST requests in [text] mode"); } RequestConfig config = prepareConfig(httpClientRequestOptions); CloseableHttpClient httpClient = HttpClientProxyUtils.getHttpClient(httpClientRequestOptions.isSslTrustAllEnabled()); HttpPut httpPut = new HttpPut(url); httpPut.setConfig(config); prepareHeaders(httpClientRequestOptions, httpPut); HttpEntity entity = EntityBuilder.create().setText(httpClientRequestOptions.getText()) .setContentEncoding(httpClientRequestOptions.getCharacterEncoding()) .setContentType(ContentType.create(httpClientRequestOptions.getContentType())).build(); httpPut.setEntity(entity); CloseableHttpResponse response = httpClient.execute(httpPut); return processResponse(response, httpClientRequestOptions.isBinary()); }
httpput.setConfig(requestConfig.build());
httpput.setConfig(requestConfig.build());