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


Java RoutingContext类代码示例

本文整理汇总了Java中io.vertx.ext.web.RoutingContext的典型用法代码示例。如果您正苦于以下问题:Java RoutingContext类的具体用法?Java RoutingContext怎么用?Java RoutingContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RoutingContext类属于io.vertx.ext.web包,在下文中一共展示了RoutingContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFormattedElement

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
@Test
public void getFormattedElement() {
  RoutingContext mockContext = Mockito.mock(RoutingContext.class);
  AccessLogParam param = new AccessLogParam().setRoutingContext(mockContext);
  HttpServerRequest mockRequest = Mockito.mock(HttpServerRequest.class);
  VertxHttpHeaders headers = new VertxHttpHeaders();
  String testValue = "testValue";
  headers.add(HEADER_IDENTIFIER, testValue);

  Mockito.when(mockContext.request()).thenReturn(mockRequest);
  Mockito.when(mockRequest.headers()).thenReturn(headers);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals(testValue, result);
  assertEquals(ELEMENT.getIdentifier(), HEADER_IDENTIFIER);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:18,代码来源:RequestHeaderElementTest.java

示例2: addItem

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
private void addItem(RoutingContext rc) {
    String body = rc.getBodyAsString();
    if (body != null) {
        Item item = Json.decodeValue(body, Item.class);

        if (item.getQuantity() == 0) {
            redis.hdel("my-shopping-list", item.getName(), res -> {
                if (res.failed()) {
                    rc.fail(res.cause());
                } else {
                    getShoppingList(rc);
                }
            });
        } else {
            redis.hset("my-shopping-list", item.getName(), Integer.toString(item.getQuantity()), res -> {
                if (res.failed()) {
                    rc.fail(res.cause());
                } else {
                    getShoppingList(rc);
                }
            });
        }
    } else {
        rc.response().setStatusCode(400).end();
    }
}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:27,代码来源:MyShoppingListVerticle.java

示例3: attack

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
@Override
public Handler<RoutingContext> attack(final Event event) {
    return Fn.get(() -> (context) -> Responser.exec(() -> {
        // 1. Build Arguments
        final Object[] arguments = buildArgs(context, event);

        // 2. Method call
        invoke(event, arguments);

        // 3. Resource model building
        final Envelop data = Envelop.ok();

        // 4. Process modal
        Answer.reply(context, data, event);
    }, context, event), event);
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:17,代码来源:BlockAim.java

示例4: handle

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
public void handle(RoutingContext ctx) {
    HttpServerResponse response = ctx.response();
    if (userManager.isLogined(ctx)) {
        try {
            String uid = userManager.getUid(userManager.getIdFromSession(ctx));
            JobResult result = requestManager.getApiKeys(uid);
            if (result.isSuccess()) {
                SafeResultSet rs = (SafeResultSet) result.getArgs()[0];
                while (rs.next()) {
                    //
                    //
                    //
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
            response.setStatusCode(500);
        }
    } else {
        response.setStatusCode(400);
    }
    response.end();
    response.close();
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:25,代码来源:APIKeyManageRouter.java

示例5: addToList

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
private void addToList(RoutingContext rc) {
    JsonObject json = rc.getBodyAsJson();
    int quantity = json.getInteger("quantity", 1);
    if (quantity <= 0) {
        rc.response().setStatusCode(400);
        return;
    }

    redis.hset(KEY, json.getString("name"), Integer.toString(quantity), r -> {
        if (r.succeeded()) {
            getList(rc);
        } else {
            rc.fail(r.cause());
        }
    });

}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:18,代码来源:MyShoppingVerticle.java

示例6: attack

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
@Override
public Handler<RoutingContext> attack(final Event event) {
    return Fn.get(() -> (context) -> Responser.exec(() -> {
        // 1. Build Arguments
        final Object[] arguments = buildArgs(context, event);

        // 2. Method call
        final Object result = invoke(event, arguments);

        // 3. Resource model building
        final Envelop data = Flower.continuous(context, result);

        // 4. Rpc Client Call to send the data.
        final Future<Envelop> handler = TunnelClient.create(getClass())
                .connect(context.vertx())
                .connect(event)
                .send(data);
        // 5. Reply
        handler.setHandler(res -> Answer.reply(context, res.result()));
    }, context, event), event);
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:22,代码来源:IpcAim.java

示例7: buildSuccess

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
public <B> void buildSuccess(RoutingContext routingContext, B body) {
    LOG.debug("Building success message");

    Completable.fromAction(
            () ->
                    routingContext.response()
                            .setStatusCode(200)
                            .putHeader(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE)
                            .putHeader("Link", buildLinkHeaderValue())
                            .end(body != null ? Json.encodePrettily(body) : StringUtils.EMPTY))
            .subscribeOn(Schedulers.io())
            .subscribe(
                    () -> {}, // Do nothing on success
                    (ex) -> routingContext.fail(ex)
            );
}
 
开发者ID:Atypon-OpenSource,项目名称:wayf-cloud,代码行数:17,代码来源:ResponseWriter.java

示例8: rootHandler

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
/**
 * Handler for the /api endpoint, listing out routes and loaded verticles
 * 
 * @param ctx
 */
private void rootHandler(final RoutingContext ctx) {
	ctx.response().putHeader(Constants.CONTENT_HEADER, Constants.CONTENT_TYPE_JSON);
	final JsonObject result = new JsonObject().put("RunningSince", Utils.getDateString(this.startDate));
	final JsonObject routeObject = new JsonObject();
	for (final Route r : this.router.getRoutes()) {
		final String p = r.getPath();
		if (p != null) {
			routeObject.put(p, String.valueOf(r));
		}
	}
	result.put("Routes", routeObject);
	final JsonArray verticleArray = new JsonArray(this.loadedVerticles);
	result.put("Verticles", verticleArray);
	ctx.response().end(result.encodePrettily());
}
 
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:21,代码来源:ApplicationStarter.java

示例9: handle

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
@Override
public void handle(RoutingContext ctx) {
	if(!AdminManager.isAdmin(ctx)) {
		ctx.response().setStatusCode(204).end();
		ctx.response().close();
		return;
	}
	
	int surveyNo = Integer.parseInt(ctx.request().getFormAttribute("survey_no"));
	String title = ctx.request().getFormAttribute("title");
	boolean isObjective = Boolean.parseBoolean(ctx.request().getFormAttribute("is_objective"));
	
	if(isObjective) {
		// true면 객관식, false면 주관식
		String objects = ctx.request().getFormAttribute("objects");
		
		DB.executeUpdate("INSERT INTO survey_question(survey_no, title, is_objective, objects) VALUES(?, ?, ?, ?)", surveyNo, title, isObjective, objects);
	} else {
		DB.executeUpdate("INSERT INTO survey_question(survey_no, title, is_objective) VALUES(?, ?, ?)", surveyNo, title, isObjective);
	}
	
	ctx.response().setStatusCode(201).end();
	ctx.response().close();
}
 
开发者ID:DSM-DMS,项目名称:DMS,代码行数:25,代码来源:AddSurveyQuestion.java

示例10: in

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
@Override
public Object[] in(final RoutingContext context,
                   final Event event)
        throws WebException {
    /** Consume mime type matching **/
    final MediaType requestMedia = getMedia(context);
    MediaAtom.accept(event, requestMedia);

    /** Extract definition from method **/
    final List<Epsilon<Object>> epsilons =
            this.income.in(context, event);

    /** Extract value list **/
    return epsilons.stream()
            .map(Epsilon::getValue).toArray();
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:17,代码来源:MediaAnalyzer.java

示例11: registerSessionId

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
private void registerSessionId(RoutingContext ctx, String id) {
	/*
	 * keepLogin 설정에 따라 세션 혹은 쿠키 설정
	 */
	
	String sessionId = getSessionFromId(id);
	// 이미 할당된 session id가 있는지 확인
	
	if(sessionId == null) {
		// 할당된 session id가 없는 경우 create
		sessionId = createSessionId();
	}
	
	// keep_login 설정에 따라 쿠키 또는 세션 put
	SessionUtil.createCookie(ctx, "UserSession", sessionId);
	MySQL.executeUpdate("UPDATE account SET session_id=? WHERE id=?", sessionId, AES256.encrypt(id));
}
 
开发者ID:JoMingyu,项目名称:Daejeon-People,代码行数:18,代码来源:Signin.java

示例12: getFormattedElementOnNotFound

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
@Test
public void getFormattedElementOnNotFound() {
  AccessLogParam param = new AccessLogParam();
  RoutingContext mockContext = Mockito.mock(RoutingContext.class);
  HttpServerResponse mockResponse = Mockito.mock(HttpServerResponse.class);
  VertxHttpHeaders headers = new VertxHttpHeaders();
  String headerValue = "headerValue";

  param.setRoutingContext(mockContext);
  headers.add("anotherHeader", headerValue);

  Mockito.when(mockContext.response()).thenReturn(mockResponse);
  Mockito.when(mockResponse.headers()).thenReturn(headers);

  String result = ELEMENT.getFormattedElement(param);

  assertEquals("-", result);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:ResponseHeaderElementTest.java

示例13: writeDatasetContents

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
private void writeDatasetContents(
    RoutingContext routingContext, Observable<DataEnvelope> datasetContents) {
  HttpServerResponse httpServerResponse =
      jsonContentType(routingContext.response()).setChunked(true);

  final AtomicBoolean isFirst = new AtomicBoolean(true);
  datasetContents.subscribe(
      (DataEnvelope dataEnvelope) -> {
        if (!isFirst.get()) {
          httpServerResponse.write(",");
        } else {
          isFirst.set(false);
          httpServerResponse.write("[");
        }
        httpServerResponse.write(new JsonObject(dataEnvelope.getPayload()).encodePrettily());
      },
      throwable -> GlobalExceptionHandler.error(routingContext, throwable),
      () -> httpServerResponse.end("]"));
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:20,代码来源:DatasetResource.java

示例14: failureHandlerErrorDataWithInvocation

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
@Test
public void failureHandlerErrorDataWithInvocation(@Mocked RoutingContext context, @Mocked InvocationException e) {
  RestProducerInvocation restProducerInvocation = new RestProducerInvocation();

  ErrorDataDecoderException edde = new ErrorDataDecoderException(e);
  new Expectations() {
    {
      context.get(RestConst.REST_PRODUCER_INVOCATION);
      result = restProducerInvocation;
      context.failure();
      returns(edde, edde);
    }
  };

  Deencapsulation.invoke(dispatcher, "failureHandler", context);

  Assert.assertSame(e, this.throwable);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:TestVertxRestDispatcher.java

示例15: pageRenderingHandler

import io.vertx.ext.web.RoutingContext; //导入依赖的package包/类
private void pageRenderingHandler(RoutingContext context) {
  String requestedPage = context.request().getParam("page");
  dbService.fetchPage(requestedPage, reply -> {
    if (reply.succeeded()) {

      JsonObject payLoad = reply.result();
      boolean found = payLoad.getBoolean("found");
      String rawContent = payLoad.getString("rawContent", EMPTY_PAGE_MARKDOWN);
      context.put("title", requestedPage);
      context.put("id", payLoad.getInteger("id", -1));
      context.put("newPage", found ? "no" : "yes");
      context.put("rawContent", rawContent);
      context.put("content", Processor.process(rawContent));
      context.put("timestamp", new Date().toString());

      templateEngine.render(context, "templates", "/page.ftl", ar -> {
        if (ar.succeeded()) {
          context.response().putHeader("Content-Type", "text/html");
          context.response().end(ar.result());
        } else {
          context.fail(ar.cause());
        }
      });

    } else {
      context.fail(reply.cause());
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:30,代码来源:HttpServerVerticle.java


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