本文整理汇总了Java中io.vertx.rxjava.core.http.HttpServerResponse类的典型用法代码示例。如果您正苦于以下问题:Java HttpServerResponse类的具体用法?Java HttpServerResponse怎么用?Java HttpServerResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpServerResponse类属于io.vertx.rxjava.core.http包,在下文中一共展示了HttpServerResponse类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getShoppingList
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
private void getShoppingList(RoutingContext rc) {
Single<HttpResponse<Buffer>> list = shopping.get("/shopping").rxSend();
HttpServerResponse serverResponse = rc.response()
.setChunked(true);
list.subscribe(
response -> {
JsonObject body = response.bodyAsJsonObject();
Observable.from(body)
.flatMap(entry ->
retrievePrice(pricer, entry).toObservable())
.subscribe(
product -> writeProductLine(serverResponse, product),
rc::fail,
serverResponse::end
);
},
rc::fail);
}
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:21,代码来源:MyShoppingList.java
示例2: getShoppingListWithCB
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
private void getShoppingListWithCB(RoutingContext rc) {
Single<HttpResponse<Buffer>> list = shopping.get("/shopping").rxSend();
HttpServerResponse serverResponse = rc.response()
.setChunked(true);
list.subscribe(
response -> {
JsonObject body = response.bodyAsJsonObject();
Observable.from(body)
.flatMap(entry ->
circuit.executeWithFallback(
future -> retrievePrice(pricer, entry, future),
t -> getFallbackPrice(entry)
)
.rxSetHandler().toObservable())
.subscribe(
product -> writeProductLine(serverResponse, product),
rc::fail,
serverResponse::end
);
},
rc::fail);
}
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:25,代码来源:MyShoppingList.java
示例3: getOne
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
private void getOne(RoutingContext ctx) {
HttpServerResponse response = ctx.response()
.putHeader("Content-Type", "application/json");
store.get(ctx.get("fruitId"))
.subscribe(
json -> response.end(json.encodePrettily()),
err -> {
if (err instanceof NoSuchElementException) {
error(ctx, 404, err);
} else if (err instanceof IllegalArgumentException) {
error(ctx, 415, err);
} else {
error(ctx, 500, err);
}
}
);
}
开发者ID:cescoffier,项目名称:various-vertx-demos,代码行数:19,代码来源:CrudApplication.java
示例4: handleSingleResponseBody
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
default <R> void handleSingleResponseBody(RoutingContext ctx, Class<R> clazz, R ret) {
HttpServerResponse resp = ctx.response();
if (ret != null) {
if (ret instanceof String) {
resp.end((String) ret);
} else if (ret instanceof Buffer) {
resp.end((Buffer) ret);
} else if (ret instanceof JsonObject) {
resp.end(((JsonObject) ret).encode());
} else if (ret instanceof JsonArray) {
resp.end(((JsonArray) ret).encode());
} else {
resp.end(objectToString(ret));
}
}
}
开发者ID:egopulse,项目名称:java-code-gen,代码行数:17,代码来源:RouteRegistrarHelper.java
示例5: handleResponseBody
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
@SuppressWarnings("unchecked")
default <R> void handleResponseBody(RoutingContext ctx, Class<R> retType, R ret) {
HttpServerResponse resp = ctx.response();
if (ret != null) {
resp.putHeader("content-type", ctx.getAcceptableContentType());
Single single = null;
if (ret instanceof Observable) {
single = ((Observable) ret).toList().toSingle();
} else if (ret instanceof Single) {
single = (Single) ret;
} else if (ret instanceof Completable) {
single = ((Completable) ret).toSingleDefault("");
}
if (single != null) {
single.subscribe(
r -> handleSingleResponseBody(ctx, (Class) r.getClass(), r),
e -> handleError(ctx, (Throwable) e));
} else {
handleSingleResponseBody(ctx, retType, ret);
}
} else {
resp.end();
}
}
开发者ID:egopulse,项目名称:java-code-gen,代码行数:26,代码来源:RouteRegistrarHelper.java
示例6: RouteRegistrarCodeGenerator
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
public RouteRegistrarCodeGenerator(Models models) {
this.models = models;
Elements elementsUtil = models.getElemsUtil();
stringType = elementsUtil.getTypeElement(String.class.getCanonicalName()).asType();
routingCtxType = elementsUtil.getTypeElement(RoutingContext.class.getCanonicalName()).asType();
routingCtxTypeCore = elementsUtil.getTypeElement(io.vertx.ext.web.RoutingContext.class.getCanonicalName()).asType();
reqType = elementsUtil.getTypeElement(HttpServerRequest.class.getCanonicalName()).asType();
reqTypeCore = elementsUtil.getTypeElement(io.vertx.core.http.HttpServerRequest.class.getCanonicalName()).asType();
respType = elementsUtil.getTypeElement(HttpServerResponse.class.getCanonicalName()).asType();
respTypeCore = elementsUtil.getTypeElement(io.vertx.core.http.HttpServerResponse.class.getCanonicalName()).asType();
routeType = elementsUtil.getTypeElement(Route.class.getCanonicalName()).asType();
routeTypeCore = elementsUtil.getTypeElement(io.vertx.ext.web.Route.class.getCanonicalName()).asType();
routerType = elementsUtil.getTypeElement(Router.class.getCanonicalName()).asType();
routerTypeCore = elementsUtil.getTypeElement(io.vertx.ext.web.Router.class.getCanonicalName()).asType();
sessionType = elementsUtil.getTypeElement(Session.class.getCanonicalName()).asType();
sessionTypeCore = elementsUtil.getTypeElement(io.vertx.ext.web.Session.class.getCanonicalName()).asType();
}
开发者ID:egopulse,项目名称:java-code-gen,代码行数:18,代码来源:RouteRegistrarCodeGenerator.java
示例7: retrieveAll
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
private void retrieveAll(RoutingContext ctx) {
HttpServerResponse response = ctx.response()
.putHeader("Content-Type", "application/json");
JsonArray res = new JsonArray();
store.getAll()
.subscribe(
res::add,
err -> error(ctx, 415, err),
() -> response.end(res.encodePrettily())
);
}
开发者ID:cescoffier,项目名称:various-vertx-demos,代码行数:12,代码来源:CrudApplication.java
示例8: respondNotFound
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
private void respondNotFound(HttpServerResponse response, String username) {
response.setStatusCode(HTTP_NOT_FOUND);
response.headers()
.set(CONTENT_ENCODING, UTF_8.name())
.set(CONTENT_TYPE, PLAIN_TEXT_UTF_8.toString());
response.end(String.format("User with username of '%s' was not found", username));
}
开发者ID:MiguelGL,项目名称:popular-purchases-demo,代码行数:8,代码来源:RecentPurchasesHandler.java
示例9: respondInternalError
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
private void respondInternalError(HttpServerResponse response, Throwable th) {
response.setStatusCode(HTTP_NOT_FOUND);
response.headers()
.set(CONTENT_ENCODING, UTF_8.name())
.set(CONTENT_TYPE, PLAIN_TEXT_UTF_8.toString());
response.end(String.valueOf(th));
}
开发者ID:MiguelGL,项目名称:popular-purchases-demo,代码行数:8,代码来源:RecentPurchasesHandler.java
示例10: start
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
@Override
public void start() throws Exception {
Router router = Router.router(vertx);
router.get("/hello").handler(routingContext -> {
HttpServerRequest request = routingContext.request();
HttpServerResponse response = routingContext.response();
Long minSleep = (request.getParam("minSleepMs") != null) ? Long.parseLong(request.getParam("minSleepMs")) : 500L;
Long maxSleep = (request.getParam("maxSleepMs") != null) ? Long.parseLong(request.getParam("maxSleepMs")) : 500L;
HelloGenerator helloTask = new HelloGenerator(minSleep, maxSleep);
Observable.<String>create(sub -> {
String message = null;
try {
message = helloTask.call();
} catch (Exception e) {
sub.onError(e);
}
sub.onNext(message);
sub.onCompleted();
})
.last()
.subscribeOn(Schedulers.io())
.subscribe(message -> routingContext.response().setStatusCode(200).end(message),
error -> routingContext.response().setStatusCode(500).end());
});
vertx.createHttpServer().requestHandler(router::accept).listen(8080);
}
开发者ID:gregwhitaker,项目名称:async-showdown,代码行数:32,代码来源:Application.java
示例11: writeProductLine
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
public static void writeProductLine(HttpServerResponse response, JsonObject product) {
// All entries are string
response.write(" * " + product.getString("name") + " x "
+ product.getString("quantity")
+ " = " + product.getString("total") + "\n");
}
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:7,代码来源:Shopping.java
示例12: getShoppingList
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
private void getShoppingList(RoutingContext rc) {
HttpServerResponse serverResponse =
rc.response().setChunked(true);
/*
+--> Retrieve shopping list
+
+--> for each item, call the pricer, concurrently
+
|
+--> For each completed evaluation (line),
write it to the HTTP response
*/
Single<JsonObject> list = shopping
.get("/shopping")
.rxSend()
.map(HttpResponse::bodyAsJsonObject);
list.subscribe(
json -> {
Observable.from(json)
.flatMapSingle(entry ->
circuit.rxExecuteCommandWithFallback(
future -> Shopping.retrievePrice(pricer, entry, future),
err -> Shopping.getFallbackPrice(entry)
)
)
.subscribe(
res -> {
System.out.println(res.encode());
Shopping
.writeProductLine
(serverResponse, res);
},
t -> {
t.printStackTrace();
rc.fail(t);
},
serverResponse::end
);
}
);
/*
shopping pricer
backend
+ + +
| | |
+--------------> | |
| | |
| | |
+-------------------------------> |
| | |
+-------------------------------> |
write <--| | |
+-------------------------------> |
write <--| + +
|
write <--|
|
end <--|
*/
}
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:65,代码来源:MyShoppingList.java
示例13: writeProductLine
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
public static void writeProductLine(HttpServerResponse response, JsonObject product) {
// All entries are string
response.write(" * " + product.getString("name")
+ " x " + product.getString("quantity")
+ " = " + product.getString("total") + "\n");
}
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:7,代码来源:Shopping.java
示例14: getShoppingList
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
private void getShoppingList(RoutingContext rc) {
HttpServerResponse serverResponse =
rc.response().setChunked(true);
/*
+--> Retrieve shopping list
+
+--> for each item, call the pricer, concurrently
+
|
+--> For each completed evaluation (line),
write it to the HTTP response
*/
Single<JsonObject> single = shopping.get("/shopping")
.rxSend()
.map(HttpResponse::bodyAsJsonObject);
/*
shopping pricer
backend
+ + +
| | |
+--------------> | |
| | |
| | |
+-------------------------------> |
| | |
+-------------------------------> |
write <--| | |
+-------------------------------> |
write <--| + +
|
write <--|
|
end <--|
*/
single.subscribe(list -> {
Observable.from(list)
.flatMapSingle(entry ->
circuit.rxExecuteCommandWithFallback(
future -> {
Shopping.retrievePrice(pricer, entry, future);
},
err -> Shopping.getFallbackPrice(entry)
))
.subscribe(
json -> {
Shopping.writeProductLine(serverResponse, json);
},
rc::fail,
serverResponse::end
);
}
);
}
开发者ID:cescoffier,项目名称:vertx-rhsummit-2017,代码行数:58,代码来源:MyShoppingList.java
示例15: handle
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
@Override
public void handle(HttpServerRequest request)
{
request.bodyHandler(buff -> {
Context ctx = vertx.getOrCreateContext();
ResteasyUriInfo uriInfo = VertxUtil.extractUriInfo(request.getDelegate(), servletMappingPrefix);
ResteasyHttpHeaders headers = VertxUtil.extractHttpHeaders(request.getDelegate());
HttpServerResponse response = request.response();
VertxHttpResponse vertxResponse = new VertxHttpResponse(response.getDelegate(), dispatcher.getProviderFactory(), request.method());
VertxHttpRequest vertxRequest = new VertxHttpRequest(ctx.getDelegate(), headers, uriInfo, request.rawMethod(), dispatcher.getDispatcher(), vertxResponse, false);
if (buff.length() > 0)
{
ByteBufInputStream in = new ByteBufInputStream(buff.getDelegate().getByteBuf());
vertxRequest.setInputStream(in);
}
try
{
AppGlobals.set(appGlobals);
appGlobals.injectGlobals();
dispatcher.service(ctx.getDelegate(), request.getDelegate(), response.getDelegate(), vertxRequest, vertxResponse, true);
} catch (Failure e1)
{
vertxResponse.setStatus(e1.getErrorCode());
} catch (Exception ex)
{
vertxResponse.setStatus(500);
LogMessages.LOGGER.error(Messages.MESSAGES.unexpected(), ex);
}
finally
{
AppGlobals.set(null);
}
if (!vertxRequest.getAsyncContext().isSuspended())
{
try
{
vertxResponse.finish();
} catch (IOException e)
{
e.printStackTrace();
}
}
});
}
开发者ID:FroMage,项目名称:redpipe,代码行数:46,代码来源:VertxPluginRequestHandler.java
示例16: respondRecentPurchases
import io.vertx.rxjava.core.http.HttpServerResponse; //导入依赖的package包/类
private void respondRecentPurchases(HttpServerResponse response, String username) {
Observable<List<ObjectNode>> observedRecentPurchasesList =
observeGetUserPurchases(username)
.flatMap(userPurchases -> {
List<Long> productIds = asStream(userPurchases.elements())
.map(ObjectNode.class::cast)
.map(jsonPurchase -> jsonPurchase.get("productId").asLong())
.distinct()
.sorted()
.collect(Collectors.toList());
Observable<ObjectNode> observedProductDetails = Observable.from(productIds)
.flatMap(this::observeGetProductDetails);
Observable<ArrayNode> observedProductPurchases = Observable.from(productIds)
.flatMap(this::observeGetProductPurchases);
Observable<List<ObjectNode>> observedRecentPurchases = observedProductDetails
.zipWith(
observedProductPurchases,
(productDetails, productPurchases) -> {
ObjectNode recentPurchase = Json.mapper.createObjectNode()
.put("id", productDetails.get("id").asText())
.put("face", productDetails.get("face").asText())
.put("price", productDetails.get("price").asLong())
.put("size", productDetails.get("size").asLong())
.put("recent", productDetails.get("size").asLong());
ArrayNode recents = recentPurchase.putArray("recent");
asStream(productPurchases.elements())
.map(purchase -> purchase.get("username").textValue())
.distinct()
.forEach(user -> recents.add(user));
return recentPurchase;
})
.toSortedList((recentPurchase1, recentPurchase2) -> {
ArrayNode recent1 = (ArrayNode) recentPurchase1.get("recent");
ArrayNode recent2 = (ArrayNode) recentPurchase2.get("recent");
return Integer.compare(recent1.size(), recent2.size()) * -1; // desc
});
return observedRecentPurchases;
});
observedRecentPurchasesList.subscribe(recentPurchasesList -> {
ArrayNode jsonResponse = Json.mapper.createArrayNode();
recentPurchasesList.forEach(jsonResponse::add);
response.setStatusCode(HTTP_OK);
response.headers()
.set(CONTENT_ENCODING, UTF_8.name())
.set(CONTENT_TYPE, JSON_UTF_8.toString());
response.end(Json.encode(jsonResponse));
}, th -> {
respondInternalError(response, th);
});
}
开发者ID:MiguelGL,项目名称:popular-purchases-demo,代码行数:61,代码来源:RecentPurchasesHandler.java
注:本文中的io.vertx.rxjava.core.http.HttpServerResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论