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


Java HttpServerResponse.putHeader方法代码示例

本文整理汇总了Java中io.vertx.core.http.HttpServerResponse.putHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerResponse.putHeader方法的具体用法?Java HttpServerResponse.putHeader怎么用?Java HttpServerResponse.putHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.core.http.HttpServerResponse的用法示例。


在下文中一共展示了HttpServerResponse.putHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: redirect

import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
public static HttpServerResponse redirect(HttpServerRequest request,HttpServerResponse response,String page){
		String uri = request.uri();
		String mainpage= null;
//		System.out.println("--->"+uri);
		if(!"/".equals(uri))
		    mainpage=request.absoluteURI().replace(request.uri(), "")+page;
		else{
			if(page.startsWith("/"))
				page = page.substring(1);
			mainpage=request.absoluteURI()+page;
		}
		response.putHeader("Content-Type", "text/html;charset=utf-8");
		response.putHeader("Location", mainpage);
		response.setStatusCode(HttpStatus.See_OTher);
		return response;
	}
 
开发者ID:troopson,项目名称:etagate,代码行数:17,代码来源:RequestHelper.java

示例2: wapPay

import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
/**
 * 该方法实现了支付宝手机网页的支付功能;
 * 方法将调用支付宝支付页面需要用到的数据拼接和设置好,然后,写到响应中,前台会自动弹出支付宝支付页面;
 * 其中,支付金额要求大于0.01,并且小于100000000,需要调用者自己检查该值再传进来,否则页面会报获取不到订单信息错误;
 *
 * @param aliAccountInfo 保存了支付宝账户的信息,包括appId、用户私钥、支付宝公钥和回调地址等,具体参考AliAccountInfo类的属性说明
 * @param payBizContent 保存了订单信息,包括本地订单号、金额等,具体参考BizContent类的属性说明
 * Create by quandong
 */
public static void wapPay(AliAccountInfo aliAccountInfo, PayBizContent payBizContent, HttpServerResponse httpResponse) throws IOException {
    AlipayClient alipayClient = AliPayCliFactory.getAlipayClient(aliAccountInfo); // 从客户端工厂中获取AlipayClient
    AlipayTradeWapPayRequest alipayRequest = new AlipayTradeWapPayRequest(); // 创建API对应的request
    String form = "";

    alipayRequest.setReturnUrl(aliAccountInfo.getReturnUrl()); // 设置回跳地址
    alipayRequest.setNotifyUrl(aliAccountInfo.getNotifyUrl()); // 设置通知地址
    alipayRequest.setBizContent(payBizContent.toString()); // 填充业务参数

    try {
        form = alipayClient.pageExecute(alipayRequest).getBody(); // 调用SDK生成表单
    } catch (AlipayApiException e) {
        e.printStackTrace();
    }

    httpResponse.putHeader("Content-Type", "text/html;charset=" + AlipayConstants.CHARSET_UTF8); // 设置文本类型及编码
    httpResponse.end(form); // 直接将完整的表单html输出到页面
}
 
开发者ID:Leibnizhu,项目名称:AlipayWechatPlatform,代码行数:28,代码来源:AliPayApi.java

示例3: addResponseHeaders

import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
default void addResponseHeaders(RouteDefinition definition, HttpServerResponse response) {

		if (!response.ended() &&
			!response.headers().contains(HttpHeaders.CONTENT_TYPE)) {

			if (definition != null &&
			    definition.getProduces() != null) {
				for (MediaType produces : definition.getProduces()) {
					response.putHeader(HttpHeaders.CONTENT_TYPE, MediaTypeHelper.toString(produces));
				}
			}
			else {
				response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.WILDCARD);
			}
		}
	}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:17,代码来源:HttpResponseWriter.java

示例4: reply

