本文整理匯總了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);
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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());
}
示例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());
}
示例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());
}
示例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);
}
示例9: getMethod
import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
public HttpMethod getMethod() {
return method;
}
示例10: setMethod
import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
public void setMethod(HttpMethod method) {
this.method = method;
}
示例11: method
import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
@Override
public HttpMethod method() {
return request.method();
}
示例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;
}
示例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();
}
示例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();
}
示例15: method
import io.gravitee.common.http.HttpMethod; //導入依賴的package包/類
@Override
public HttpMethod method() {
return HttpMethod.valueOf(httpServerRequest.method().name());
}