org.apache.http.client.methods.HttpGet#METHOD_NAME源码实例Demo

下面列出了org.apache.http.client.methods.HttpGet#METHOD_NAME 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: teammates   文件: ActionFactoryTest.java
@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 + "."));
}
 
源代码2 项目: keycloak   文件: HttpClientPerformanceTest.java
public CustomRedirectStrategy() {
    this.REDIRECT_METHODS = new String[]{
        HttpGet.METHOD_NAME,
        HttpPost.METHOD_NAME,
        HttpHead.METHOD_NAME,
        HttpDelete.METHOD_NAME,
        HttpOptions.METHOD_NAME
    };
}
 
源代码3 项目: teammates   文件: BackDoor.java
/**
 * 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);
    }
}
 
源代码4 项目: teammates   文件: LegacyUrlMapperTest.java
private void setupMocks(String requestUrl) {
    mockRequest = new MockHttpServletRequest(HttpGet.METHOD_NAME, requestUrl);
    mockResponse = new MockHttpServletResponse();
}
 
源代码5 项目: teammates   文件: AutomatedServletTest.java
private void setupMocks(String requestUrl) {
    mockRequest = new MockHttpServletRequest(HttpGet.METHOD_NAME, requestUrl);
    mockResponse = new MockHttpServletResponse();
}
 
@Override
public String getMethod() {
    return HttpGet.METHOD_NAME;
}
 
源代码7 项目: Inside_Android_Testing   文件: ApiGatewayTest.java
@Override
public String getMethod() {
    return HttpGet.METHOD_NAME;
}
 
源代码8 项目: fanfouapp-opensource   文件: OAuthHelper.java
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);
}
 
源代码9 项目: teammates   文件: WebPageServletTest.java
@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());

}
 
源代码10 项目: canal   文件: RequestConvertersExt.java
/**
 * 修改 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));
}