import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
public static void reply(
        final RoutingContext context,
        final Envelop envelop) {
    // 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());
    response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    // 3. Response process
    if (!response.ended()) {
        response.end(envelop.response());
    }
    response.close();
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:18,代码来源:Answer.java

示例5: 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

示例6: handle

import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
void handle(HttpServerRequest req) {
    HttpServerResponse resp = req.response();
    resp.putHeader("strict-transport-security", "max-age=31536000; includeSubDomains");
    resp.putHeader("x-frame-options", "DENY");
    resp.putHeader("content-type", "text/plain; charset=utf-8");
    resp.setStatusCode(200).end("Hello wørld!");
}
 
开发者ID:xkr47,项目名称:vertx-acme4j,代码行数:8,代码来源:TestApp.java

示例7: addHeaders

import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
private static void addHeaders(Response jaxrsResponse, HttpServerResponse response) {

		if (jaxrsResponse.getMetadata() != null) {

			List<Object> cookies = jaxrsResponse.getMetadata().get(HttpHeaders.SET_COOKIE.toString());
			if (cookies != null) {

				Iterator<Object> it = cookies.iterator();
				while (it.hasNext()) {
					Object next = it.next();
					if (next instanceof NewCookie) {

						NewCookie cookie = (NewCookie) next;
						response.putHeader(HttpHeaders.SET_COOKIE, cookie.toString());

						it.remove();
					}
				}

				if (cookies.size() < 1) {
					jaxrsResponse.getMetadata().remove(HttpHeaders.SET_COOKIE.toString());
				}
			}
		}

		if (jaxrsResponse.getMetadata() != null && jaxrsResponse.getMetadata().size() > 0) {

			for (String name : jaxrsResponse.getMetadata().keySet()) {
				List<Object> meta = jaxrsResponse.getMetadata().get(name);

				if (meta != null && meta.size() > 0) {
					for (Object item : meta) {
						if (item != null) {
							response.putHeader(name, item.toString());
						}
					}
				}
			}
		}
	}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:41,代码来源:JaxResponseWriter.java

示例8: login

import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@GET
@Path("/login")
public HttpServerResponse login(@Context HttpServerResponse response) {

	response.setStatusCode(201);
	response.putHeader("X-SessionId", "session");
	response.end("Hello world!");
	return response;
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:10,代码来源:TestContextRest.java

示例9: stripTransferEncodingAndLength

import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
private void stripTransferEncodingAndLength(final HttpServerResponse contextResponse,
    final Map.Entry<String, String> h) {

    if ("Content-Length".equalsIgnoreCase(h.getKey()) || "Transfer-Encoding".equalsIgnoreCase(h.getKey())) {
        return;
    }
    contextResponse.putHeader(h.getKey(), h.getValue());
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:9,代码来源:UnauthenticatedClientValidator.java

示例10: 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

示例11: 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

示例12: jsonContentType

import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
public static HttpServerResponse jsonContentType(HttpServerResponse response) {
  return response.putHeader("content-type", CONTENT_TYPE_APPLICATION_JSON);
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:4,代码来源:WebServerUtils.java

示例13: 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 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

示例14: 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;
    }

    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

示例15: 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;
    }

    String guildId = request.getParam("guildId");
    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;
    }

    Member member = guild.getMemberById(userId);
    if (member == null) {
        response.setStatusCode(403);
        response.end();
        return;
    }

    SettingsRecord settings = DatabaseUtils.getGuildSettings(database, guild);
    if (!settings.getStatistics()) {
        response.setStatusCode(404);
        response.end();
        return;
    }

    Map<String, List<Stat>> stats = guild.getTextChannels()
            .stream()
            .filter((channel) -> member.hasPermission(channel, Permission.MESSAGE_READ))
            .collect(Collectors.toMap((channel) -> channel.getId(), (channel) -> Stat.getChannelMessageStats(database, guildId, channel.getId(), from, to, 60)));

    if (stats.isEmpty()) {
        response.setStatusCode(403);
        response.end();
        return;
    }

    Gson gson  = new Gson();
    response.putHeader("Content-Type", "application/json");
    response.end(gson.toJson(stats, stats.getClass()));
}
 
开发者ID:Samoxive,项目名称:SafetyJim,代码行数:69,代码来源:ChannelsMessageStats.java


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