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.zumoe2etestapp.tests.CustomApiTests.java
private TestCase createTypedApiTest(final Random rndGen, final TypedTestType testType) { String name = String.format("Typed Overload - %s", testType); TestCase test = new TestCase(name) { MobileServiceClient mClient;//from ww w . j a v a 2 s. c o m List<Pair<String, String>> mQuery; TestExecutionCallback mCallback; Movie[] mExpectedResult = null; TestResult mResult; @Override protected void executeTest(MobileServiceClient client, TestExecutionCallback callback) { mResult = new TestResult(); mResult.setTestCase(this); mResult.setStatus(TestStatus.Passed); mClient = client; mCallback = callback; final StringIdMovie ramdomMovie = QueryTestData.getRandomStringIdMovie(rndGen); log("Using movie: " + ramdomMovie.getTitle()); String apiName = MOVIEFINDER_API_NAME; String apiUrl; switch (testType) { case GetByTitle: apiUrl = apiName + "/title/" + ramdomMovie.getTitle(); log("API: " + apiUrl); mExpectedResult = new StringIdMovie[] { ramdomMovie }; try { AllStringIdMovies result = mClient .invokeApi(apiUrl, HttpGet.METHOD_NAME, null, AllStringIdMovies.class).get(); if (!Util.compareArrays(mExpectedResult, result.getMovies())) { createResultFromException(mResult, new ExpectedValueException( Util.arrayToString(mExpectedResult), Util.arrayToString(result.getMovies()))); } } catch (Exception exception) { createResultFromException(mResult, exception); } finally { mCallback.onTestComplete(mResult.getTestCase(), mResult); } break; case GetByDate: final Date releaseDate = ramdomMovie.getReleaseDate(); TimeZone tz = TimeZone.getTimeZone("UTC"); Calendar c = Calendar.getInstance(tz); c.setTime(releaseDate); apiUrl = apiName + "/date/" + c.get(Calendar.YEAR) + "/" + (c.get(Calendar.MONTH) + 1) + "/" + c.get(Calendar.DATE); log("API: " + apiUrl); SimpleMovieFilter dateFilter = new SimpleMovieFilter() { @Override protected boolean criteria(Movie movie) { return movie.getReleaseDate().equals(releaseDate); } }; mExpectedResult = dateFilter.filter(QueryTestData.getAllStringIdMovies()).elements .toArray(new Movie[0]); try { AllStringIdMovies result = mClient .invokeApi(apiUrl, HttpGet.METHOD_NAME, null, AllStringIdMovies.class).get(); if (!Util.compareArrays(mExpectedResult, result.getMovies())) { createResultFromException(mResult, new ExpectedValueException( Util.arrayToString(mExpectedResult), Util.arrayToString(result.getMovies()))); } } catch (Exception exception) { createResultFromException(mResult, exception); } finally { mCallback.onTestComplete(mResult.getTestCase(), mResult); } break; case PostByDuration: case PostByYear: String orderBy = null; switch (rndGen.nextInt(3)) { case 0: orderBy = null; break; case 1: orderBy = "title"; break; case 2: orderBy = "title"; //duration break; } mQuery = null; if (orderBy != null) { mQuery = new ArrayList<Pair<String, String>>(); mQuery.add(new Pair<String, String>("orderBy", orderBy)); log("OrderBy: " + orderBy); } if (testType == TypedTestType.PostByYear) { apiUrl = apiName + "/moviesOnSameYear"; } else { apiUrl = apiName + "/moviesWithSameDuration"; } log("API: " + apiUrl); final String orderByCopy = orderBy; SimpleMovieFilter movieFilter = new SimpleMovieFilter() { @Override protected boolean criteria(Movie movie) { if (testType == TypedTestType.PostByYear) { return movie.getYear() == ramdomMovie.getYear(); } else { return movie.getDuration() == ramdomMovie.getDuration(); } } @Override protected List<Movie> applyOrder(List<? extends Movie> movies) { if (orderByCopy == null || orderByCopy.equals("title")) { Collections.sort(movies, new MovieComparator("getTitle")); } else if (orderByCopy.equals("duration")) { Collections.sort(movies, new MovieComparator("getDuration")); } return new ArrayList<Movie>(movies); } }; mExpectedResult = movieFilter.filter(QueryTestData.getAllStringIdMovies()).elements .toArray(new Movie[0]); if (mQuery == null) { try { AllStringIdMovies result = mClient.invokeApi(apiUrl, ramdomMovie, HttpPost.METHOD_NAME, null, AllStringIdMovies.class).get(); if (!Util.compareArrays(mExpectedResult, result.getMovies())) { createResultFromException(mResult, new ExpectedValueException(Util.arrayToString(mExpectedResult), Util.arrayToString(result.getMovies()))); } } catch (Exception exception) { createResultFromException(mResult, exception); } finally { mCallback.onTestComplete(mResult.getTestCase(), mResult); } } else { try { AllStringIdMovies result = mClient.invokeApi(apiUrl, ramdomMovie, HttpPost.METHOD_NAME, mQuery, AllStringIdMovies.class).get(); if (!Util.compareArrays(mExpectedResult, result.getMovies())) { createResultFromException(mResult, new ExpectedValueException(Util.arrayToString(mExpectedResult), Util.arrayToString(result.getMovies()))); } } catch (Exception exception) { createResultFromException(mResult, exception); } finally { mCallback.onTestComplete(mResult.getTestCase(), mResult); } } break; } } }; return test; }
From source file:org.deviceconnect.android.manager.setting.ReqResDebugActivity.java
/** * ??.//from ww w . j a va 2s.c o m * @param clientId ID * @param clientSecret * @param listener */ private void requestAccessToken(final String clientId, final String clientSecret, final AccessTokenListener listener) { String signature = createSignature(clientId, mScopes, clientSecret); URIBuilder builder = createURIBuilder(); builder.setProfile(AuthorizationProfileConstants.PROFILE_NAME); builder.setAttribute(AuthorizationProfileConstants.ATTRIBUTE_REQUEST_ACCESS_TOKEN); builder.addParameter(AuthorizationProfileConstants.PARAM_CLIENT_ID, clientId); builder.addParameter(AuthorizationProfileConstants.PARAM_SCOPE, combineStr(mScopes)); builder.addParameter(AuthorizationProfileConstants.PARAM_APPLICATION_NAME, getPackageName()); builder.addParameter(AuthorizationProfileConstants.PARAM_GRANT_TYPE, AuthorizationProfileConstants.GrantType.AUTHORIZATION_CODE.getValue()); builder.addParameter(AuthorizationProfile.PARAM_SIGNATURE, signature); executeHttpRequest(HttpGet.METHOD_NAME, builder, new HttpListener() { @Override public void onReceivedResponse(final String response) { try { parseRequestAccessToken(new JSONObject(response), listener); } catch (JSONException e) { if (listener != null) { listener.onReceivedError(); } } } }); }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testGetMapping() throws IOException { GetMappingsRequest getMappingRequest = new GetMappingsRequest(); String[] indices = Strings.EMPTY_ARRAY; if (randomBoolean()) { indices = randomIndicesNames(0, 5); getMappingRequest.indices(indices); } else if (randomBoolean()) { getMappingRequest.indices((String[]) null); }/*from ww w . j av a2 s .c om*/ String type = null; if (randomBoolean()) { type = randomAlphaOfLengthBetween(3, 10); getMappingRequest.types(type); } else if (randomBoolean()) { getMappingRequest.types((String[]) null); } Map<String, String> expectedParams = new HashMap<>(); setRandomIndicesOptions(getMappingRequest::indicesOptions, getMappingRequest::indicesOptions, expectedParams); setRandomMasterTimeout(getMappingRequest, expectedParams); setRandomLocal(getMappingRequest, expectedParams); Request request = RequestConverters.getMappings(getMappingRequest); StringJoiner endpoint = new StringJoiner("/", "/", ""); String index = String.join(",", indices); if (Strings.hasLength(index)) { endpoint.add(index); } endpoint.add("_mapping"); if (type != null) { endpoint.add(type); } assertThat(endpoint.toString(), equalTo(request.getEndpoint())); assertThat(expectedParams, equalTo(request.getParameters())); assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod())); }
From source file:com.wudaosoft.net.httpclient.Request.java
public WorkerBuilder get(String url) { return new WorkerBuilder(this, HttpGet.METHOD_NAME, url); }
From source file:niproxy.NiProxyMonitor.java
@Override public void handle(HttpRequest request, HttpResponse response, NHttpResponseTrigger trigger, HttpContext context) throws HttpException, IOException { if (request.getRequestLine().getMethod().equalsIgnoreCase(HttpGet.METHOD_NAME) || request.getRequestLine().getMethod().equalsIgnoreCase("POST")) { // Check if the request should be handled executor.execute(new NIRequestHandler(request, response, trigger, context)); } else {//from w w w . j a v a 2 s. c om // execute the request through the proxy executor.execute(new TransparentRequestHandler(request, response, trigger, context)); } }
From source file:org.elasticsearch.client.RequestConvertersTests.java
public void testGetSettings() throws IOException { String[] indicesUnderTest = randomBoolean() ? null : randomIndicesNames(0, 5); GetSettingsRequest getSettingsRequest = new GetSettingsRequest().indices(indicesUnderTest); Map<String, String> expectedParams = new HashMap<>(); setRandomMasterTimeout(getSettingsRequest, expectedParams); setRandomIndicesOptions(getSettingsRequest::indicesOptions, getSettingsRequest::indicesOptions, expectedParams);//from www . ja v a 2s . c o m setRandomLocal(getSettingsRequest, expectedParams); if (randomBoolean()) { // the request object will not have include_defaults present unless it is set to // true getSettingsRequest.includeDefaults(randomBoolean()); if (getSettingsRequest.includeDefaults()) { expectedParams.put("include_defaults", Boolean.toString(true)); } } StringJoiner endpoint = new StringJoiner("/", "/", ""); if (indicesUnderTest != null && indicesUnderTest.length > 0) { endpoint.add(String.join(",", indicesUnderTest)); } endpoint.add("_settings"); if (randomBoolean()) { String[] names = randomBoolean() ? null : new String[randomIntBetween(0, 3)]; if (names != null) { for (int x = 0; x < names.length; x++) { names[x] = randomAlphaOfLengthBetween(3, 10); } } getSettingsRequest.names(names); if (names != null && names.length > 0) { endpoint.add(String.join(",", names)); } } Request request = RequestConverters.getSettings(getSettingsRequest); assertThat(endpoint.toString(), equalTo(request.getEndpoint())); assertThat(request.getParameters(), equalTo(expectedParams)); assertThat(request.getMethod(), equalTo(HttpGet.METHOD_NAME)); assertThat(request.getEntity(), nullValue()); }
From source file:org.elasticsearch.client.IndicesClientIT.java
public void testOpenExistingIndex() throws IOException { String index = "index"; createIndex(index, Settings.EMPTY);//from w w w. j a va 2s. co m closeIndex(index); 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)); OpenIndexRequest openIndexRequest = new OpenIndexRequest(index); OpenIndexResponse openIndexResponse = execute(openIndexRequest, highLevelClient().indices()::open, highLevelClient().indices()::openAsync); assertTrue(openIndexResponse.isAcknowledged()); Response response = client().performRequest(HttpGet.METHOD_NAME, index + "/_search"); assertThat(response.getStatusLine().getStatusCode(), equalTo(RestStatus.OK.getStatus())); }
From source file:org.deviceconnect.android.manager.setting.ReqResDebugActivity.java
/** * Network Service Discovery?.//from w w w. j a v a2s . com * ?????????ID?? */ private void executeNetworkServiceDiscovery() { if (mSettings.isUseALocalOAuth()) { boolean result = checkAuthorization(new Runnable() { @Override public void run() { executeNetworkServiceDiscovery(); } }); if (result) { return; } } URIBuilder builder = createURIBuilder(); builder.setProfile(NetworkServiceDiscoveryProfile.PROFILE_NAME); builder.setAttribute(NetworkServiceDiscoveryProfile.ATTRIBUTE_GET_NETWORK_SERVICES); if (mSettings.isUseALocalOAuth()) { String accessToken = mPref.getString(KEY_ACCESS_TOKEN, null); builder.addParameter(DConnectMessage.EXTRA_ACCESS_TOKEN, accessToken); } URI uri = null; try { uri = builder.build(); } catch (URISyntaxException e) { // URI??? return; } executeHttpRequest(HttpGet.METHOD_NAME, uri, new HttpListener() { @Override public void onReceivedResponse(final String response) { parseNetworkServieDiscovery(response); } }); }
From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.tests.MiscTests.java
private TestCase createHttpContentApiTest() { String name = "Use \"text/plain\" Content and \"identity\" Encoding Headers"; TestCase test = new TestCase(name) { MobileServiceClient mClient;//from w w w . j a v a 2 s . c o m List<Pair<String, String>> mQuery; List<Pair<String, String>> mHeaders; TestExecutionCallback mCallback; JsonObject mExpectedResult; int mExpectedStatusCode; String mHttpMethod; byte[] mContent; TestResult mResult; @Override protected void executeTest(MobileServiceClient client, TestExecutionCallback callback) { mResult = new TestResult(); mResult.setTestCase(this); mResult.setStatus(TestStatus.Passed); mClient = client; mCallback = callback; createHttpContentTestInput(); try { ServiceFilterResponse response = mClient .invokeApi(APP_API_NAME, mContent, mHttpMethod, mHeaders, mQuery).get(); Exception ex = validateResponse(response); if (ex != null) { createResultFromException(mResult, ex); } else { mResult.getTestCase().log("Header validated successfully"); String responseContent = response.getContent(); mResult.getTestCase().log("Response content: " + responseContent); JsonElement jsonResponse = null; String decodedContent = responseContent.replace("__{__", "{").replace("__}__", "}") .replace("__[__", "[").replace("__]__", "]"); jsonResponse = new JsonParser().parse(decodedContent); if (!Util.compareJson(mExpectedResult, jsonResponse)) { createResultFromException(mResult, new ExpectedValueException(mExpectedResult, jsonResponse)); } } mCallback.onTestComplete(mResult.getTestCase(), mResult); } catch (Exception exception) { createResultFromException(exception); mCallback.onTestComplete(mResult.getTestCase(), mResult); return; } } ; private Exception validateResponse(ServiceFilterResponse response) { if (mExpectedStatusCode != response.getStatus().getStatusCode()) { mResult.getTestCase().log("Invalid status code"); String content = response.getContent(); if (content != null) { mResult.getTestCase().log("Response: " + content); } return new ExpectedValueException(mExpectedStatusCode, response.getStatus().getStatusCode()); } else { return null; } } private void createHttpContentTestInput() { mHttpMethod = HttpGet.METHOD_NAME; log("Method = " + mHttpMethod); mExpectedResult = new JsonObject(); mExpectedResult.addProperty("method", mHttpMethod); JsonObject user = new JsonObject(); user.addProperty("level", "anonymous"); mExpectedResult.add("user", user); mHeaders = new ArrayList<Pair<String, String>>(); mHeaders.add(new Pair<String, String>("Accept", "text/plain")); mHeaders.add(new Pair<String, String>("Accept-Encoding", "identity")); mQuery = new ArrayList<Pair<String, String>>(); mQuery.add(new Pair<String, String>("format", "other")); mExpectedStatusCode = 200; } }; return test; }
From source file:org.elasticsearch.client.RequestConverters.java
static Request searchTemplate(SearchTemplateRequest searchTemplateRequest) throws IOException { Request request;// www. ja v a 2 s . c o m if (searchTemplateRequest.isSimulate()) { request = new Request(HttpGet.METHOD_NAME, "_render/template"); } else { SearchRequest searchRequest = searchTemplateRequest.getRequest(); String endpoint = endpoint(searchRequest.indices(), searchRequest.types(), "_search/template"); request = new Request(HttpGet.METHOD_NAME, endpoint); Params params = new Params(request); addSearchRequestParams(params, searchRequest); } request.setEntity(createEntity(searchTemplateRequest, REQUEST_BODY_CONTENT_TYPE)); return request; }