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


Java RoutingContext.request方法代码示例

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

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

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

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

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

示例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);
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:22,代码来源:VertxHttpRequest.java

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

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

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

示例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));
}
 
开发者ID:Samoxive,项目名称:SafetyJim,代码行数:36,代码来源:Guilds.java

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

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

}
 
开发者ID:troopson,项目名称:etagate,代码行数:28,代码来源:RequestHandler.java

示例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()));
}
 
开发者ID:Samoxive,项目名称:SafetyJim,代码行数:73,代码来源:ChannelMessageStats.java

示例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);
}
 
开发者ID:Samoxive,项目名称:SafetyJim,代码行数:64,代码来源:GetGuildSettings.java

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


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