當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpMethod類代碼示例

本文整理匯總了Java中io.gravitee.common.http.HttpMethod的典型用法代碼示例。如果您正苦於以下問題:Java HttpMethod類的具體用法?Java HttpMethod怎麽用?Java HttpMethod使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpMethod類屬於io.gravitee.common.http包,在下文中一共展示了HttpMethod類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doFilter

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    HttpServletRequest request = (HttpServletRequest) req;
    response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, request.getHeader("origin"));
    response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
    response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
    response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "POST, PUT, GET, OPTIONS, DELETE, X-XSRF-TOKEN");
    response.setHeader(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1209600");

    if (!HttpMethod.OPTIONS.equals(request.getMethod())) {
        chain.doFilter(req, res);
    }
}
 
開發者ID:gravitee-io,項目名稱:graviteeio-access-management,代碼行數:14,代碼來源:CORSFilter.java

示例2: doFilter

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
	HttpServletResponse response = (HttpServletResponse) res;
	HttpServletRequest request = (HttpServletRequest) req;
	response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN, request.getHeader("origin"));
	response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
	response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With");
	response.setHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS, "POST, PUT, GET, OPTIONS, DELETE, X-XSRF-TOKEN");
	response.setHeader(HttpHeaders.ACCESS_CONTROL_MAX_AGE, "1209600");

	if (!HttpMethod.OPTIONS.name().equals(request.getMethod())) {
		chain.doFilter(req, res);
	}
}
 
開發者ID:gravitee-io,項目名稱:gravitee-management-rest-api,代碼行數:14,代碼來源:CORSFilter.java

示例3: isPreflightRequest

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
private boolean isPreflightRequest(Request request) {
    String originHeader = request.headers().getFirst(HttpHeaders.ORIGIN);
    String accessControlRequestMethod = request.headers().getFirst(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD);
    return request.method() == HttpMethod.OPTIONS &&
            originHeader != null &&
            accessControlRequestMethod != null;
}
 
開發者ID:gravitee-io,項目名稱:gravitee-gateway,代碼行數:8,代碼來源:CorsHandler.java

示例4: shouldNotValidate_invalidEndpoint

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
@Test
public void shouldNotValidate_invalidEndpoint(TestContext context) {
    // Prepare
    EndpointRule rule = mock(EndpointRule.class);
    when(rule.endpoint()).thenReturn(createEndpoint());

    io.gravitee.definition.model.services.healthcheck.Step step = new io.gravitee.definition.model.services.healthcheck.Step();
    Request request = new Request();
    request.setPath("/");
    request.setMethod(HttpMethod.GET);

    step.setRequest(request);
    Response response = new Response();
    response.setAssertions(Collections.singletonList(Response.DEFAULT_ASSERTION));
    step.setResponse(response);

    when(rule.steps()).thenReturn(Collections.singletonList(step));

    HttpEndpointRuleHandler runner = new HttpEndpointRuleHandler(vertx, rule);
    Async async = context.async();

    // Verify
    runner.setStatusHandler(new Handler<EndpointStatus>() {
        @Override
        public void handle(EndpointStatus status) {
            Assert.assertFalse(status.isSuccess());
            async.complete();
        }
    });

    // Run
    runner.handle(null);

    // Wait until completion
    async.awaitSuccess();
}
 
開發者ID:gravitee-io,項目名稱:gravitee-gateway,代碼行數:37,代碼來源:HttpEndpointRuleHandlerTest.java

示例5: call_override_method

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
@Test
public void call_override_method() throws Exception {
    org.apache.http.client.fluent.Request request = org.apache.http.client.fluent.Request.Get("http://localhost:8082/echo/helloworld");

    org.apache.http.client.fluent.Response response = request.execute();
    HttpResponse returnResponse = response.returnResponse();

    assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode());
    assertEquals(HttpMethod.POST.name(), returnResponse.getFirstHeader("method").getValue());
}
 
開發者ID:gravitee-io,項目名稱:gravitee-gateway,代碼行數:11,代碼來源:OverrideMethodGatewayTest.java

示例6: preflight_request

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
@Test
public void preflight_request() throws Exception {
    Request request = Request.Options("http://localhost:8082/test/my_team")
            .addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.GET.name())
            .addHeader(HttpHeaders.ORIGIN, "http://localhost");

    Response response = request.execute();
    HttpResponse returnResponse = response.returnResponse();

    assertEquals(HttpStatus.SC_OK, returnResponse.getStatusLine().getStatusCode());
}
 
開發者ID:gravitee-io,項目名稱:gravitee-gateway,代碼行數:12,代碼來源:CorsTest.java

