|
|
|
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.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import jakarta.ws.rs.core.Response;
|
|
|
|
|
|
|
|
@Component
|
|
|
|
public class CamelRouter extends RouteBuilder {
|
|
|
|
|
|
|
|
@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()}"));
|
|
|
|
|
|
|
|
// @formatter:off
|
|
|
|
from("cxfrs:/api?" +
|
|
|
|
"resourceClasses="+UserService.class.getName() +
|
|
|
|
"&bindingStyle=SimpleConsumer" +
|
|
|
|
"&providers=jaxrsProvider" +
|
|
|
|
"&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
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|