You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.4 KiB

package com.example.camel;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.bean.validator.BeanValidationException;
import org.apache.camel.model.dataformat.JsonLibrary;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import jakarta.ws.rs.core.Response;
@Component
public class CamelRouter extends RouteBuilder {
@Value("${app.queue-name}")
private String queueName;
@Override
public void configure() throws Exception {
// very raw way, just to handle the validation responses
onException(BeanValidationException.class).handled(true)
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(Response.Status.BAD_REQUEST.getStatusCode()))
.setBody(simple("${exchangeProperty.CamelExceptionCaught.getMessage()}"));
from("cxfrs:/api?resourceClasses=" + UserService.class.getName() + "&bindingStyle=SimpleConsumer"
+ "&providers=jaxrsProvider&loggingFeatureEnabled=true").to("log:cxfrs-log?showAll=true")
.to("bean-validator:user").setHeader(Exchange.BEAN_METHOD_NAME, simple("${header.operationName}"))
.to("activemq6:queue:"+queueName);
from("activemq6:queue:"+queueName).to("log:activemq6-log?showAll=true").to("disruptor:UserDisruptor");
from("disruptor:UserDisruptor").to("log:disruptor-log?showAll=true").bean(UserServiceImpl.class).marshal()
.json(JsonLibrary.Jackson);
}
}