本文整理汇总了Java中io.vertx.ext.web.RoutingContext.request方法的典型用法代码示例。如果您正苦于以下问题:Java RoutingContext.request方法的具体用法?Java RoutingContext.request怎么用?Java RoutingContext.request使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.ext.web.RoutingContext
的用法示例。
在下文中一共展示了RoutingContext.request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
public void handle(RoutingContext ctx) {
HttpServerResponse response = ctx.response();
HttpServerRequest request = ctx.request();
String apiKey = request.getParam("api_key");
String host = request.getParam("host_name");
if (Guardian.checkParameters(apiKey, host) && userManager.isLogined(ctx)) {
try {
String uid = userManager.getUid(userManager.getIdFromSession(ctx));
if(requestManager.addHost(uid, apiKey, host)){
response.setStatusCode(200);
}else{
response.setStatusCode(304);
}
} catch (SQLException e) {
e.printStackTrace();
response.setStatusCode(500);
}
} else {
response.setStatusCode(400);
}
response.end();
response.close();
}
示例2: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext context) {
HttpServerRequest request = context.request();
// we need to keep state since we can be called again on reroute
Boolean handled = context.get(BODY_HANDLED);
if (handled == null || !handled) {
BHandler handler = new BHandler(context);
request.handler(handler);
request.endHandler(v -> handler.end());
context.put(BODY_HANDLED, true);
} else {
// on reroute we need to re-merge the form params if that was desired
if (mergeFormAttributes && request.isExpectMultipart()) {
request.params().addAll(request.formAttributes());
}
context.next();
}
}
示例3: updateAlipayPaySetting
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
private void updateAlipayPaySetting(RoutingContext rc) {
if (forbidAccess(rc, "uid", true)) {
return;
}
HttpServerRequest req = rc.request();
HttpServerResponse resp = rc.response().putHeader("content-type", "application/json; charset=utf-8");
//解析参数
Long uid = Long.parseLong(req.getParam("uid"));
Integer paySwitch = Integer.parseInt(req.getParam("paySwitch"));
String appId = req.getParam("appId");
String appPrivKey = req.getParam("appPrivKey");
String zfbPubKey = req.getParam("zfbPubKey");
//参数检查
if (paySwitch == 1 && !CommonUtils.notEmptyString(appId, appPrivKey, zfbPubKey)) {
resp.end(new JsonObject().put("status", "invalid").toString());
return;
}
//保存支付参数
JsonObject acc = new JsonObject().put(ID, uid).put(ZFBAPPID, appId).put(ZFBPRIVKEY, appPrivKey).put(ZFBPUBKEY, zfbPubKey).put(ZFBPAYON, paySwitch);
updatePaySetting(resp, acc, COMMAND_UPDATE_ALIPAY);
}
示例4: updateOfficialAccount
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
/**
* 更新公众号配置
* 请求方法:PUT
* 请求参数:id,name邮箱,appid,appsecret,verify
* 响应:success或fail
*/
private void updateOfficialAccount(RoutingContext rc) {
if (forbidAccess(rc, "id", true)) {
return;
}
HttpServerRequest req = rc.request();
Long id = Long.valueOf(req.getParam("id"));
String name = req.getParam("name");
String appid = req.getParam("appid");
String appsecret = req.getParam("appsecret");
String verify = req.getParam("verify");
JsonObject updateAcc = new JsonObject().put(ID, id).put(NAME, name).put(WXAPPID, appid).put(WXAPPSECRET, appsecret).put(VERIFY, verify);
log.debug("更新公众号配置:{}", updateAcc);
vertx.eventBus().<Integer>send(ADDR_ACCOUNT_DB.get(), makeMessage(COMMAND_UPDATE_NORMAL, updateAcc), ar -> {
HttpServerResponse response = rc.response();
if(ar.succeeded()){
Integer rows = ar.result().body();
response.putHeader("content-type", "application/json; charset=utf-8").end(rows > 0 ? "success" : "fail");
} else {
log.error("EventBus消息响应错误", ar.cause());
response.setStatusCode(500).end("EventBus error!");
}
});
}
示例5: refuseNonLanAccess
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
/**
* 判断当前请求是否允许,如果不允许,则将状态码设为403并结束响应
*
* @return true:禁止访问 false=允许访问
* @author Leibniz.Hu
*/
protected boolean refuseNonLanAccess(RoutingContext rc) {
HttpServerRequest req = rc.request();
HttpServerResponse resp = rc.response();
String realIp = req.getHeader("X-Real-IP");
String xforward = req.getHeader("X-Forwarded-For");
//禁止外网访问
if (realIp != null && !isLanIP(realIp)) {
log.warn("检测到非法访问,来自X-Real-IP={}", realIp);
resp.setStatusCode(403).end();
return true;
}
if (xforward != null && !isLanIP(xforward)) {
log.warn("检测到非法访问,来自X-Forwarded-For={}", xforward);
resp.setStatusCode(403).end();
return true;
}
return false;
}
示例6: VertxHttpRequest
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
public VertxHttpRequest(final RoutingContext context,
final ResteasyUriInfo uriInfo,
final ResteasyProviderFactory providerFactory) {
super(uriInfo);
this.context = context;
vertxRequest = context.request();
httpHeaders = new VertxRoutingContextHttpHeaders(context);
LOG.debug("vertxRequest.isEnded={}", vertxRequest.isEnded());
if (!vertxRequest.isEnded()) {
is = new VertxBlockingInputStream(vertxRequest);
} else {
is = NullInputStream.nullInputStream();
}
asynchronousContext = new VertxExecutionContext(context, providerFactory, this);
}
示例7: oauthBaseCallback
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
/**
* 支付宝静默授权的回调方法
* 由支付宝服务器调用
*
* @param rc Vertx的RoutingContext对象
* @author Leibniz.Hu
*/
private void oauthBaseCallback(RoutingContext rc) {
HttpServerRequest req = rc.request();
HttpServerResponse resp = rc.response();
Integer eid = Integer.parseInt(req.getParam("eid"));
getAccountAndExecute(resp, eid, aliAcc -> {
AlipaySystemOauthTokenResponse oauthRes = AliPayApi.getUserId(aliAcc, req);
oauthSuccessProcess(req, resp, oauthRes, url -> log.info("授权成功,OpenID={},{},准备跳转到{}", oauthRes.getUserId(), oauthRes.getAlipayUserId(), url));
});
}
示例8: oauthInfoCallback
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
/**
* 支付宝普通授权(获取用户信息)的回调方法
* 由支付宝服务器调用
*
* @param rc Vertx的RoutingContext对象
* @author Leibniz.Hu
*/
private void oauthInfoCallback(RoutingContext rc) {
HttpServerRequest req = rc.request();
HttpServerResponse resp = rc.response();
Integer eid = Integer.parseInt(req.getParam("eid"));
getAccountAndExecute(resp, eid, aliAcc -> {
AlipayUserInfoShareResponse oauthRes = AliPayApi.getUserDetailInfo(aliAcc, req);
oauthSuccessProcess(req, resp, oauthRes, url -> log.info("授权成功,OpenID={},准备跳转到{}", oauthRes.getUserId(), url));
});
}
示例9: apply
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public Object apply(final String name,
final Class<?> paramType,
final RoutingContext context) {
// Extract request from header
final HttpServerRequest request = context.request();
return ZeroSerializer.getValue(paramType, request.getHeader(name));
}
示例10: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext ctx, Server server, DiscordBot bot, DSLContext database) {
HttpServerRequest request = ctx.request();
HttpServerResponse response = ctx.response();
String userId = ServerUtils.authUser(request, response, config);
if (userId == null) {
return;
}
OauthsecretsRecord record = database.selectFrom(Tables.OAUTHSECRETS)
.where(Tables.OAUTHSECRETS.USERID.eq(userId))
.fetchAny();
if (record == null) {
response.setStatusCode(403);
response.end();
return;
}
List<Guild> jimGuilds = bot.getGuilds();
String[] userGuilds = getGuildsOfUser(record);
List<GuildEntity> result = jimGuilds.stream()
.filter((guild) -> isInUserGuilds(guild, userGuilds))
.map((guild) -> {
String url = guild.getIconUrl();
return new GuildEntity(guild.getId(), guild.getName(), url);
})
.collect(Collectors.toList());
Gson gson = new Gson();
response.putHeader("Content-Type", "application/json");
response.end(gson.toJson(result));
}
示例11: search
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public Record search(final List<Record> records,
final RoutingContext context) {
final HttpServerRequest request = context.request();
// Input source
final String uri = request.uri();
final Optional<Record> hitted =
records.stream()
.filter(record -> isMatch(uri, record))
.findAny();
// Find valid;
return hitted.orElse(null);
}
示例12: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext rc) {
HttpServerRequest clientRequest = rc.request();
String uri = clientRequest.uri();
uri = appObj.offsetUrl(uri);
appObj.takeRequest(rc, clientRequest, uri, ar -> {
HttpServerResponse clientResponse = rc.response();
if (ar.succeeded()) {
this.handle(clientRequest, clientResponse, ar.result());
} else {
if (ar.cause() instanceof TimeoutException)
clientResponse.setStatusCode(HttpStatus.Request_Timeout);
else
clientResponse.setStatusCode(HttpStatus.Service_Unavailable);
// ar.cause().printStackTrace();
}
if (!clientResponse.ended())
clientResponse.end();
});
}
示例13: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext ctx, Server server, DiscordBot bot, DSLContext database) {
HttpServerRequest request = ctx.request();
HttpServerResponse response = ctx.response();
String userId = ServerUtils.authUser(request, response, config);
if (userId == null) {
return;
}
String guildId = request.getParam("guildId");
String channelId = request.getParam("channelId");
String fromParam = request.getParam("from");
String toParam = request.getParam("to");
long from;
long to;
try {
from = Long.parseLong(fromParam);
to = Long.parseLong(toParam);
if (from <= 0 || to <= 0 || from >= to) {
response.setStatusCode(400);
response.end();
return;
}
} catch (NumberFormatException e) {
response.setStatusCode(400);
response.end();
return;
}
Guild guild = DiscordUtils.getGuildFromBot(bot, guildId);
if (guild == null) {
response.setStatusCode(404);
response.end();
return;
}
TextChannel channel = guild.getTextChannelById(channelId);
if (channel == null) {
response.setStatusCode(403);
response.end();
return;
}
Member member = guild.getMemberById(userId);
if (member == null) {
response.setStatusCode(403);
response.end();
return;
}
if (!member.hasPermission(channel, Permission.MESSAGE_READ)) {
response.setStatusCode(403);
response.end();
return;
}
SettingsRecord settings = DatabaseUtils.getGuildSettings(database, guild);
if (!settings.getStatistics()) {
response.setStatusCode(404);
response.end();
return;
}
Gson gson = new Gson();
List<Stat> stats = Stat.getChannelMessageStats(database, guildId, channelId, from, to, 60);
response.putHeader("Content-Type", "application/json");
response.end(gson.toJson(stats, stats.getClass()));
}
示例14: handle
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext ctx, Server server, DiscordBot bot, DSLContext database) {
HttpServerRequest request = ctx.request();
HttpServerResponse response = ctx.response();
String guildId = request.getParam("guildId");
int shardId = DiscordUtils.getShardIdFromGuildId(Long.parseLong(guildId), bot.getConfig().jim.shard_count);
JDA shard = bot.getShards().get(shardId).getShard();
Guild guild = shard.getGuildById(guildId);
SettingsRecord record = database.selectFrom(Tables.SETTINGS)
.where(Tables.SETTINGS.GUILDID.eq(guildId))
.fetchAny();
if (record == null || guild == null) {
response.setStatusCode(404);
response.end();
return;
}
Gson gson = new GsonBuilder().serializeNulls().create();
List<PartialChannel> channels = guild.getTextChannels()
.stream()
.map((channel) -> new PartialChannel(channel.getId(), channel.getName()))
.collect(Collectors.toList());
List<PartialRole> roles = guild.getRoles()
.stream()
.map((role) -> new PartialRole(role.getId(), role.getName()))
.collect(Collectors.toList());
Channel modLogChannel = shard.getTextChannelById(record.getModlogchannelid());
PartialChannel modLogChannelPartial = new PartialChannel(modLogChannel.getId(), modLogChannel.getName());
Channel welcomeMessageChannel = shard.getTextChannelById(record.getWelcomemessagechannelid());
PartialChannel welcomeMessageChannelPartial = new PartialChannel(welcomeMessageChannel.getId(), welcomeMessageChannel.getName());
Role holdingRoomRole = null;
PartialRole holdingRoomRolePartial = null;
if (record.getHoldingroomroleid() != null) {
holdingRoomRole = shard.getRoleById(record.getHoldingroomroleid());
holdingRoomRolePartial = new PartialRole(holdingRoomRole.getId(), holdingRoomRole.getName());
}
GuildSettings settings = new GuildSettings(
guildId,
record.getModlog(),
modLogChannelPartial,
record.getHoldingroom(),
holdingRoomRolePartial,
record.getHoldingroomminutes(),
record.getInvitelinkremover(),
record.getWelcomemessage(),
record.getMessage(),
welcomeMessageChannelPartial,
record.getPrefix(),
record.getSilentcommands(),
record.getNospaceprefix(),
record.getStatistics(),
channels,
roles
);
String responseJson = gson.toJson(settings);
response.putHeader("Content-Type", "application/json");
response.end(responseJson);
}
示例15: updateEmailPassword
import io.vertx.ext.web.RoutingContext; //导入方法依赖的package包/类
/**
* 更新邮箱密码
* 请求方法:PUT
* 请求参数:id,oldPassword旧密码,newPassword新密码,rePasswordo重复密码
* 响应:success或fail
*/
private void updateEmailPassword(RoutingContext rc) {
if (forbidAccess(rc, "id", true)) {
return;
}
HttpServerRequest req = rc.request();
HttpServerResponse resp = rc.response().putHeader("content-type", "text/plain; charset=utf-8");
Long id = Long.valueOf(req.getParam("id"));
String oldPassword = req.getParam("oldPassword");
log.debug("即将发送EventBus消息查询(ID={},密码={})是否正确", id, oldPassword);
Future.<Message<JsonObject>>future(f ->
vertx.eventBus().send(ADDR_ACCOUNT_DB.get(), makeMessage(COMMAND_ID_LOGIN, id, oldPassword), f)
).compose(msg ->
Future.<Message<Integer>>future(f -> {
JsonObject acc = msg.body();
if (acc == null) {
log.warn("账户({})不存在或密码({})错误", id, oldPassword);
rc.response().end("errPswd");
return;
}
String email = req.getParam("email");
String newPassword = req.getParam("newPassword");
boolean needUpdatePassword = false;
if (newPassword != null && newPassword.trim().length() > 0) {
String rePassword = req.getParam("rePassword");
if (rePassword == null || rePassword.trim().length() == 0) {
log.error("输入的重复密码为空");
resp.setStatusCode(500).end("EMPTY_REPEAT_PSWD");
return;
}
if (!newPassword.trim().equals(rePassword.trim())) {
log.error("输入的新密码({})与重复密码不一致({})", newPassword, rePassword);
resp.setStatusCode(500).end("PSWD_NOT_EQUAL");
return;
}
needUpdatePassword = true;
}
JsonObject updateAcc = new JsonObject().put(ID, id).put(EMAIL, email);
if (needUpdatePassword) {
updateAcc.put(PASSWORD, newPassword);
}
vertx.eventBus().send(ADDR_ACCOUNT_DB.get(), makeMessage(COMMAND_UPDATE_NORMAL, updateAcc), f);
})
).setHandler(res -> {
if(res.succeeded()){
Integer rows = res.result().body();
log.info("更新密码/邮箱完毕,影响了{}条数据库记录", rows);
rc.response().end(rows > 0 ? "success" : "fail");
} else {
log.error("更新密码/邮箱时抛出异常", res.cause());
rc.response().setStatusCode(500).end();
}
});
}