本文整理汇总了Java中io.vertx.core.http.HttpServerResponse.setStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerResponse.setStatusCode方法的具体用法?Java HttpServerResponse.setStatusCode怎么用?Java HttpServerResponse.setStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.http.HttpServerResponse
的用法示例。
在下文中一共展示了HttpServerResponse.setStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
public void handle(RoutingContext ctx) {
HttpServerResponse response = ctx.response();
if (userManager.isLogined(ctx)) {
try {
String uid = userManager.getUid(userManager.getIdFromSession(ctx));
JobResult result = requestManager.getApiKeys(uid);
if (result.isSuccess()) {
SafeResultSet rs = (SafeResultSet) result.getArgs()[0];
while (rs.next()) {
//
//
//
}
}
} catch (SQLException e) {
e.printStackTrace();
response.setStatusCode(500);
}
} else {
response.setStatusCode(400);
}
response.end();
response.close();
}
示例2: proxyUserRequest
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
/**
* Proxies the specified HTTP request, enriching its headers with authentication information.
*
* @param userId the ID of the user making the request.
* @param origReq the original request (i.e., {@link RoutingContext#request()}.
* @param origRes the original response (i.e., {@link RoutingContext#request()}.
*/
public void proxyUserRequest(final String userId,
final HttpServerRequest origReq,
final HttpServerResponse origRes) {
final Handler<HttpClientResponse> proxiedResHandler = proxiedRes -> {
origRes.setChunked(true);
origRes.setStatusCode(proxiedRes.statusCode());
origRes.headers().setAll(proxiedRes.headers());
proxiedRes.handler(origRes::write);
proxiedRes.endHandler(v -> origRes.end());
};
final HttpClientRequest proxiedReq;
proxiedReq = httpClient.request(origReq.method(), port, host, origReq.uri(), proxiedResHandler);
proxiedReq.setChunked(true);
proxiedReq.headers().add(X_FORWARDED_PROTO, getHeader(origReq, X_FORWARDED_PROTO, origReq.scheme()));
proxiedReq.headers().add(X_FORWARDED_FOR, getHeader(origReq, X_FORWARDED_FOR, origReq.remoteAddress().host()));
proxiedReq.headers().addAll(origReq.headers());
injectRutHeader(proxiedReq, userId);
origReq.handler(proxiedReq::write);
origReq.endHandler(v -> proxiedReq.end());
}
示例3: 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();
}
示例4: handle
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
public void handle(RoutingContext ctx)
{
HttpServerResponse response = ctx.response();
if(userManager.isLogined(ctx)){
try {
String uid = userManager.getUid(userManager.getIdFromSession(ctx));
String result = requestManager.createApiKey(uid);
if(result != null){
response.setStatusCode(200);
response.setStatusMessage(result);
}
} catch (SQLException e) {
e.printStackTrace();
response.setStatusCode(500);
}
}else{
response.setStatusCode(400);
}
response.end();
response.close();
}
示例5: onFailure
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
protected void onFailure(RoutingContext context) {
LOGGER.error("edge server failed.", context.failure());
HttpServerResponse response = context.response();
response.setStatusCode(Status.BAD_GATEWAY.getStatusCode());
response.setStatusMessage(Status.BAD_GATEWAY.getReasonPhrase());
response.end();
}
示例6: 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_GITHUB_TOKEN +
"\",\"scope\":\"admin:repo_hook,gist,read:org,repo,user\",\"token_type\":\"bearer\"}");
} else {
response.write("{\"errorMessage\":\"Invalid token.\"}");
response.setStatusCode(400);
}
response.end();
}
示例7: 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").contains(Properties.DEFAULT_GITHUB_TOKEN)) {
response.write("{ \"name\":\"Marian Labuda\", \"email\":\"[email protected]\"}");
} else {
response.write("{\"errorMessage\":\"Invalid token.\"}");
response.setStatusCode(400);
}
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);
String authHeader = routingContext.request().getHeader("Authorization");
if (authHeader == null || !authHeader.contains(Properties.DEFAULT_AUTH_TOKEN)) {
response.setStatusCode(401);
} else {
response.write(new Response().getResponse(Constants.GET_ROUTE_RESPONSE_TEMPLATE));
}
response.end();
}
示例9: handle
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
public void handle(HttpServerRequest clientRequest, HttpServerResponse clientResponse,
HttpResponse<Buffer> appResponse) {
int statusCode = appResponse.statusCode();
clientResponse.setStatusCode(statusCode);
// clientResponse.setStatusMessage(appResponse.statusMessage());
// System.out.println(appResponse.statusMessage());
MultiMap appHeaders = appResponse.headers();
appHeaders.forEach(entry -> {
String k = entry.getKey();
String v = entry.getValue();
// System.out.println("Header Response:[" + k + "]=" + v);
if ("Location".equalsIgnoreCase(k) && S.isNotBlank(v)) {
String schemal = clientRequest.scheme();
String host = clientRequest.host();
clientResponse.putHeader("Location", v.replaceAll(HTTP_SCHEMAL_HOST_REG, schemal + "://" + host + "/"));
} else
clientResponse.putHeader(k, v);
});
clientResponse.setChunked(true);
Buffer buff = appResponse.bodyAsBuffer();
if (buff != null && buff.length() > 0)
clientResponse.write(buff);
}
示例10: write
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@Override
public void write(String path, HttpServerRequest request, HttpServerResponse response) {
if (fileExists(context, path)) {
response.sendFile(path);
}
else {
response.setStatusCode(Response.Status.NOT_FOUND.getStatusCode());
}
}
示例11: getRoute
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
@GET
@Path("/context")
public String getRoute(@Context HttpServerResponse response, @Context HttpServerRequest request) {
response.setStatusCode(201);
return request.uri();
}
示例12: 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));
}
示例13: redirectToLandingPage
import io.vertx.core.http.HttpServerResponse; //导入方法依赖的package包/类
private void redirectToLandingPage(RoutingContext context) {
HttpServerResponse response = context.response();
response.setStatusCode(303);
response.headers().add("Location", WebServerUtils.withApplicationName("about.hbs"));
response.end();
}
示例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 code = request.getParam("code");
if (code == null) {
response.setStatusCode(400);
response.end();
return;
}
DiscordSecrets secrets = DiscordApiUtils.getUserSecrets(config, code);
if (secrets == null || !secrets.scope.equals("guilds identify")) {
response.setStatusCode(400);
response.end();
return;
}
SelfUser self = DiscordApiUtils.getSelf(secrets.accessToken);
if (self == null) {
response.setStatusCode(400);
response.end();
return;
}
Long now = (new Date().getTime()) / 1000;
OauthsecretsRecord record = database.newRecord(Tables.OAUTHSECRETS);
record.setUserid(self.id);
record.setAccesstoken(secrets.accessToken);
record.setRefreshtoken(secrets.refreshToken);
record.setExpirationdate(now + secrets.expiresIn);
database.insertInto(Tables.OAUTHSECRETS)
.set(record)
.onDuplicateKeyUpdate()
.set(record)
.execute();
String token = getJwtToken(self.id);
response.putHeader("Content-Type", "application/json");
response.end("\"" + token + "\"");
}
示例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()));
}