use of io.helidon.webserver.Service in project helidon by oracle.
the class LraCdiExtension method beforeServerStart.
private void beforeServerStart(@Observes @Priority(PLATFORM_AFTER + 99) @Initialized(ApplicationScoped.class) Object event, BeanManager beanManager) {
NonJaxRsResource nonJaxRsResource = resolve(NonJaxRsResource.class, beanManager);
Service nonJaxRsParticipantService = nonJaxRsResource.createNonJaxRsParticipantResource();
beanManager.getExtension(ServerCdiExtension.class).serverRoutingBuilder().register(nonJaxRsResource.contextPath(), nonJaxRsParticipantService);
}
use of io.helidon.webserver.Service in project helidon by oracle.
the class NonJaxRsResource method createNonJaxRsParticipantResource.
Service createNonJaxRsParticipantResource() {
return rules -> rules.any("/{type}/{fqdn}/{methodName}", (req, res) -> {
LOGGER.log(Level.FINE, () -> "Non JAX-RS LRA resource " + req.method().name() + " " + req.absoluteUri());
RequestHeaders headers = req.headers();
HttpRequest.Path path = req.path();
URI lraId = headers.first(LRA_HTTP_CONTEXT_HEADER).or(() -> headers.first(LRA_HTTP_ENDED_CONTEXT_HEADER)).map(URI::create).orElse(null);
URI parentId = headers.first(LRA_HTTP_PARENT_CONTEXT_HEADER).map(URI::create).orElse(null);
PropagatedHeaders propagatedHeaders = participantService.prepareCustomHeaderPropagation(headers.toMap());
String fqdn = path.param("fqdn");
String method = path.param("methodName");
String type = path.param("type");
switch(type) {
case "compensate":
case "complete":
Single.<Optional<?>>empty().observeOn(exec).onCompleteResumeWithSingle(o -> participantService.invoke(fqdn, method, lraId, parentId, propagatedHeaders)).forSingle(result -> result.ifPresentOrElse(r -> sendResult(res, r), res::send)).exceptionallyAccept(t -> sendError(lraId, req, res, t));
break;
case "afterlra":
req.content().as(String.class).map(LRAStatus::valueOf).observeOn(exec).flatMapSingle(s -> Single.defer(() -> participantService.invoke(fqdn, method, lraId, s, propagatedHeaders))).onComplete(res::send).onError(t -> sendError(lraId, req, res, t)).ignoreElement();
break;
case "status":
Single.<Optional<?>>empty().observeOn(exec).onCompleteResumeWithSingle(o -> participantService.invoke(fqdn, method, lraId, null, propagatedHeaders)).forSingle(result -> result.ifPresentOrElse(r -> sendResult(res, r), // or in the case of non-JAX-RS method returning ParticipantStatus null.
() -> res.status(Response.Status.GONE.getStatusCode()).send())).exceptionallyAccept(t -> sendError(lraId, req, res, t));
break;
case "forget":
Single.<Optional<?>>empty().observeOn(exec).onCompleteResumeWithSingle(o -> participantService.invoke(fqdn, method, lraId, parentId, propagatedHeaders)).onComplete(res::send).onError(t -> sendError(lraId, req, res, t)).ignoreElement();
break;
default:
LOGGER.severe(() -> "Unexpected non Jax-Rs LRA compensation type " + type + ": " + req.absoluteUri());
res.status(404).send();
break;
}
});
}
use of io.helidon.webserver.Service in project helidon by oracle.
the class ServerCdiExtension method registerWebServerServices.
@SuppressWarnings("unchecked")
private void registerWebServerServices(BeanManager beanManager) {
List<Bean<?>> beans = prioritySort(beanManager.getBeans(Service.class));
CreationalContext<Object> context = beanManager.createCreationalContext(null);
for (Bean<?> bean : beans) {
Bean<Object> objBean = (Bean<Object>) bean;
Service service = (Service) objBean.create(context);
registerWebServerService(serviceBeans.remove(bean), service);
}
STARTUP_LOGGER.finest("Registered WebServer services");
}
Aggregations