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