List of usage examples for org.apache.http.client.methods HttpPost METHOD_NAME
String METHOD_NAME
To view the source code for org.apache.http.client.methods HttpPost METHOD_NAME.
Click Source Link
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testSearchNullSource() throws IOException { SearchRequest searchRequest = new SearchRequest(); Request request = RequestConverters.search(searchRequest); assertEquals(HttpPost.METHOD_NAME, request.getMethod()); assertEquals("/_search", request.getEndpoint()); assertNull(request.getEntity());//from ww w .ja va 2s . c om }
From source file:org.dcm4che3.tool.unvscp.UnvSCP.java
private static void configurePushMethod(UnvSCP main, CommandLine cl) throws ParseException { String method = null;// w w w . jav a2 s. c o m if (cl.hasOption("push-http-method") && !"".equals(method = cl.getOptionValue("push-http-method"))) { if (HttpPost.METHOD_NAME.equalsIgnoreCase(method)) { UnvWebClient.setUploadingFilesHttpMethod(HttpPost.METHOD_NAME); } else if (HttpPut.METHOD_NAME.equalsIgnoreCase(method)) { UnvWebClient.setUploadingFilesHttpMethod(HttpPut.METHOD_NAME); } else { throw new ParseException( "--push-http-method accepts only POST|PUT. Method \"" + method + "\" is not supported."); } } else { UnvWebClient.setUploadingFilesHttpMethod(HttpPut.METHOD_NAME); } LOG.info("Using http method \"{}\" for uploading files", UnvWebClient.getUploadingFilesHttpMethod()); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testSearch() throws Exception { String[] indices = randomIndicesNames(0, 5); SearchRequest searchRequest = new SearchRequest(indices); int numTypes = randomIntBetween(0, 5); String[] types = new String[numTypes]; for (int i = 0; i < numTypes; i++) { types[i] = "type-" + randomAlphaOfLengthBetween(2, 5); }/* w w w. j ava2 s . co m*/ searchRequest.types(types); Map<String, String> expectedParams = new HashMap<>(); setRandomSearchParams(searchRequest, expectedParams); setRandomIndicesOptions(searchRequest::indicesOptions, searchRequest::indicesOptions, expectedParams); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); // rarely skip setting the search source completely if (frequently()) { // frequently set the search source to have some content, otherwise leave it // empty but still set it if (frequently()) { if (randomBoolean()) { searchSourceBuilder.size(randomIntBetween(0, Integer.MAX_VALUE)); } if (randomBoolean()) { searchSourceBuilder.from(randomIntBetween(0, Integer.MAX_VALUE)); } if (randomBoolean()) { searchSourceBuilder.minScore(randomFloat()); } if (randomBoolean()) { searchSourceBuilder.explain(randomBoolean()); } if (randomBoolean()) { searchSourceBuilder.profile(randomBoolean()); } if (randomBoolean()) { searchSourceBuilder .highlighter(new HighlightBuilder().field(randomAlphaOfLengthBetween(3, 10))); } if (randomBoolean()) { searchSourceBuilder.query(new TermQueryBuilder(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10))); } if (randomBoolean()) { searchSourceBuilder.aggregation( new TermsAggregationBuilder(randomAlphaOfLengthBetween(3, 10), ValueType.STRING) .field(randomAlphaOfLengthBetween(3, 10))); } if (randomBoolean()) { searchSourceBuilder .suggest(new SuggestBuilder().addSuggestion(randomAlphaOfLengthBetween(3, 10), new CompletionSuggestionBuilder(randomAlphaOfLengthBetween(3, 10)))); } if (randomBoolean()) { searchSourceBuilder.addRescorer(new QueryRescorerBuilder(new TermQueryBuilder( randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10)))); } if (randomBoolean()) { searchSourceBuilder.collapse(new CollapseBuilder(randomAlphaOfLengthBetween(3, 10))); } } searchRequest.source(searchSourceBuilder); } Request request = RequestConverters.search(searchRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); String index = String.join(",", indices); if (Strings.hasLength(index)) { endpoint.add(index); } String type = String.join(",", types); if (Strings.hasLength(type)) { endpoint.add(type); } endpoint.add("_search"); assertEquals(HttpPost.METHOD_NAME, request.getMethod()); assertEquals(endpoint.toString(), request.getEndpoint()); assertEquals(expectedParams, request.getParameters()); assertToXContentBody(searchSourceBuilder, request.getEntity()); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testMultiSearch() throws IOException { int numberOfSearchRequests = randomIntBetween(0, 32); MultiSearchRequest multiSearchRequest = new MultiSearchRequest(); for (int i = 0; i < numberOfSearchRequests; i++) { SearchRequest searchRequest = randomSearchRequest(() -> { // No need to return a very complex SearchSourceBuilder here, that is tested // elsewhere SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); searchSourceBuilder.from(randomInt(10)); searchSourceBuilder.size(randomIntBetween(20, 100)); return searchSourceBuilder; });//from ww w.j a va 2s. com // scroll is not supported in the current msearch api, so unset it: searchRequest.scroll((Scroll) null); // only expand_wildcards, ignore_unavailable and allow_no_indices can be // specified from msearch api, so unset other options: IndicesOptions randomlyGenerated = searchRequest.indicesOptions(); IndicesOptions msearchDefault = new MultiSearchRequest().indicesOptions(); searchRequest.indicesOptions(IndicesOptions.fromOptions(randomlyGenerated.ignoreUnavailable(), randomlyGenerated.allowNoIndices(), randomlyGenerated.expandWildcardsOpen(), randomlyGenerated.expandWildcardsClosed(), msearchDefault.allowAliasesToMultipleIndices(), msearchDefault.forbidClosedIndices(), msearchDefault.ignoreAliases())); multiSearchRequest.add(searchRequest); } Map<String, String> expectedParams = new HashMap<>(); expectedParams.put(RestSearchAction.TYPED_KEYS_PARAM, "true"); if (randomBoolean()) { multiSearchRequest.maxConcurrentSearchRequests(randomIntBetween(1, 8)); expectedParams.put("max_concurrent_searches", Integer.toString(multiSearchRequest.maxConcurrentSearchRequests())); } Request request = RequestConverters.multiSearch(multiSearchRequest); assertEquals("/_msearch", request.getEndpoint()); assertEquals(HttpPost.METHOD_NAME, request.getMethod()); assertEquals(expectedParams, request.getParameters()); List<SearchRequest> requests = new ArrayList<>(); CheckedBiConsumer<SearchRequest, XContentParser, IOException> consumer = (searchRequest, p) -> { SearchSourceBuilder searchSourceBuilder = SearchSourceBuilder.fromXContent(p, false); if (searchSourceBuilder.equals(new SearchSourceBuilder()) == false) { searchRequest.source(searchSourceBuilder); } requests.add(searchRequest); }; MultiSearchRequest.readMultiLineFormat(new BytesArray(EntityUtils.toByteArray(request.getEntity())), REQUEST_BODY_CONTENT_TYPE.xContent(), consumer, null, multiSearchRequest.indicesOptions(), null, null, null, xContentRegistry(), true); assertEquals(requests, multiSearchRequest.requests()); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testSearchScroll() throws IOException { SearchScrollRequest searchScrollRequest = new SearchScrollRequest(); searchScrollRequest.scrollId(randomAlphaOfLengthBetween(5, 10)); if (randomBoolean()) { searchScrollRequest.scroll(randomPositiveTimeValue()); }/* w ww. j a v a2s . co m*/ Request request = RequestConverters.searchScroll(searchScrollRequest); assertEquals(HttpPost.METHOD_NAME, request.getMethod()); assertEquals("/_search/scroll", request.getEndpoint()); assertEquals(0, request.getParameters().size()); assertToXContentBody(searchScrollRequest, request.getEntity()); assertEquals(REQUEST_BODY_CONTENT_TYPE.mediaTypeWithoutParameters(), request.getEntity().getContentType().getValue()); }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.tests.CustomApiTests.java
@SuppressWarnings("deprecation") private TestCase invokeJsonApiOverload4WithCallbackTest() { String name = String.format("Json With Callback - Overload 4"); TestCase test = new TestCase(name) { TestExecutionCallback mCallback; TestResult mResult;/*from w ww. j a v a 2s.c o m*/ @Override protected void executeTest(MobileServiceClient client, TestExecutionCallback callback) { mResult = new TestResult(); mResult.setTestCase(this); mResult.setStatus(TestStatus.Passed); mCallback = callback; List<Pair<String, String>> parameters = new ArrayList<Pair<String, String>>(); JsonElement json = createJson(new Random(), 0, false); try { client.invokeApi(PUBLIC_API_NAME, json, HttpPost.METHOD_NAME, parameters, jsonTestCallback()); } catch (Exception exception) { createResultFromException(mResult, exception); } } private ApiJsonOperationCallback jsonTestCallback() { return new ApiJsonOperationCallback() { @Override public void onCompleted(JsonElement jsonObject, Exception exception, ServiceFilterResponse response) { if (exception != null) { createResultFromException(mResult, exception); } mCallback.onTestComplete(mResult.getTestCase(), mResult); } }; } }; return test; }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.tests.CustomApiTests.java
@SuppressWarnings("deprecation") private TestCase invokeJsonApiOverload4WithCallbackFailTest() { String name = String.format("Json With Callback - Overload 4 - Fail"); TestCase test = new TestCase(name) { TestExecutionCallback mCallback; TestResult mResult;/*from w w w .j av a2 s. c om*/ @Override protected void executeTest(MobileServiceClient client, TestExecutionCallback callback) { mResult = new TestResult(); mResult.setTestCase(this); mResult.setStatus(TestStatus.Passed); mCallback = callback; List<Pair<String, String>> parameters = new ArrayList<Pair<String, String>>(); JsonElement json = createJson(new Random(), 0, false); try { client.invokeApi(INEXISTENT_API_NAME, json, HttpPost.METHOD_NAME, parameters, jsonTestCallback()); } catch (Exception exception) { createResultFromException(mResult, exception); } } private ApiJsonOperationCallback jsonTestCallback() { return new ApiJsonOperationCallback() { @Override public void onCompleted(JsonElement jsonObject, Exception exception, ServiceFilterResponse response) { if (exception == null) { mResult.setStatus(TestStatus.Failed); } mCallback.onTestComplete(mResult.getTestCase(), mResult); } }; } }; return test; }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.tests.CustomApiTests.java
private TestCase invokeHttpContentApiOverload1WithCallbackTest() { String name = String.format("Http With Callback - Overload 1"); TestCase test = new TestCase(name) { TestExecutionCallback mCallback; TestResult mResult;//from w w w . j av a 2 s . c o m @Override protected void executeTest(MobileServiceClient client, TestExecutionCallback callback) { mResult = new TestResult(); mResult.setTestCase(this); mResult.setStatus(TestStatus.Passed); mCallback = callback; String apiUrl = APP_API_NAME; try { client.invokeApi(apiUrl, new byte[0], HttpPost.METHOD_NAME, new ArrayList<Pair<String, String>>(), new ArrayList<Pair<String, String>>(), serviceFilterResponseCallback()); } catch (Exception exception) { createResultFromException(mResult, exception); } } private ServiceFilterResponseCallback serviceFilterResponseCallback() { return new ServiceFilterResponseCallback() { @Override public void onResponse(ServiceFilterResponse response, Exception exception) { if (exception != null) { createResultFromException(mResult, exception); } mCallback.onTestComplete(mResult.getTestCase(), mResult); } }; } }; return test; }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.tests.CustomApiTests.java
private TestCase invokeHttpContentApiOverload1WithCallbackFailTest() { String name = String.format("Http With Callback - Overload 1 - Fail"); TestCase test = new TestCase(name) { TestExecutionCallback mCallback; TestResult mResult;//from w w w. j a va 2 s .c o m @Override protected void executeTest(MobileServiceClient client, TestExecutionCallback callback) { mResult = new TestResult(); mResult.setTestCase(this); mResult.setStatus(TestStatus.Passed); mCallback = callback; String apiUrl = APP_API_NAME + INEXISTENT_API_NAME; try { client.invokeApi(apiUrl, new byte[0], HttpPost.METHOD_NAME, new ArrayList<Pair<String, String>>(), new ArrayList<Pair<String, String>>(), serviceFilterResponseCallback()); } catch (Exception exception) { createResultFromException(mResult, exception); } } private ServiceFilterResponseCallback serviceFilterResponseCallback() { return new ServiceFilterResponseCallback() { @Override public void onResponse(ServiceFilterResponse response, Exception exception) { if (exception == null) { mResult.setStatus(TestStatus.Failed); } mCallback.onTestComplete(mResult.getTestCase(), mResult); } }; } }; return test; }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.tests.CustomApiTests.java
private String createHttpMethod(final Random rndGen) { switch (rndGen.nextInt(10)) { case 0://from w ww . j a va 2 s. c o m case 1: case 2: return HttpPost.METHOD_NAME; case 3: case 4: case 5: case 6: return HttpGet.METHOD_NAME; case 7: return HttpPut.METHOD_NAME; case 8: return HttpDelete.METHOD_NAME; default: return PATCH_METHOD_NAME; } }