本文整理汇总了Java中io.vertx.core.eventbus.DeliveryOptions.setHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java DeliveryOptions.setHeaders方法的具体用法?Java DeliveryOptions.setHeaders怎么用?Java DeliveryOptions.setHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.eventbus.DeliveryOptions
的用法示例。
在下文中一共展示了DeliveryOptions.setHeaders方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: manageError
import io.vertx.core.eventbus.DeliveryOptions; //导入方法依赖的package包/类
public void manageError(Message<JsonObject> message, Throwable cause, String serviceName) {
int code = MainApiException.INTERNAL_SERVER_ERROR.getStatusCode();
String statusMessage = MainApiException.INTERNAL_SERVER_ERROR.getStatusMessage();
DeliveryOptions deliveryOptions = new DeliveryOptions();
if (cause instanceof MainApiException) {
code = ((MainApiException)cause).getStatusCode();
statusMessage = ((MainApiException)cause).getStatusMessage();
deliveryOptions.setHeaders(((MainApiException)cause).getHeaders());
} else {
logUnexpectedError(serviceName, cause);
}
deliveryOptions.addHeader(SwaggerRouter.CUSTOM_STATUS_CODE_HEADER_KEY, String.valueOf(code));
deliveryOptions.addHeader(SwaggerRouter.CUSTOM_STATUS_MESSAGE_HEADER_KEY, statusMessage);
message.reply(null, deliveryOptions);
}
示例2: getAsyncResultHandler
import io.vertx.core.eventbus.DeliveryOptions; //导入方法依赖的package包/类
public <T> Handler<AsyncResult<ResourceResponse<T>>> getAsyncResultHandler(Message<JsonObject> message, String serviceName, boolean withJsonEncode, TypeReference<T> type) {
return result -> {
if (result.succeeded()) {
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setHeaders(result.result().getHeaders());
if(withJsonEncode) {
message.reply(Json.encode(result.result().getResponse()), deliveryOptions);
} else {
message.reply(result.result().getResponse(), deliveryOptions);
}
} else {
Throwable cause = result.cause();
manageError(message, cause, serviceName);
}
};
}
示例3: getAsyncResultHandler
import io.vertx.core.eventbus.DeliveryOptions; //导入方法依赖的package包/类
public <T> Handler<AsyncResult<ResourceResponse<T>>> getAsyncResultHandler(Message<JsonObject> message, String serviceName, boolean withJsonEncode, TypeReference<T> type) {
return result -> {
if (result.succeeded()) {
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setHeaders(result.result().getHeaders());
if(withJsonEncode) {
message.reply(result.result().toJson(), deliveryOptions);
} else {
message.reply(result.result().getResponse(), deliveryOptions);
}
} else {
Throwable cause = result.cause();
manageError(message, cause, serviceName);
}
};
}
示例4: processIncoming
import io.vertx.core.eventbus.DeliveryOptions; //导入方法依赖的package包/类
/**
* Check incoming messages for final destinations and then forward them if they are not
* duplicates
*
* @param incomingData received from event bus
*/
protected void processIncoming(final Message<JsonObject> incomingData) {
final MultiMap headers = incomingData.headers();
final List<String> finalDestination = headers.getAll(Constants.BUS_FINAL_DESTINATION);
if ((finalDestination != null) && !finalDestination.isEmpty()) {
final JsonObject j = incomingData.body();
// Forwarding the original headers
final DeliveryOptions dOpts = new DeliveryOptions();
dOpts.setHeaders(headers);
final Future<Void> duplicate = Future.future(f -> {
if (f.succeeded()) {
// Forwarding it to where it should go
final EventBus eb = this.getVertx().eventBus();
finalDestination.forEach(d -> {
eb.send(d, j, dOpts);
});
} else {
this.logger.info("Dropped duplicate Object:" + String.valueOf(j));
}
});
// The duplicate check happens here!
this.checkForDuplicate(duplicate, j);
} else {
this.logger.fatal(new Exception("Incoming message without final destination" + incomingData.toString()));
}
}
示例5: getRxResultHandler
import io.vertx.core.eventbus.DeliveryOptions; //导入方法依赖的package包/类
public <T> Action1<ResourceResponse<T>> getRxResultHandler(Message<JsonObject> message, boolean withJsonEncode, TypeReference<T> type) {
return result -> {
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setHeaders(result.getHeaders());
if (withJsonEncode) {
message.reply(Json.encode(result.getResponse()), deliveryOptions);
} else {
message.reply(result.getResponse(), deliveryOptions);
}
};
}
示例6: getRxResultHandler
import io.vertx.core.eventbus.DeliveryOptions; //导入方法依赖的package包/类
public <T> Action1<ResourceResponse<T>> getRxResultHandler(Message<JsonObject> message, boolean withJsonEncode, TypeReference<T> type) {
return result -> {
DeliveryOptions deliveryOptions = new DeliveryOptions();
deliveryOptions.setHeaders(result.getHeaders());
if (withJsonEncode) {
message.reply(result.toJson(), deliveryOptions);
} else {
message.reply(result.getResponse(), deliveryOptions);
}
};
}