Java Code Examples for org.apache.http.client.methods.HttpGet#METHOD_NAME

The following examples show how to use org.apache.http.client.methods.HttpGet#METHOD_NAME . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionFactoryTest.java    From teammates with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testGetAction() throws Exception {
    ActionFactory actionFactory = new ActionFactory();

    ______TS("Action exists and is retrieved");

    MockHttpServletRequest existingActionServletRequest = new MockHttpServletRequest(
            HttpGet.METHOD_NAME, Const.ResourceURIs.URI_PREFIX + Const.ResourceURIs.AUTH);
    existingActionServletRequest.addHeader("Backdoor-Key", Config.BACKDOOR_KEY);
    Action existingAction = actionFactory.getAction(existingActionServletRequest, HttpGet.METHOD_NAME);
    assertTrue(existingAction instanceof GetAuthInfoAction);

    ______TS("Action does not exist and ActionMappingException is thrown");

    MockHttpServletRequest nonExistentActionServletRequest = new MockHttpServletRequest(
            HttpGet.METHOD_NAME, Const.ResourceURIs.URI_PREFIX + "blahblahblah");
    nonExistentActionServletRequest.addHeader("Backdoor-Key", Config.BACKDOOR_KEY);
    ActionMappingException nonExistentActionException = assertThrows(ActionMappingException.class,
            () -> actionFactory.getAction(nonExistentActionServletRequest, HttpGet.METHOD_NAME));
    assertTrue(nonExistentActionException.getMessage()
            .equals("Resource with URI " + Const.ResourceURIs.URI_PREFIX + "blahblahblah" + " is not found."));

    ______TS("Method does not exist on action and ActionMappingException is thrown");

    MockHttpServletRequest nonExistentMethodOnActionServletRequest = new MockHttpServletRequest(
            HttpGet.METHOD_NAME, Const.ResourceURIs.URI_PREFIX + Const.ResourceURIs.AUTH);
    nonExistentMethodOnActionServletRequest.addHeader("Backdoor-Key", Config.BACKDOOR_KEY);
    ActionMappingException nonExistentMethodOnActionException = assertThrows(ActionMappingException.class,
            () -> actionFactory.getAction(nonExistentMethodOnActionServletRequest, HttpPost.METHOD_NAME));
    assertTrue(nonExistentMethodOnActionException.getMessage()
            .equals("Method [" + HttpPost.METHOD_NAME + "] is not allowed for URI "
            + Const.ResourceURIs.URI_PREFIX + Const.ResourceURIs.AUTH + "."));
}
 
Example 2
Source File: HttpClientPerformanceTest.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public CustomRedirectStrategy() {
    this.REDIRECT_METHODS = new String[]{
        HttpGet.METHOD_NAME,
        HttpPost.METHOD_NAME,
        HttpHead.METHOD_NAME,
        HttpDelete.METHOD_NAME,
        HttpOptions.METHOD_NAME
    };
}
 
Example 3
Source File: BackDoor.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Executes HTTP request with the given {@code method} and {@code relativeUrl}.
 *
 * @return The content of the HTTP response
 */
private static ResponseBodyAndCode executeRequest(
        String method, String relativeUrl, Map<String, String[]> params, String body) {
    String url = TestProperties.TEAMMATES_URL + Const.ResourceURIs.URI_PREFIX + relativeUrl;

    HttpRequestBase request;
    switch (method) {
    case HttpGet.METHOD_NAME:
        request = createGetRequest(url, params);
        break;
    case HttpPost.METHOD_NAME:
        request = createPostRequest(url, params, body);
        break;
    case HttpPut.METHOD_NAME:
        request = createPutRequest(url, params, body);
        break;
    case HttpDelete.METHOD_NAME:
        request = createDeleteRequest(url, params);
        break;
    default:
        throw new RuntimeException("Unaccepted HTTP method: " + method);
    }

    addAuthKeys(request);

    try (CloseableHttpClient httpClient = HttpClients.createDefault();
            CloseableHttpResponse response = httpClient.execute(request)) {

        String responseBody = null;
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            try (BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()))) {
                responseBody = br.lines().collect(Collectors.joining(System.lineSeparator()));
            }
        }
        return new ResponseBodyAndCode(responseBody, response.getStatusLine().getStatusCode());

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example 4
Source File: LegacyUrlMapperTest.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
private void setupMocks(String requestUrl) {
    mockRequest = new MockHttpServletRequest(HttpGet.METHOD_NAME, requestUrl);
    mockResponse = new MockHttpServletResponse();
}
 
