use of org.opennms.core.rpc.api.RpcResponse in project opennms by OpenNMS.
the class CamelRpcClientPreProcessor method process.
@Override
public void process(Exchange exchange) {
@SuppressWarnings("unchecked") final CamelRpcRequest<RpcRequest, RpcResponse> wrapper = exchange.getIn().getBody(CamelRpcRequest.class);
final JmsQueueNameFactory queueNameFactory = new JmsQueueNameFactory(CamelRpcConstants.JMS_QUEUE_PREFIX, wrapper.getModule().getId(), wrapper.getRequest().getLocation());
exchange.getIn().setHeader(CamelRpcConstants.JMS_QUEUE_NAME_HEADER, queueNameFactory.getName());
exchange.getIn().setHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER, wrapper.getRequest().getTimeToLiveMs() != null ? wrapper.getRequest().getTimeToLiveMs() : CAMEL_JMS_REQUEST_TIMEOUT);
final String request = wrapper.getModule().marshalRequest((RpcRequest) wrapper.getRequest());
exchange.getIn().setBody(request);
}
use of org.opennms.core.rpc.api.RpcResponse in project opennms by OpenNMS.
the class CamelRpcServerRouteManager method bind.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void bind(RpcModule module) throws Exception {
if (module != null) {
final RpcModule<RpcRequest, RpcResponse> rpcModule = (RpcModule<RpcRequest, RpcResponse>) module;
final String routeId = getRouteId(rpcModule);
final Route existingRoute = context.getRoute(routeId);
if (routeIdsByModule.containsKey(rpcModule)) {
if (existingRoute == null) {
LOG.error("RpcModule {} ({}) was marked as registered but its route {} cannot be found in the Camel context", rpcModule.getId(), Integer.toHexString(rpcModule.hashCode()), routeId);
} else {
LOG.warn("RpcModule {} ({}) was already registered on route {}: {}", rpcModule.getId(), Integer.toHexString(rpcModule.hashCode()), routeId, existingRoute);
}
} else {
if (existingRoute == null) {
final DynamicRpcRouteBuilder routeBuilder = new DynamicRpcRouteBuilder(context, identity, rpcModule);
context.addRoutes(routeBuilder);
routeIdsByModule.put(rpcModule, routeId);
LOG.info("Registered RpcModule {} ({}) on route {} with queue {}", rpcModule.getId(), Integer.toHexString(rpcModule.hashCode()), routeId, routeBuilder.getQueueName());
} else {
LOG.warn("RpcModule {} ({}) cannot be registered, route {} is already present: {}", rpcModule.getId(), Integer.toHexString(rpcModule.hashCode()), routeId, existingRoute);
}
}
}
}
use of org.opennms.core.rpc.api.RpcResponse in project opennms by OpenNMS.
the class CamelRpcServerProcessor method process.
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
final RpcRequest request = module.unmarshalRequest(exchange.getIn().getBody(String.class));
final CompletableFuture<RpcResponse> future = module.execute(request);
future.whenComplete((res, ex) -> {
try {
final RpcResponse response;
if (ex != null) {
// An exception occurred, store the exception in a new response
LOG.warn("An error occured while executing a call in {}.", module.getId(), ex);
response = module.createResponseWithException(ex);
} else {
// No exception occurred, use the given response
response = res;
}
try {
exchange.getOut().setBody(module.marshalResponse(response), String.class);
} catch (Throwable t) {
LOG.error("Marshalling a response in RPC module {} failed.", module, t);
exchange.setException(t);
exchange.getOut().setFault(true);
}
} finally {
callback.done(false);
}
});
return false;
}
Aggregations