本文整理汇总了Java中io.vertx.core.http.HttpServerResponse.end方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerResponse.end方法的具体用法?Java HttpServerResponse.end怎么用?Java HttpServerResponse.end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.http.HttpServerResponse
的用法示例。
在下文中一共展示了HttpServerResponse.end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的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;
}
User user = DiscordApiUtils.getUser(userId, config.jim.token);
if (user == null) {
response.setStatusCode(404);
response.end();
return;
}
Gson gson = new Gson();
response.putHeader("Content-Type", "application/json");
response.end(gson.toJson(user));
}
示例2: reply
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
public static void reply(
final RoutingContext context,
final Envelop envelop,
final Event event
) {
// 1. Get response reference
final HttpServerResponse response
= context.response();
// 2. Set response status
final HttpStatusCode code = envelop.status();
response.setStatusCode(code.code());
response.setStatusMessage(code.message());
// 3. Media processing
Normalizer.out(response, envelop, event);
// 4. Store Session
storeSession(context, envelop.data(), event.getAction());
// 5. Response process
if (!response.ended()) {
response.end(envelop.response());
}
response.close();
}
示例3: write
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@Override
public void write(Throwable exception, HttpServerRequest request, HttpServerResponse response) {
String message = exception.getMessage();
if (StringUtils.isNullOrEmptyTrimmed(message)) {
response.end(exception.toString());
}
else {
response.end(message);
}
}
示例4: handle
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的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));
}
示例5: handle
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext routingContext) {
HttpServerResponse response = routingContext.response();
response.putHeader("Content-Type", "application/json").setChunked(true);
String authHeader = routingContext.request().getHeader("Authorization");
if (authHeader == null || !authHeader.equals(Properties.DEFAULT_AUTH_TOKEN)) {
response.setStatusCode(401);
} else {
response.write(new Response().getResponse(Constants.GET_OPENSHIFT_DEPLOYMENT_CONFIG_RESPONSE_TEMPLATE));
}
response.end();
}
示例6: write
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@Override
public void write(Response result, HttpServerRequest request, HttpServerResponse response) {
Assert.notNull(result, "Expected result but got null!");
response.setStatusCode(result.getStatus());
addHeaders(result, response);
if (result.getEntity() != null) {
// try to find appropriate writer ...
String mediaType = response.headers().get(HttpHeaders.CONTENT_TYPE);
HttpResponseWriter writer;
try {
writer = RestRouter.getWriters().get(mediaType);
}
catch (ClassFactoryException e) {
writer = null;
}
if (writer != null) {
writer.write(result.getEntity(), request, response);
} else {
response.end(result.getEntity().toString());
}
} else {
response.end();
}
}
示例7: wechatNotify
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
/**
* 微信支付回调接口
* 更新订单状态(更新shop_order,已支付,商城订单号,支付类型,支付时间)
*
* 异步返回 成功则返回微信接口规定的信息,失败则返回“下单失败”
*
* @author Leibniz
*/
private void wechatNotify(RoutingContext rc) {
String param = rc.getBody().toString();
log.info("接收到微信支付回调请求,请求数据: " + param);
//将解析后的数据传入map
Map<String, String> payReturnParam = XmlUtils.xmltoMap(param);
//TODO 完善其他返回状态的处理
HttpServerResponse response = rc.response();
if ("SUCCESS".equals(payReturnParam.get("return_code"))) {
String localOrderId = payReturnParam.get("out_trade_no"); //本地订单ID
String wechatOrderId = payReturnParam.get("transaction_id"); //微信订单ID
//调用callback 更新订单数据,已支付,商城订单号,支付类型,支付时间
JsonObject updateOrder = new JsonObject().put(PLATORDERID, wechatOrderId).put(ORDERID, localOrderId).put(TYPE, 0);
vertx.eventBus().<Integer>send(ADDR_ORDER_DB.get(), makeMessage(COMMAND_UPDATE_PAID_ORDER, updateOrder), ebar -> {
if (ebar.succeeded()) {
int rows = ebar.result().body();
log.info("微信支付回调更新数据库,影响行数={}", rows);
} else {
log.error("EventBus消息响应错误", ebar.cause());
response.setStatusCode(500).end("EventBus error!");
}
});
response.putHeader("content-type", "application/xml; charset=utf-8").end(WECHAT_CALLBACK_SUCCESS_RETURN);
} else {
response.end("下单失败");
}
}
示例8: handle
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext routingContext) {
HttpServerResponse response = routingContext.response();
response.putHeader("Content-Type", "application/json").setChunked(true);
if (routingContext.request().getHeader("Authorization").equals(Properties.DEFAULT_KEYCLOAK_TOKEN)) {
response.write("{\"access_token\":\"" + Properties.DEFAULT_OPENSHIFT_TOKEN +
"\",\"expires_in\":86400,\"scope\":\"user:full\",\"token_type\":\"Bearer\"}");
} else {
response.write("{\"errorMessage\":\"Invalid token.\"}");
response.setStatusCode(400);
}
response.end();
}
示例9: write
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@Override
public void write(T result, HttpServerRequest request, HttpServerResponse response) {
String mediaType = response.headers().get(HttpHeaders.CONTENT_TYPE);
HttpResponseWriter writer;
try {
writer = RestRouter.getWriters().get(mediaType);
}
catch (ClassFactoryException e) {
// writer = RestRouter.getWriters().get(result);
writer = null;
}
if (writer != null && !(writer instanceof GenericResponseWriter)) {
writer.write(result, request, response);
}
else {
log.warn("No writer associated with: '" + mediaType + "', defaulting to toString() as output!");
if (result != null) {
response.end(result.toString());
}
else {
response.end();
}
}
}
示例10: handle
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext routingContext) {
HttpServerResponse response = routingContext.response();
response.putHeader("Content-Type", "application/json").setChunked(true);
response.write(new Response().getResponse(Constants.GET_WORKSPACE_RESPONSE_TEMPLATE));
response.end();
}
示例11: handle
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@Override
public void handle(RoutingContext routingContext) {
HttpServerResponse response = routingContext.response();
response.putHeader("Content-Type", "application/json").setChunked(true);
response.write(new Response().getResponse(Constants.GET_WORKSPACE_BY_ID_RESPONSE_TEMPLATE));
response.end();
}
示例12: redirectToDiscord
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
public static void redirectToDiscord(HttpServerResponse response, Config config) {
try {
response.setStatusCode(302);
response.putHeader("Location", "https://discordapp.com/api/oauth2/authorize?" +
"client_id=" + config.oauth.client_id +
"&redirect_uri=" + URLEncoder.encode(config.oauth.redirect_uri, "utf-8") +
"&response_type=code" +
"&scope=guilds%20identify");
response.putHeader("User-Agent", "Safety Jim");
response.end();
} catch (Exception e) {
}
}
示例13: updateWechatPaySetting
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
private void updateWechatPaySetting(RoutingContext rc) {
if (forbidAccess(rc, "uid", true)) {
return;
}
Set<FileUpload> uploads = rc.fileUploads();
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 mchId = req.getParam("mchId");
String payKey = req.getParam("payKey");
//参数检查
if (paySwitch == 1 && !CommonUtils.notEmptyString(mchId, payKey)) {
resp.end(new JsonObject().put("status", "invalid").toString());
return;
}
// 异步保存证书文件
if (uploads != null && !uploads.isEmpty()) {
for (FileUpload next : uploads) {
if (paySwitch == 1 && "cert".equals(next.name()) && next.size() > 0) {
String filePath = Constants.CERT_DIR + uid + "_wxPay.p12";
FileSystem fs = this.vertx.fileSystem();
fs.exists(filePath, ex -> {
if(ex.succeeded()){
Future<Void> delFuture = Future.future();
Future<Void> copyFuture = Future.future();
fs.delete(filePath, delFuture.completer());
fs.copy(next.uploadedFileName(), filePath, copyFuture.completer());
if(ex.result()){
delFuture.compose(res -> {}, copyFuture);
}
copyFuture.setHandler(res -> {
if (res.succeeded()) {
log.info("复制文件{}到{}成功!", next.uploadedFileName(), filePath);
} else {
log.error("复制文件" + next.uploadedFileName() + "到" + filePath + "失败!", res.cause());
}
});
} else {
log.error("判断文件" + filePath + "是否存在时抛出异常!", ex.cause());
}
});
break;
}
}
}
//保存支付参数
JsonObject acc = new JsonObject().put(ID, uid).put(MCHID, mchId).put(MCHKEY, payKey).put(WXPAYON, paySwitch);
updatePaySetting(resp, acc, COMMAND_UPDATE_WECHATPAY);
}
示例14: write
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@Override
public void write(IllegalArgumentException result, HttpServerRequest request, HttpServerResponse response) {
response.end("Huh this produced an error: '" + result.getMessage() + "'");
}
示例15: write
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@Override
public void write(String result, HttpServerRequest request, HttpServerResponse response) {
response.end("<custom>" + result + "</custom>");
}