当前位置: 首页>>代码示例>>Java>>正文


Java HttpMethod类代码示例

本文整理汇总了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);
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:20,代码来源:QueryManager.java

示例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);
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:17,代码来源:ActivityLogManager.java

示例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));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:AccessLogHandlerTest.java

示例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);
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:27,代码来源:TestVertxHttpMethod.java

示例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;
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:20,代码来源:WebServerVerticle.java

示例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);
    }
 
开发者ID:Leibnizhu,项目名称:AlipayWechatPlatform,代码行数:23,代码来源:NetworkUtils.java

示例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;
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:33,代码来源:RestBuilder.java

示例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);
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:32,代码来源:RestRouter.java

示例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"));

}
 
开发者ID:trajano,项目名称:app-ms,代码行数:24,代码来源:AuthenticatedClientValidator.java

示例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();
}
 
开发者ID:JoMingyu,项目名称:Daejeon-People,代码行数:18,代码来源:LogHandlerImpl.java

示例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);
}
 
开发者ID:opentracing-contrib,项目名称:java-vertx-web,代码行数:26,代码来源:TracingHandlerTest.java

示例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;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:21,代码来源:MethodResolver.java

示例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());
}
 
开发者ID:opentracing-contrib,项目名称:java-vertx-web,代码行数:19,代码来源:TracingHandlerTest.java

示例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);
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:14,代码来源:ClusterManager.java


注:本文中的io.vertx.core.http.HttpMethod类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。