示例7: preflight_request_unauthorized

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
@Test
public void preflight_request_unauthorized() throws Exception {
    Request request = Request.Options("http://localhost:8082/test/my_team")
            .addHeader(HttpHeaders.ACCESS_CONTROL_REQUEST_METHOD, HttpMethod.GET.name())
            .addHeader(HttpHeaders.ORIGIN, "http://bad_host");

    Response response = request.execute();
    HttpResponse returnResponse = response.returnResponse();

    assertEquals(HttpStatus.SC_BAD_REQUEST, returnResponse.getStatusLine().getStatusCode());
}
 
開發者ID:gravitee-io,項目名稱:gravitee-gateway,代碼行數:12,代碼來源:CorsTest.java

示例8: setUp

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
@Before
public void setUp() throws TechnicalException {
    PropertyFilter apiMembershipTypeFilter = new ApiPermissionFilter();
    objectMapper.setFilterProvider(new SimpleFilterProvider(Collections.singletonMap("apiMembershipTypeFilter", apiMembershipTypeFilter)));

    Api api = new Api();
    api.setId(API_ID);
    api.setDescription("Gravitee.io");
    when(apiRepository.findById(API_ID)).thenReturn(Optional.of(api));
    PageEntity page = new PageEntity();
    page.setName("My Title");
    page.setOrder(1);
    page.setType(PageType.MARKDOWN.toString());
    page.setContent("Read the doc");
    when(pageService.findApiPagesByApi(API_ID)).thenReturn(Collections.singletonList(new PageListItem()));
    when(pageService.findById(any())).thenReturn(page);
    Membership membership = new Membership();
    membership.setUserId("johndoe");
    membership.setReferenceId(API_ID);
    membership.setReferenceType(MembershipReferenceType.API);
    membership.setRoles(Collections.singletonMap(RoleScope.API.getId(), SystemRole.PRIMARY_OWNER.name()));
    when(membershipRepository.findByReferenceAndRole(eq(MembershipReferenceType.API), eq(API_ID), any(), any()))
            .thenReturn(Collections.singleton(membership));
    MemberEntity memberEntity = new MemberEntity();
    memberEntity.setUsername(membership.getUserId());
    memberEntity.setRole(SystemRole.PRIMARY_OWNER.name());
    when(membershipService.getMembers(eq(MembershipReferenceType.API), eq(API_ID), eq(RoleScope.API)))
            .thenReturn(Collections.singleton(memberEntity));
    UserEntity userEntity = new UserEntity();
    userEntity.setUsername(memberEntity.getUsername());
    when(userService.findByName(memberEntity.getUsername(), false)).thenReturn(userEntity);

    api.setGroups(Collections.singleton("my-group"));
    GroupEntity groupEntity = new GroupEntity();
    groupEntity.setId("my-group");
    groupEntity.setName("My Group");
    when(groupService.findByIds(api.getGroups())).thenReturn(Collections.singleton(groupEntity));

    PlanEntity publishedPlan = new PlanEntity();
    publishedPlan.setId("plan-id");
    publishedPlan.setApis(Collections.singleton(API_ID));
    publishedPlan.setDescription("free plan");
    publishedPlan.setType(PlanType.API);
    publishedPlan.setSecurity(PlanSecurityType.API_KEY);
    publishedPlan.setValidation(PlanValidationType.AUTO);
    publishedPlan.setStatus(PlanStatus.PUBLISHED);
    Map<String, Path> paths = new HashMap<>();
    Path path = new Path();
    path.setPath("/");
    io.gravitee.definition.model.Rule rule = new io.gravitee.definition.model.Rule();
    rule.setEnabled(true);
    rule.setMethods(Collections.singletonList(HttpMethod.GET));
    Policy policy = new Policy();
    policy.setName("rate-limit");
    String ls = System.lineSeparator();
    policy.setConfiguration("{" + ls +
            "          \"rate\": {" + ls +
            "            \"limit\": 1," + ls +
            "            \"periodTime\": 1," + ls +
            "            \"periodTimeUnit\": \"SECONDS\"" + ls +
            "          }" + ls +
            "        }");
    rule.setPolicy(policy);
    path.setRules(Collections.singletonList(rule));
    paths.put("/", path);
    publishedPlan.setPaths(paths);
    PlanEntity closedPlan = new PlanEntity();
    closedPlan.setId("closedPlan-id");
    closedPlan.setApis(Collections.singleton(API_ID));
    closedPlan.setDescription("free closedPlan");
    closedPlan.setType(PlanType.API);
    closedPlan.setSecurity(PlanSecurityType.API_KEY);
    closedPlan.setValidation(PlanValidationType.AUTO);
    closedPlan.setStatus(PlanStatus.CLOSED);
    closedPlan.setPaths(paths);
    Set<PlanEntity> set = new HashSet<>();
    set.add(publishedPlan);
    set.add(closedPlan);
    when(planService.findByApi(API_ID)).thenReturn(set);
}
 
開發者ID:gravitee-io,項目名稱:gravitee-management-rest-api,代碼行數:81,代碼來源:ApiService_ExportAsJsonTest.java