Example 5
Source File: AutomatedServletTest.java    From teammates with GNU General Public License v2.0 4 votes vote down vote up
private void setupMocks(String requestUrl) {
    mockRequest = new MockHttpServletRequest(HttpGet.METHOD_NAME, requestUrl);
    mockResponse = new MockHttpServletResponse();
}
 
Example 6
Source File: HttpGetWithEntity.java    From elasticsearch-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public String getMethod() {
    return HttpGet.METHOD_NAME;
}
 
Example 7
Source File: ApiGatewayTest.java    From Inside_Android_Testing with Apache License 2.0 4 votes vote down vote up
@Override
public String getMethod() {
    return HttpGet.METHOD_NAME;
}
 
Example 8
Source File: OAuthHelper.java    From fanfouapp-opensource with Apache License 2.0 4 votes vote down vote up
static String buildOAuthHeader(final String method, final String url,
        List<SimpleRequestParam> params, final OAuthConfig provider,
        final OAuthToken otoken) {
    if (params == null) {
        params = new ArrayList<SimpleRequestParam>();
    }
    final long timestamp = System.currentTimeMillis() / 1000;
    final long nonce = timestamp + OAuthHelper.RAND.nextInt();
    final List<SimpleRequestParam> oauthHeaderParams = new ArrayList<SimpleRequestParam>();
    oauthHeaderParams.add(new SimpleRequestParam("oauth_consumer_key",
            provider.getConsumerKey()));
    oauthHeaderParams.add(OAuthHelper.OAUTH_SIGNATURE_METHOD);
    oauthHeaderParams.add(new SimpleRequestParam("oauth_timestamp",
            timestamp));
    oauthHeaderParams.add(new SimpleRequestParam("oauth_nonce", nonce));
    oauthHeaderParams.add(new SimpleRequestParam("oauth_version",
            OAuthHelper.OAUTH_VERSION1));
    if (null != otoken) {
        oauthHeaderParams.add(new SimpleRequestParam("oauth_token", otoken
                .getToken()));
    }
    final List<SimpleRequestParam> signatureBaseParams = new ArrayList<SimpleRequestParam>(
            oauthHeaderParams.size() + params.size());
    signatureBaseParams.addAll(oauthHeaderParams);
    if ((method != HttpGet.METHOD_NAME) && (params != null)
            && !SimpleRequestParam.hasFile(params)) {
        signatureBaseParams.addAll(params);
    }
    OAuthHelper.parseGetParams(url, signatureBaseParams);

    final String encodedUrl = OAuthHelper.encode(OAuthHelper
            .constructRequestURL(url));

    final String encodedParams = OAuthHelper.encode(OAuthHelper
            .alignParams(signatureBaseParams));

    final StringBuffer base = new StringBuffer(method).append("&")
            .append(encodedUrl).append("&").append(encodedParams);
    final String oauthBaseString = base.toString();

    if (AppContext.DEBUG) {
        Log.d(OAuthHelper.TAG, "getOAuthHeader() url=" + url);
        Log.d(OAuthHelper.TAG, "getOAuthHeader() encodedUrl=" + encodedUrl);
        Log.d(OAuthHelper.TAG, "getOAuthHeader() encodedParams="
                + encodedParams);
        Log.d(OAuthHelper.TAG, "getOAuthHeader() baseString="
                + oauthBaseString);
    }
    final SecretKeySpec spec = OAuthHelper.getSecretKeySpec(provider,
            otoken);
    oauthHeaderParams.add(new SimpleRequestParam("oauth_signature",
            OAuthHelper.getSignature(oauthBaseString, spec)));
    return "OAuth "
            + OAuthHelper.encodeParameters(oauthHeaderParams, ",", true);
}
 
Example 9
Source File: WebPageServletTest.java    From teammates with GNU General Public License v2.0 3 votes vote down vote up
@Test
public void allTests() throws Exception {

    // Nothing to test; just make sure that the response is 200

    WebPageServlet servlet = new WebPageServlet();
    MockHttpServletRequest mockRequest = new MockHttpServletRequest(HttpGet.METHOD_NAME, "http://localhost:4200");
    MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    servlet.doGet(mockRequest, mockResponse);

    assertEquals(HttpStatus.SC_OK, mockResponse.getStatus());

}
 
Example 10
Source File: RequestConvertersExt.java    From canal with Apache License 2.0 3 votes vote down vote up
/**
 * 修改 getMappings 去掉request参数
 *
 * @param getMappingsRequest
 * @return
 * @throws IOException
 */
static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOException {
    String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices();
    String[] types = getMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.types();

    return new Request(HttpGet.METHOD_NAME, RequestConverters.endpoint(indices, "_mapping", types));
}