List of usage examples for org.apache.http.client.methods HttpPut METHOD_NAME
String METHOD_NAME
To view the source code for org.apache.http.client.methods HttpPut METHOD_NAME.
Click Source Link
From source file:com.mirth.connect.client.core.ServerConnection.java
private HttpRequestBase createRequestBase(String method) { HttpRequestBase requestBase = null;/* w ww . ja va2s . c o m*/ if (StringUtils.equalsIgnoreCase(HttpGet.METHOD_NAME, method)) { requestBase = new HttpGet(); } else if (StringUtils.equalsIgnoreCase(HttpPost.METHOD_NAME, method)) { requestBase = new HttpPost(); } else if (StringUtils.equalsIgnoreCase(HttpPut.METHOD_NAME, method)) { requestBase = new HttpPut(); } else if (StringUtils.equalsIgnoreCase(HttpDelete.METHOD_NAME, method)) { requestBase = new HttpDelete(); } else if (StringUtils.equalsIgnoreCase(HttpOptions.METHOD_NAME, method)) { requestBase = new HttpOptions(); } else if (StringUtils.equalsIgnoreCase(HttpPatch.METHOD_NAME, method)) { requestBase = new HttpPatch(); } requestBase.setConfig(requestConfig); return requestBase; }
From source file:com.azure.webapi.MobileServiceClient.java
/** * /* w w w.ja v a 2 s . c o m*/ * @param apiName * The API name * @param content * The byte array to send as the request body * @param httpMethod * The HTTP Method used to invoke the API * @param requestHeaders * The extra headers to send in the request * @param parameters * The query string parameters sent in the request * @param callback * The callback to invoke after the API execution */ public void invokeApi(String apiName, byte[] content, String httpMethod, List<Pair<String, String>> requestHeaders, List<Pair<String, String>> parameters, final ServiceFilterResponseCallback callback) { if (apiName == null || apiName.trim().equals("")) { if (callback != null) { callback.onResponse(null, new IllegalArgumentException("apiName cannot be null")); } return; } if (httpMethod == null || httpMethod.trim().equals("")) { if (callback != null) { callback.onResponse(null, new IllegalArgumentException("httpMethod cannot be null")); } return; } Uri.Builder uriBuilder = Uri.parse(getAppUrl().toString()).buildUpon(); uriBuilder.path(CUSTOM_API_URL + apiName); if (parameters != null && parameters.size() > 0) { for (Pair<String, String> parameter : parameters) { uriBuilder.appendQueryParameter(parameter.first, parameter.second); } } ServiceFilterRequest request; String url = uriBuilder.build().toString(); if (httpMethod.equalsIgnoreCase(HttpGet.METHOD_NAME)) { request = new ServiceFilterRequestImpl(new HttpGet(url)); } else if (httpMethod.equalsIgnoreCase(HttpPost.METHOD_NAME)) { request = new ServiceFilterRequestImpl(new HttpPost(url)); } else if (httpMethod.equalsIgnoreCase(HttpPut.METHOD_NAME)) { request = new ServiceFilterRequestImpl(new HttpPut(url)); } else if (httpMethod.equalsIgnoreCase(HttpPatch.METHOD_NAME)) { request = new ServiceFilterRequestImpl(new HttpPatch(url)); } else if (httpMethod.equalsIgnoreCase(HttpDelete.METHOD_NAME)) { request = new ServiceFilterRequestImpl(new HttpDelete(url)); } else { if (callback != null) { callback.onResponse(null, new IllegalArgumentException("httpMethod not supported")); } return; } if (requestHeaders != null && requestHeaders.size() > 0) { for (Pair<String, String> header : requestHeaders) { request.addHeader(header.first, header.second); } } if (content != null) { try { request.setContent(content); } catch (Exception e) { if (callback != null) { callback.onResponse(null, e); } return; } } MobileServiceConnection conn = createConnection(); // Create AsyncTask to execute the request and parse the results new RequestAsyncTask(request, conn) { @Override protected void onPostExecute(ServiceFilterResponse response) { if (callback != null) { callback.onResponse(response, mTaskException); } } }.execute(); }
From source file:org.trancecode.xproc.step.RequestParser.java
private HttpRequestBase constructMethod(final String method, final URI hrefUri) { final HttpEntity httpEntity = request.getEntity(); final HeaderGroup headers = request.getHeaders(); if (StringUtils.equalsIgnoreCase(HttpPost.METHOD_NAME, method)) { final HttpPost httpPost = new HttpPost(hrefUri); for (final Header h : headers.getAllHeaders()) { if (!StringUtils.equalsIgnoreCase("Content-Type", h.getName())) { httpPost.addHeader(h);//from ww w . j a v a 2s . co m } } httpPost.setEntity(httpEntity); return httpPost; } else if (StringUtils.equalsIgnoreCase(HttpPut.METHOD_NAME, method)) { final HttpPut httpPut = new HttpPut(hrefUri); httpPut.setEntity(httpEntity); return httpPut; } else if (StringUtils.equalsIgnoreCase(HttpDelete.METHOD_NAME, method)) { final HttpDelete httpDelete = new HttpDelete(hrefUri); httpDelete.setHeaders(headers.getAllHeaders()); return httpDelete; } else if (StringUtils.equalsIgnoreCase(HttpGet.METHOD_NAME, method)) { final HttpGet httpGet = new HttpGet(hrefUri); httpGet.setHeaders(headers.getAllHeaders()); return httpGet; } else if (StringUtils.equalsIgnoreCase(HttpHead.METHOD_NAME, method)) { final HttpHead httpHead = new HttpHead(hrefUri); httpHead.setHeaders(headers.getAllHeaders()); return httpHead; } return null; }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testCreateIndex() throws IOException { CreateIndexRequest createIndexRequest = randomCreateIndexRequest(); Map<String, String> expectedParams = new HashMap<>(); setRandomTimeout(createIndexRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); setRandomMasterTimeout(createIndexRequest, expectedParams); setRandomWaitForActiveShards(createIndexRequest::waitForActiveShards, expectedParams); Request request = RequestConverters.createIndex(createIndexRequest); assertEquals("/" + createIndexRequest.index(), request.getEndpoint()); assertEquals(expectedParams, request.getParameters()); assertEquals(HttpPut.METHOD_NAME, request.getMethod()); assertToXContentBody(createIndexRequest, request.getEntity()); }
From source file:org.fcrepo.integration.http.api.FedoraLdpIT.java
License:asdf
private static void assertResourceOptionsHeaders(final HttpResponse httpResponse) { final List<String> methods = headerValues(httpResponse, "Allow"); assertTrue("Should allow GET", methods.contains(HttpGet.METHOD_NAME)); assertTrue("Should allow PUT", methods.contains(HttpPut.METHOD_NAME)); assertTrue("Should allow DELETE", methods.contains(HttpDelete.METHOD_NAME)); assertTrue("Should allow OPTIONS", methods.contains(HttpOptions.METHOD_NAME)); }
From source file:org.elasticsearch.client.SearchIT.java
public void testSearchWithParentJoin() throws IOException { final String indexName = "child_example"; StringEntity parentMapping = new StringEntity( "{\n" + " \"mappings\": {\n" + " \"qa\" : {\n" + " \"properties\" : {\n" + " \"qa_join_field\" : {\n" + " \"type\" : \"join\",\n" + " \"relations\" : { \"question\" : \"answer\" }\n" + " }\n" + " }\n" + " }\n" + " }" + "}", ContentType.APPLICATION_JSON); client().performRequest(HttpPut.METHOD_NAME, "/" + indexName, Collections.emptyMap(), parentMapping); StringEntity questionDoc = new StringEntity("{\n" + " \"body\": \"<p>I have Windows 2003 server and i bought a new Windows 2008 server...\",\n" + " \"title\": \"Whats the best way to file transfer my site from server to a newer one?\",\n" + " \"tags\": [\n" + " \"windows-server-2003\",\n" + " \"windows-server-2008\",\n" + " \"file-transfer\"\n" + " ],\n" + " \"qa_join_field\" : \"question\"\n" + "}", ContentType.APPLICATION_JSON); client().performRequest(HttpPut.METHOD_NAME, "/" + indexName + "/qa/1", Collections.emptyMap(), questionDoc);/* w ww . j a v a 2 s . c o m*/ StringEntity answerDoc1 = new StringEntity( "{\n" + " \"owner\": {\n" + " \"location\": \"Norfolk, United Kingdom\",\n" + " \"display_name\": \"Sam\",\n" + " \"id\": 48\n" + " },\n" + " \"body\": \"<p>Unfortunately you're pretty much limited to FTP...\",\n" + " \"qa_join_field\" : {\n" + " \"name\" : \"answer\",\n" + " \"parent\" : \"1\"\n" + " },\n" + " \"creation_date\": \"2009-05-04T13:45:37.030\"\n" + "}", ContentType.APPLICATION_JSON); client().performRequest(HttpPut.METHOD_NAME, "/" + indexName + "/qa/2", Collections.singletonMap("routing", "1"), answerDoc1); StringEntity answerDoc2 = new StringEntity( "{\n" + " \"owner\": {\n" + " \"location\": \"Norfolk, United Kingdom\",\n" + " \"display_name\": \"Troll\",\n" + " \"id\": 49\n" + " },\n" + " \"body\": \"<p>Use Linux...\",\n" + " \"qa_join_field\" : {\n" + " \"name\" : \"answer\",\n" + " \"parent\" : \"1\"\n" + " },\n" + " \"creation_date\": \"2009-05-05T13:45:37.030\"\n" + "}", ContentType.APPLICATION_JSON); client().performRequest(HttpPut.METHOD_NAME, "/" + indexName + "/qa/3", Collections.singletonMap("routing", "1"), answerDoc2); client().performRequest(HttpPost.METHOD_NAME, "/_refresh"); TermsAggregationBuilder leafTermAgg = new TermsAggregationBuilder("top-names", ValueType.STRING) .field("owner.display_name.keyword").size(10); ChildrenAggregationBuilder childrenAgg = new ChildrenAggregationBuilder("to-answers", "answer") .subAggregation(leafTermAgg); TermsAggregationBuilder termsAgg = new TermsAggregationBuilder("top-tags", ValueType.STRING) .field("tags.keyword").size(10).subAggregation(childrenAgg); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.size(0).aggregation(termsAgg); SearchRequest searchRequest = new SearchRequest(indexName); searchRequest.source(searchSourceBuilder); SearchResponse searchResponse = execute(searchRequest, highLevelClient()::search, highLevelClient()::searchAsync); assertSearchHeader(searchResponse); assertNull(searchResponse.getSuggest()); assertEquals(Collections.emptyMap(), searchResponse.getProfileResults()); assertEquals(3, searchResponse.getHits().totalHits); assertEquals(0, searchResponse.getHits().getHits().length); assertEquals(0f, searchResponse.getHits().getMaxScore(), 0f); assertEquals(1, searchResponse.getAggregations().asList().size()); Terms terms = searchResponse.getAggregations().get("top-tags"); assertEquals(0, terms.getDocCountError()); assertEquals(0, terms.getSumOfOtherDocCounts()); assertEquals(3, terms.getBuckets().size()); for (Terms.Bucket bucket : terms.getBuckets()) { assertThat(bucket.getKeyAsString(), either(equalTo("file-transfer")).or(equalTo("windows-server-2003")) .or(equalTo("windows-server-2008"))); assertEquals(1, bucket.getDocCount()); assertEquals(1, bucket.getAggregations().asList().size()); Children children = bucket.getAggregations().get("to-answers"); assertEquals(2, children.getDocCount()); assertEquals(1, children.getAggregations().asList().size()); Terms leafTerms = children.getAggregations().get("top-names"); assertEquals(0, leafTerms.getDocCountError()); assertEquals(0, leafTerms.getSumOfOtherDocCounts()); assertEquals(2, leafTerms.getBuckets().size()); assertEquals(2, leafTerms.getBuckets().size()); Terms.Bucket sam = leafTerms.getBucketByKey("Sam"); assertEquals(1, sam.getDocCount()); Terms.Bucket troll = leafTerms.getBucketByKey("Troll"); assertEquals(1, troll.getDocCount()); } }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testPutMapping() throws IOException { PutMappingRequest putMappingRequest = new PutMappingRequest(); String[] indices = randomIndicesNames(0, 5); putMappingRequest.indices(indices);/*w w w. j a v a 2 s . co m*/ String type = randomAlphaOfLengthBetween(3, 10); putMappingRequest.type(type); Map<String, String> expectedParams = new HashMap<>(); setRandomTimeout(putMappingRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); setRandomMasterTimeout(putMappingRequest, expectedParams); Request request = RequestConverters.putMapping(putMappingRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); String index = String.join(",", indices); if (Strings.hasLength(index)) { endpoint.add(index); } endpoint.add("_mapping"); endpoint.add(type); assertEquals(endpoint.toString(), request.getEndpoint()); assertEquals(expectedParams, request.getParameters()); assertEquals(HttpPut.METHOD_NAME, request.getMethod()); assertToXContentBody(putMappingRequest, request.getEntity()); }
From source file:org.elasticsearch.client.RequestConverters.java
static Request index(IndexRequest indexRequest) { String method = Strings.hasLength(indexRequest.id()) ? HttpPut.METHOD_NAME : HttpPost.METHOD_NAME; boolean isCreate = (indexRequest.opType() == DocWriteRequest.OpType.CREATE); String endpoint = endpoint(indexRequest.index(), indexRequest.type(), indexRequest.id(), isCreate ? "_create" : null); Request request = new Request(method, endpoint); Params parameters = new Params(request); parameters.withRouting(indexRequest.routing()); parameters.withTimeout(indexRequest.timeout()); parameters.withVersion(indexRequest.version()); parameters.withVersionType(indexRequest.versionType()); parameters.withPipeline(indexRequest.getPipeline()); parameters.withRefreshPolicy(indexRequest.getRefreshPolicy()); parameters.withWaitForActiveShards(indexRequest.waitForActiveShards()); BytesRef source = indexRequest.source().toBytesRef(); ContentType contentType = createContentType(indexRequest.getContentType()); request.setEntity(new ByteArrayEntity(source.bytes, source.offset, source.length, contentType)); return request; }
From source file:com.wudaosoft.net.httpclient.Request.java
public WorkerBuilder put(String url) { return new WorkerBuilder(this, HttpPut.METHOD_NAME, url); }
From source file:org.elasticsearch.client.RestClient.java
private static HttpRequestBase createHttpRequest(String method, URI uri, HttpEntity entity) { switch (method.toUpperCase(Locale.ROOT)) { case HttpDeleteWithEntity.METHOD_NAME: return addRequestBody(new HttpDeleteWithEntity(uri), entity); case HttpGetWithEntity.METHOD_NAME: return addRequestBody(new HttpGetWithEntity(uri), entity); case HttpHead.METHOD_NAME: return addRequestBody(new HttpHead(uri), entity); case HttpOptions.METHOD_NAME: return addRequestBody(new HttpOptions(uri), entity); case HttpPatch.METHOD_NAME: return addRequestBody(new HttpPatch(uri), entity); case HttpPost.METHOD_NAME: HttpPost httpPost = new HttpPost(uri); addRequestBody(httpPost, entity); return httpPost; case HttpPut.METHOD_NAME: return addRequestBody(new HttpPut(uri), entity); case HttpTrace.METHOD_NAME: return addRequestBody(new HttpTrace(uri), entity); default://w ww. j a v a 2 s .com throw new UnsupportedOperationException("http method not supported: " + method); } }