List of usage examples for org.apache.http.client.methods HttpGet METHOD_NAME
String METHOD_NAME
To view the source code for org.apache.http.client.methods HttpGet METHOD_NAME.
Click Source Link
From source file:com.microsoft.windowsazure.mobileservices.sdk.testapp.test.CustomApiClientTests.java
public void testInvokeMethodEcho() throws Throwable { // Container to store callback's results and do the asserts. final ResultsContainer container = new ResultsContainer(); MobileServiceClient client = null;/*from www . j av a 2s . c o m*/ try { client = new MobileServiceClient(appUrl, appKey, getInstrumentation().getTargetContext()); client = client.withFilter(new HttpMetaEchoFilter()); List<Pair<String, String>> mockHeaders = new ArrayList<Pair<String, String>>(); List<Pair<String, String>> mockParameters = new ArrayList<Pair<String, String>>(); ServiceFilterResponse response = client .invokeApi("myApi", null, HttpGet.METHOD_NAME, mockHeaders, mockParameters).get(); if (response == null || response.getContent() == null) { container.setException(new Exception("Expected response")); } else { container.setResponseValue(response.getContent()); } } catch (Exception exception) { container.setException(exception); } // Asserts Exception exception = container.getException(); if (exception != null) { fail(exception.getMessage()); } else { JsonObject jResponse = (new JsonParser()).parse(container.getResponseValue()).getAsJsonObject(); assertEquals(HttpGet.METHOD_NAME, jResponse.get("method").getAsString()); } }
From source file:org.elasticsearch.client.IndicesClientIT.java
public void testCloseExistingIndex() throws IOException { String index = "index"; createIndex(index, Settings.EMPTY);//from w ww . j av a 2 s . c om Response response = client().performRequest(HttpGet.METHOD_NAME, index + "/_search"); assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus())); CloseIndexRequest closeIndexRequest = new CloseIndexRequest(index); CloseIndexResponse closeIndexResponse = execute(closeIndexRequest, highLevelClient().indices()::close, highLevelClient().indices()::closeAsync); assertTrue(closeIndexResponse.isAcknowledged()); ResponseException exception = expectThrows(ResponseException.class, () -> client().performRequest(HttpGet.METHOD_NAME, index + "/_search")); assertThat(exception.getResponse().getStatusLine().getStatusCode(), equalTo(RestStatus.BAD_REQUEST.getStatus())); assertThat(exception.getMessage().contains(index), equalTo(true)); }
From source file:org.elasticsearch.client.RequestConverters.java
static Request fieldCaps(FieldCapabilitiesRequest fieldCapabilitiesRequest) { Request request = new Request(HttpGet.METHOD_NAME, endpoint(fieldCapabilitiesRequest.indices(), "_field_caps")); Params params = new Params(request); params.withFields(fieldCapabilitiesRequest.fields()); params.withIndicesOptions(fieldCapabilitiesRequest.indicesOptions()); return request; }
From source file:org.elasticsearch.client.RequestConverters.java
static Request rankEval(RankEvalRequest rankEvalRequest) throws IOException { Request request = new Request(HttpGet.METHOD_NAME, endpoint(rankEvalRequest.indices(), Strings.EMPTY_ARRAY, "_rank_eval")); Params params = new Params(request); params.withIndicesOptions(rankEvalRequest.indicesOptions()); request.setEntity(createEntity(rankEvalRequest.getRankEvalSpec(), REQUEST_BODY_CONTENT_TYPE)); return request; }
From source file:org.deviceconnect.android.manager.setting.ReqResDebugActivity.java
/** * Http?./*from www.jav a2s. c o m*/ * @param method HTTP * @param uri ?URI * @param listener Http???? */ private void executeHttpRequest(final String method, final URI uri, final HttpListener listener) { HttpUriRequest req = null; if (HttpGet.METHOD_NAME.equals(method)) { req = new HttpGet(uri.toString()); } else if (HttpPost.METHOD_NAME.equals(method)) { req = new HttpPost(uri.toString()); } else if (HttpPut.METHOD_NAME.equals(method)) { req = new HttpPut(uri.toString()); } else if (HttpDelete.METHOD_NAME.equals(method)) { req = new HttpDelete(uri.toString()); } else if ("?".equals(method)) { AssetManager manager = getAssets(); try { // TODO ?????? String name = "test.png"; MultipartEntity entity = new MultipartEntity(); InputStream in = manager.open(name); // ?? ByteArrayOutputStream baos = new ByteArrayOutputStream(); int len; byte[] buf = new byte[4096]; while ((len = in.read(buf)) > 0) { baos.write(buf, 0, len); } // ? entity.addPart(FileProfileConstants.PARAM_DATA, new BinaryBody(baos.toByteArray(), name)); req = new HttpPost(uri.toString()); ((HttpPost) req).setEntity(entity); } catch (UnsupportedEncodingException e) { return; } catch (IOException e) { return; } } else { return; } if (req != null) { executeHttpRequest(req, listener); } }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.tests.CustomApiTests.java
private TestCase createJsonApiTest(final ApiPermissions permission, final boolean isAuthenticated, final Random rndGen, int testNumber) { String name = String.format("Json Overload - %s - authenticated=%s - Instance=%s", permission.toString(), isAuthenticated, testNumber + 1); TestCase test = new TestCase(name) { MobileServiceClient mClient;/*from www . jav a2 s . c om*/ List<Pair<String, String>> mQuery; boolean mExpected401; TestResult mResult; @Override protected void executeTest(MobileServiceClient client, TestExecutionCallback callback) { mResult = new TestResult(); mResult.setTestCase(this); mResult.setStatus(TestStatus.Passed); if (permission == ApiPermissions.Public) { client = client.withFilter(new RemoveAuthenticationServiceFilter()); } mExpected401 = permission == ApiPermissions.Admin || (permission == ApiPermissions.User && !isAuthenticated); mClient = client; String method = createHttpMethod(rndGen); log("Method = " + method); JsonElement body = null; if (!method.equals(HttpGet.METHOD_NAME) && !method.equals(HttpDelete.METHOD_NAME)) { if (method.equals(PATCH_METHOD_NAME) || method.equals(HttpPut.METHOD_NAME)) { body = createJson(rndGen, 0, false); } else { body = createJson(rndGen, 0, true); } } if (body == null) { log("Body: NULL"); } else { log("Body: " + body.toString()); } mQuery = createQuery(rndGen); JsonElement queryJson = createQueryObject(mQuery); log("Query: " + queryJson.toString()); String api = apiNames.get(permission); log("API: " + api); if (body == null && method.equals(HttpPost.METHOD_NAME) && mQuery == null) { try { JsonElement jsonElement = client.invokeApi(api).get(); JsonObject expectedResult = new JsonObject(); expectedResult.add("user", createUserObject(mClient)); if (mQuery != null && mQuery.size() > 0) { expectedResult.add("query", createQueryObject(mQuery)); } if (!Util.compareJson(expectedResult, jsonElement)) { createResultFromException(mResult, new ExpectedValueException(expectedResult, jsonElement)); } } catch (Exception exception) { MobileServiceException cause = (MobileServiceException) exception.getCause(); ServiceFilterResponse response = cause.getResponse(); if (mExpected401) { if (response == null || response.getStatus().getStatusCode() != 401) { mResult.setStatus(TestStatus.Failed); mResult.setException(exception); mResult.getTestCase().log("Expected 401"); } } else { if (exception != null) { createResultFromException(mResult, exception); } } } } else if (body != null && method.equals(HttpPost.METHOD_NAME) && mQuery == null) { try { JsonElement jsonElement = client.invokeApi(api, body).get(); JsonObject expectedResult = new JsonObject(); expectedResult.add("user", createUserObject(mClient)); if (mQuery != null && mQuery.size() > 0) { expectedResult.add("query", createQueryObject(mQuery)); } if (!Util.compareJson(expectedResult, jsonElement)) { createResultFromException(mResult, new ExpectedValueException(expectedResult, jsonElement)); } } catch (Exception exception) { if (mExpected401) { MobileServiceException cause = (MobileServiceException) exception.getCause(); ServiceFilterResponse response = cause.getResponse(); if (response == null || response.getStatus().getStatusCode() != 401) { mResult.setStatus(TestStatus.Failed); mResult.setException(exception); mResult.getTestCase().log("Expected 401"); } } else { if (exception != null) { createResultFromException(mResult, exception); } } } } else if (body == null) { try { JsonElement jsonElement = client.invokeApi(api, method, mQuery).get(); JsonObject expectedResult = new JsonObject(); expectedResult.add("user", createUserObject(mClient)); if (mQuery != null && mQuery.size() > 0) { expectedResult.add("query", createQueryObject(mQuery)); } if (!Util.compareJson(expectedResult, jsonElement)) { createResultFromException(mResult, new ExpectedValueException(expectedResult, jsonElement)); } } catch (Exception exception) { if (mExpected401) { MobileServiceException cause = (MobileServiceException) exception.getCause(); ServiceFilterResponse response = cause.getResponse(); if (response == null || response.getStatus().getStatusCode() != 401) { mResult.setStatus(TestStatus.Failed); mResult.setException(exception); mResult.getTestCase().log("Expected 401"); } } else { if (exception != null) { createResultFromException(mResult, (Exception) exception.getCause()); } } } } else { try { JsonElement jsonElement = client.invokeApi(api, body, method, mQuery).get(); JsonObject expectedResult = new JsonObject(); expectedResult.add("user", createUserObject(mClient)); if (mQuery != null && mQuery.size() > 0) { expectedResult.add("query", createQueryObject(mQuery)); } if (!Util.compareJson(expectedResult, jsonElement)) { createResultFromException(mResult, new ExpectedValueException(expectedResult, jsonElement)); } } catch (Exception exception) { if (mExpected401) { MobileServiceException cause = (MobileServiceException) exception.getCause(); ServiceFilterResponse response = cause.getResponse(); if (response == null || response.getStatus().getStatusCode() != 401) { mResult.setStatus(TestStatus.Failed); mResult.setException(exception); mResult.getTestCase().log("Expected 401"); } } else { if (exception != null) { createResultFromException(mResult, (Exception) exception.getCause()); } } } } if (callback != null) callback.onTestComplete(this, mResult); } }; return test; }
From source file:org.elasticsearch.client.RequestConverters.java
static Request getPipeline(GetPipelineRequest getPipelineRequest) { String endpoint = new EndpointBuilder().addPathPartAsIs("_ingest/pipeline") .addCommaSeparatedPathParts(getPipelineRequest.getIds()).build(); Request request = new Request(HttpGet.METHOD_NAME, endpoint); Params parameters = new Params(request); parameters.withMasterTimeout(getPipelineRequest.masterNodeTimeout()); return request; }
From source file:org.elasticsearch.client.RequestConverters.java
static Request listTasks(ListTasksRequest listTaskRequest) { if (listTaskRequest.getTaskId() != null && listTaskRequest.getTaskId().isSet()) { throw new IllegalArgumentException("TaskId cannot be used for list tasks request"); }/* www. ja va 2 s. co m*/ Request request = new Request(HttpGet.METHOD_NAME, "/_tasks"); Params params = new Params(request); params.withTimeout(listTaskRequest.getTimeout()).withDetailed(listTaskRequest.getDetailed()) .withWaitForCompletion(listTaskRequest.getWaitForCompletion()) .withParentTaskId(listTaskRequest.getParentTaskId()).withNodes(listTaskRequest.getNodes()) .withActions(listTaskRequest.getActions()).putParam("group_by", "none"); return request; }
From source file:org.elasticsearch.client.RequestConverters.java
static Request getSettings(GetSettingsRequest getSettingsRequest) throws IOException { String[] indices = getSettingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getSettingsRequest.indices(); String[] names = getSettingsRequest.names() == null ? Strings.EMPTY_ARRAY : getSettingsRequest.names(); String endpoint = endpoint(indices, "_settings", names); Request request = new Request(HttpGet.METHOD_NAME, endpoint); Params params = new Params(request); params.withIndicesOptions(getSettingsRequest.indicesOptions()); params.withLocal(getSettingsRequest.local()); params.withIncludeDefaults(getSettingsRequest.includeDefaults()); params.withMasterTimeout(getSettingsRequest.masterNodeTimeout()); return request; }
From source file:org.elasticsearch.client.RequestConverters.java
static Request getRepositories(GetRepositoriesRequest getRepositoriesRequest) { String[] repositories = getRepositoriesRequest.repositories() == null ? Strings.EMPTY_ARRAY : getRepositoriesRequest.repositories(); String endpoint = new EndpointBuilder().addPathPartAsIs("_snapshot") .addCommaSeparatedPathParts(repositories).build(); Request request = new Request(HttpGet.METHOD_NAME, endpoint); Params parameters = new Params(request); parameters.withMasterTimeout(getRepositoriesRequest.masterNodeTimeout()); parameters.withLocal(getRepositoriesRequest.local()); return request; }