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


Java HttpServerResponse.end方法代码示例

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

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

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

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

示例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();
}
 
开发者ID:redhat-developer,项目名称:che-vertx-server,代码行数:13,代码来源:GetDeploymentConfigHandler.java

示例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();
	}
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:31,代码来源:JaxResponseWriter.java

示例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("下单失败");
    }
}
 
开发者ID:Leibnizhu,项目名称:AlipayWechatPlatform,代码行数:35,代码来源:WechatPaySubRouter.java

示例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();
}
 
开发者ID:redhat-developer,项目名称:che-vertx-server,代码行数:14,代码来源:GetOpenShiftTokenHandler.java

示例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();
		}
	}
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:29,代码来源:GenericResponseWriter.java

示例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();
}
 
开发者ID:redhat-developer,项目名称:che-vertx-server,代码行数:8,代码来源:GetWorkspaceHandler.java

示例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();
}
 
开发者ID:redhat-developer,项目名称:che-vertx-server,代码行数:8,代码来源:GetWorkspaceByIdHandler.java

示例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) {

    }
}
 
开发者ID:Samoxive,项目名称:SafetyJim,代码行数:15,代码来源:ServerUtils.java

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

示例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() + "'");
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:6,代码来源:IllegalArgumentExceptionHandler.java

示例15: write

import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@Override
public void write(String result, HttpServerRequest request, HttpServerResponse response) {

	response.end("<custom>" + result + "</custom>");
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:6,代码来源:TestCustomWriter.java


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