本文整理匯總了Java中io.vertx.core.http.HttpMethod類的典型用法代碼示例。如果您正苦於以下問題:Java HttpMethod類的具體用法?Java HttpMethod怎麽用?Java HttpMethod使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpMethod類屬於io.vertx.core.http包,在下文中一共展示了HttpMethod類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: registerWithRouter
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
public void registerWithRouter(Router router) {
// Priming queries
router.route(HttpMethod.POST, "/prime/:clusterIdOrName").handler(this::primeQuery);
router
.route(HttpMethod.POST, "/prime/:clusterIdOrName/:datacenterIdOrName")
.handler(this::primeQuery);
router
.route(HttpMethod.POST, "/prime/:clusterIdOrName/:datacenterIdOrName/:nodeIdOrName")
.handler(this::primeQuery);
// Deleting primed queries
router.route(HttpMethod.DELETE, "/prime/:clusterIdOrName").handler(this::clearPrimedQueries);
router
.route(HttpMethod.DELETE, "/prime/:clusterIdOrName/:datacenterIdOrName")
.handler(this::clearPrimedQueries);
router
.route(HttpMethod.DELETE, "/prime/:clusterIdOrName/:datacenterIdOrName/:nodeIdOrName")
.handler(this::primeQuery);
}
示例2: registerWithRouter
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
public void registerWithRouter(Router router) {
router.route(HttpMethod.GET, "/log/:clusterIdOrName").handler(this::getQueryLog);
router
.route(HttpMethod.GET, "/log/:clusterIdOrName/:datacenterIdOrName")
.handler(this::getQueryLog);
router
.route(HttpMethod.GET, "/log/:clusterIdOrName/:datacenterIdOrName/:nodeIdOrName")
.handler(this::getQueryLog);
router.route(HttpMethod.DELETE, "/log/:clusterIdOrName").handler(this::deleteQueryLog);
router
.route(HttpMethod.DELETE, "/log/:clusterIdOrName/:datacenterIdOrName")
.handler(this::deleteQueryLog);
router
.route(HttpMethod.DELETE, "/log/:clusterIdOrName/:datacenterIdOrName/:nodeIdOrName")
.handler(this::deleteQueryLog);
}
示例3: getFormattedElement
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
@Test
public void getFormattedElement() {
AccessLogParam param = new AccessLogParam();
RoutingContext mockContext = Mockito.mock(RoutingContext.class);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
String uri = "/test/uri";
param.setRoutingContext(mockContext);
Mockito.when(mockContext.request()).thenReturn(request);
Mockito.when(request.method()).thenReturn(HttpMethod.DELETE);
Mockito.when(request.path()).thenReturn(uri);
Mockito.when(request.version()).thenReturn(HttpVersion.HTTP_1_1);
String result = ELEMENT.getFormattedElement(param);
assertEquals("\"DELETE " + uri + " HTTP/1.1\"", result);
}
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:18,代碼來源:FirstLineOfRequestElementTest.java
示例4: testLog
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
@Test
public void testLog() {
RoutingContext context = Mockito.mock(RoutingContext.class);
HttpServerRequest request = Mockito.mock(HttpServerRequest.class);
long startMillisecond = 1416863450581L;
AccessLogParam accessLogParam = new AccessLogParam().setStartMillisecond(startMillisecond)
.setRoutingContext(context);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DatetimeConfigurableElement.DEFAULT_DATETIME_PATTERN,
DatetimeConfigurableElement.DEFAULT_LOCALE);
simpleDateFormat.setTimeZone(TimeZone.getDefault());
Mockito.when(context.request()).thenReturn(request);
Mockito.when(request.method()).thenReturn(HttpMethod.DELETE);
Deencapsulation.invoke(ACCESS_LOG_HANDLER, "log", accessLogParam);
Mockito.verify(logger).info("DELETE" + " - " + simpleDateFormat.format(startMillisecond));
}
示例5: testCreateRequest
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
@Test
public void testCreateRequest() {
HttpClient client = mock(HttpClient.class);
Invocation invocation = mock(Invocation.class);
OperationMeta operationMeta = mock(OperationMeta.class);
Endpoint endpoint = mock(Endpoint.class);
URIEndpointObject address = mock(URIEndpointObject.class);
when(invocation.getEndpoint()).thenReturn(endpoint);
when(endpoint.getAddress()).thenReturn(address);
when(address.isSslEnabled()).thenReturn(false);
when(invocation.getOperationMeta()).thenReturn(operationMeta);
RestOperationMeta swaggerRestOperation = mock(RestOperationMeta.class);
when(operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION)).thenReturn(swaggerRestOperation);
IpPort ipPort = mock(IpPort.class);
when(ipPort.getPort()).thenReturn(10);
when(ipPort.getHostOrIp()).thenReturn("ever");
AsyncResponse asyncResp = mock(AsyncResponse.class);
List<HttpMethod> methods = new ArrayList<>(
Arrays.asList(HttpMethod.GET, HttpMethod.PUT, HttpMethod.POST, HttpMethod.DELETE, HttpMethod.PATCH));
for (HttpMethod method : methods) {
when(swaggerRestOperation.getHttpMethod()).thenReturn(method.toString());
HttpClientRequest obj =
VertxHttpMethod.INSTANCE.createRequest(client, invocation, ipPort, "good", asyncResp);
Assert.assertNull(obj);
}
}
示例6: logRoutes
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private Router logRoutes(Router router) {
try {
for (Route route : router.getRoutes()) {
// path is public but methods are not, we use reflection to make that accessible
@SuppressWarnings("JavaReflectionMemberAccess")
Field f = route.getClass().getDeclaredField("methods");
f.setAccessible(true);
Set<HttpMethod> methods = (Set<HttpMethod>) f.get(route);
if (isNotBlank(route.getPath())) {
methods.forEach(httpMethod -> logger.info("Route: [{}] {}", httpMethod, route.getPath()));
}
}
} catch (Exception ex) {
logger.info("Could not list a route due to: {}!", ex.getMessage());
}
return router;
}
示例7: asyncPostStringWithData
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
public static void asyncPostStringWithData(String url, String body, ContentType type, String encode, Handler<String> callback) {
checkInitialized();
HttpClientRequest req = client.requestAbs(HttpMethod.POST, url, resp -> {
resp.bodyHandler(buf -> {
callback.handle(buf.toString());
});
});
switch (type) {
case XML:
req.putHeader("content-type", "application/xml;charset=" + encode);
break;
case JSON:
req.putHeader("content-type", "application/json;charset=" + encode);
break;
case FORM:
req.putHeader("content-type", "application/x-www-form-urlencoded" + encode);
break;
}
// req.putHeader("content-length", String.valueOf(body.length()));
// req.write(body);
req.end(body, encode);
}
示例8: enableCors
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
/**
* Enables CORS
*
* @param allowedOriginPattern allowed origin
* @param allowCredentials allow credentials (true/false)
* @param maxAge in seconds
* @param allowedHeaders set of allowed headers
* @param methods list of methods ... if empty all methods are allowed @return self
* @return self
*/
public RestBuilder enableCors(String allowedOriginPattern,
boolean allowCredentials,
int maxAge,
Set<String> allowedHeaders,
HttpMethod... methods) {
corsHandler = CorsHandler.create(allowedOriginPattern)
.allowCredentials(allowCredentials)
.maxAgeSeconds(maxAge);
if (methods == null || methods.length == 0) { // if not given than all
methods = HttpMethod.values();
}
for (HttpMethod method : methods) {
corsHandler.allowedMethod(method);
}
corsHandler.allowedHeaders(allowedHeaders);
return this;
}
示例9: enableCors
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
/**
* @param router to add handler to
* @param allowedOriginPattern origin pattern
* @param allowCredentials allowed credentials
* @param maxAge in seconds
* @param allowedHeaders set of headers or null for none
* @param methods list of methods or empty for all
*/
public void enableCors(Router router,
String allowedOriginPattern,
boolean allowCredentials,
int maxAge,
Set<String> allowedHeaders,
HttpMethod... methods) {
CorsHandler handler = CorsHandler.create(allowedOriginPattern)
.allowCredentials(allowCredentials)
.maxAgeSeconds(maxAge);
if (methods == null || methods.length == 0) { // if not given than all
methods = HttpMethod.values();
}
for (HttpMethod method : methods) {
handler.allowedMethod(method);
}
handler.allowedHeaders(allowedHeaders);
router.route().handler(handler);
}
示例10: register
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
/**
* Register this but also register the {@link CorsHandler}. The
* {@link CorsHandler} will deal with the normal CORS headers after it has been
* processed initially by this handler. {@inheritDoc}
*/
@Override
public void register(final Router router) {
router.route().handler(this);
router.route().handler(CorsHandler.create(".+")
.maxAgeSeconds(600)
.allowedMethod(HttpMethod.GET)
.allowedMethod(HttpMethod.POST)
.allowedMethod(HttpMethod.PUT)
.allowedMethod(HttpMethod.DELETE)
.allowedMethod(HttpMethod.OPTIONS)
.allowedHeader("Content-Type")
.allowedHeader("Accept")
.allowedHeader("Accept-Language")
.allowedHeader("Authorization"));
}
示例11: handle
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
@Override
public void handle(RoutingContext ctx) {
StringBuilder logStrBuilder = new StringBuilder();
logStrBuilder.append(ctx.request().host()).append(" : ");
logStrBuilder.append(ctx.request().method()).append(" ");
logStrBuilder.append(ctx.request().uri()).append("\n");
if(ctx.request().method() != HttpMethod.GET) {
// Parameters show in Request URI
logStrBuilder.append("Body - ").append(ctx.request().formAttributes());
}
Log.request(logStrBuilder.toString());
ctx.next();
}
示例12: testExceptionInHandler
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
@Test
public void testExceptionInHandler() throws Exception {
{
router.route("/exception").handler(routingContext -> {
throw new IllegalArgumentException("msg");
});
request("/exception", HttpMethod.GET,500);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
MockSpan mockSpan = mockSpans.get(0);
Assert.assertEquals("GET", mockSpan.operationName());
Assert.assertEquals(6, mockSpan.tags().size());
Assert.assertEquals(Boolean.TRUE, mockSpan.tags().get(Tags.ERROR.getKey()));
Assert.assertEquals(500, mockSpan.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertEquals("GET", mockSpan.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals("http://localhost:8080/exception", mockSpan.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(1, mockSpan.logEntries().size());
Assert.assertEquals(2, mockSpan.logEntries().get(0).fields().size());
Assert.assertEquals(Tags.ERROR.getKey(), mockSpan.logEntries().get(0).fields().get("event"));
Assert.assertTrue(mockSpan.logEntries().get(0).fields().get("error.object") instanceof Throwable);
}
示例13: resolve
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
public static HttpMethod resolve(final Method method) {
// 1. Method checking.
Fn.flingUp(null == method, LOGGER,
MethodNullException.class, MethodResolver.class);
final Annotation[] annotations = method.getDeclaredAnnotations();
// 2. Method ignore
HttpMethod result = null;
for (final Annotation annotation : annotations) {
final Class<?> key = annotation.annotationType();
if (METHODS.containsKey(key)) {
result = METHODS.get(key);
break;
}
}
// 2. Ignore this method.
if (null == result) {
LOGGER.info(Info.METHOD_IGNORE, method.getName());
}
return result;
}
示例14: testNoURLMapping
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
@Test
public void testNoURLMapping() throws Exception {
{
request("/noUrlMapping", HttpMethod.GET, 404);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
MockSpan mockSpan = mockSpans.get(0);
Assert.assertEquals("GET", mockSpan.operationName());
Assert.assertEquals(5, mockSpan.tags().size());
Assert.assertEquals(404, mockSpan.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertEquals("GET", mockSpan.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals("http://localhost:8080/noUrlMapping", mockSpan.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(0, mockSpan.logEntries().size());
}
示例15: registerWithRouter
import io.vertx.core.http.HttpMethod; //導入依賴的package包/類
/**
* This method handles the registration of the various routes responsible for setting and
* retrieving cluster information via http.
*
* @param router The router to register the endpoint with.
*/
public void registerWithRouter(Router router) {
router.route(HttpMethod.POST, "/cluster").handler(this::provisionCluster);
router.route(HttpMethod.DELETE, "/cluster/:clusterIdOrName").handler(this::unregisterCluster);
router.route(HttpMethod.DELETE, "/cluster").handler(this::unregisterCluster);
router.route(HttpMethod.GET, "/cluster/:clusterIdOrName").handler(this::getCluster);
router.route(HttpMethod.GET, "/cluster").handler(this::getCluster);
}