本文整理汇总了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);
}
示例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();
}
}
示例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);
}
示例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();
}
示例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());
}
});
}
示例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);
}
示例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)
);
}
示例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());
}
示例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();
}
示例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();
}
示例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));
}
示例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);
}
示例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("]"));
}
示例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);
}
示例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());
}
});
}