27 Temmuz 2020 Pazartesi

Camel JettyComponent Sınıfı

from metodu
Örnek
Şöyle yaparız
from("jetty://0.0.0.0:8080/searchProduct").routeId("searchProduct.products").threads()
.log(LoggingLevel.INFO, "searchProducts request Received with body: ${body}")
.bean(Processor.class, "createSearchProductsRequest").removeHeaders("CamelHttp*")
.setHeader(Exchange.HTTP_METHOD,
    constant(org.apache.camel.component.http4.HttpMethods.POST))
.to("http4://" + preLiveBaseAPI + searchProductsUrl + "?apiKey=" + ApiKey
    + "&bridgeEndpoint=true")
.bean(Processor.class, "buildResponse")
.log(LoggingLevel.INFO, "Search products finished");
get metodu
Örnek - jetty
Şu satırı dahil ederiz
<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
  </dependency>
  <dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
  </dependency>
  <dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-jetty-starter</artifactId>
  </dependency>
  ..
  ..<!-- all other required dependencies are in place-->
  ..
</dependencies>
Şöyle yaparız
restConfiguration()
  .component("jetty")
  .port("8080");
        
rest()
  .path("/api")
  .get("/{name}")
   ..
   ..
  .to("seda:greeting");
port metodu
Şöyle yaparız
@Component
public class EmployeePackageRoute extends RouteBuilder {
        
  @Override
  public void configure() {
    try{
      restConfiguration().component("jetty").port(8000).bindingMode(RestBindingMode.json);
      rest("/api/test/getTestResponse")
        .get().consumes(MediaType.APPLICATION_JSON_VALUE).route().setBody()
.constant("return test response"); rest("/api/bcr/recurringPaymentsDeduct") .post().consumes(MediaType.APPLICATION_JSON_VALUE)
.type(RecurringPaymentResults.class).outType(ResponseEntity.class).route() .process(ex -> { ... ex.getOut().setBody(employee); }) .to("seda:recurringPaymentsFeed"); }catch(Exception e) { ... } } }
unmarshal metodu
Şöyle yaparız.
from("jetty:http://0.0.0.0:8080/api/camel/appoverview")
.to("http4://10.150.60.237:80/api/itsb/applicationoverview?httpMethod=GET&
  bridgeEndpoint=true&throwExceptionOnFailure=true")
.unmarshal().json(JsonLibrary.Jackson)
.transform().simple("${body}")
.log("Response sent -> ${body}");
Jackson için şöyle yaparız
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-jackson</artifactId>
</dependency>

Hiç yorum yok:

Yorum Gönder