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.
33 lines
1.2 KiB
33 lines
1.2 KiB
6 months ago
|
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 {
|
||
|
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=com.example.camel.UserService" +
|
||
|
"&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
|
||
|
}
|
||
|
|
||
|
}
|