示例9: getMethod

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
public HttpMethod getMethod() {
    return method;
}
 
開發者ID:gravitee-io,項目名稱:gravitee-management-rest-api,代碼行數:4,代碼來源:Request.java

示例10: setMethod

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
public void setMethod(HttpMethod method) {
    this.method = method;
}
 
開發者ID:gravitee-io,項目名稱:gravitee-management-rest-api,代碼行數:4,代碼來源:Request.java

示例11: method

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
@Override
public HttpMethod method() {
    return request.method();
}
 
開發者ID:gravitee-io,項目名稱:gravitee-gateway,代碼行數:5,代碼來源:LoggableClientRequest.java

示例12: extractHttpMethod

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
private HttpMethod extractHttpMethod(ExecutionContext executionContext, Request request) {
    io.gravitee.common.http.HttpMethod overrideMethod = (io.gravitee.common.http.HttpMethod)
            executionContext.getAttribute(ExecutionContext.ATTR_REQUEST_METHOD);
    return (overrideMethod == null) ? request.method() : overrideMethod;
}
 
開發者ID:gravitee-io,項目名稱:gravitee-gateway,代碼行數:6,代碼來源:DefaultInvoker.java

示例13: shouldValidate

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
@Test
public void shouldValidate(TestContext context) throws InterruptedException {
    // Prepare HTTP endpoint
    stubFor(get(urlEqualTo("/"))
            .willReturn(aResponse()
                    .withStatus(200)
                    .withBody("{\"status\": \"green\"}")));

    // Prepare
    EndpointRule rule = mock(EndpointRule.class);
    when(rule.endpoint()).thenReturn(createEndpoint());

    io.gravitee.definition.model.services.healthcheck.Step step = new io.gravitee.definition.model.services.healthcheck.Step();
    Request request = new Request();
    request.setPath("/");
    request.setMethod(HttpMethod.GET);

    step.setRequest(request);
    Response response = new Response();
    response.setAssertions(Collections.singletonList(Response.DEFAULT_ASSERTION));
    step.setResponse(response);
    when(rule.steps()).thenReturn(Collections.singletonList(step));

    HttpEndpointRuleHandler runner = new HttpEndpointRuleHandler(vertx, rule);

    Async async = context.async();

    // Verify
    runner.setStatusHandler(new Handler<EndpointStatus>() {
        @Override
        public void handle(EndpointStatus status) {
            Assert.assertTrue(status.isSuccess());
            async.complete();
        }
    });

    // Run
    runner.handle(null);

    // Wait until completion
    async.awaitSuccess();
}
 
開發者ID:gravitee-io,項目名稱:gravitee-gateway,代碼行數:43,代碼來源:HttpEndpointRuleHandlerTest.java

示例14: shouldNotValidate_invalidResponseBody

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
@Test
public void shouldNotValidate_invalidResponseBody(TestContext context) throws InterruptedException {
    // Prepare HTTP endpoint
    stubFor(get(urlEqualTo("/"))
            .willReturn(aResponse()
                    .withStatus(200)
                    .withBody("{\"status\": \"yellow\"}")));

    // Prepare
    EndpointRule rule = mock(EndpointRule.class);
    when(rule.endpoint()).thenReturn(createEndpoint());

    io.gravitee.definition.model.services.healthcheck.Step step = new io.gravitee.definition.model.services.healthcheck.Step();
    Request request = new Request();
    request.setPath("/");
    request.setMethod(HttpMethod.GET);

    step.setRequest(request);
    Response response = new Response();
    response.setAssertions(Collections.singletonList("#jsonPath(#response.content, '$.status') == 'green'"));
    step.setResponse(response);
    when(rule.steps()).thenReturn(Collections.singletonList(step));

    HttpEndpointRuleHandler runner = new HttpEndpointRuleHandler(vertx, rule);

    Async async = context.async();

    // Verify
    runner.setStatusHandler(new Handler<EndpointStatus>() {
        @Override
        public void handle(EndpointStatus status) {
            Assert.assertFalse(status.isSuccess());

            // When health-check is false, we store both request and response
            Step result = status.getSteps().get(0);
            Assert.assertEquals(HttpMethod.GET, result.getRequest().getMethod());
            Assert.assertNotNull(result.getResponse().getBody());

            async.complete();
        }
    });

    // Run
    runner.handle(null);

    // Wait until completion
    async.awaitSuccess();
}
 
開發者ID:gravitee-io,項目名稱:gravitee-gateway,代碼行數:49,代碼來源:HttpEndpointRuleHandlerTest.java

示例15: method

import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
@Override
public HttpMethod method() {
    return HttpMethod.valueOf(httpServerRequest.method().name());
}
 
開發者ID:gravitee-io,項目名稱:gravitee-gateway,代碼行數:5,代碼來源:VertxHttpServerRequest.java


注:本文中的io.gravitee.common.http.HttpMethod類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。