org.apache.camel.Header Java Examples

The following examples show how to use org.apache.camel.Header. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RatingService.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
/**
 * Generate ratings for the items
 * <p/>
 * Notice how the items is mapped to @Header with the name ids, which
 * refers to the context-path {ids} in the rest-dsl service
 */
public List<RatingDto> ratings(@Header("ids") String items) {
    System.out.println("Rating items " + items);

    List<RatingDto> answer = new ArrayList<>();

    for (String id : items.split(",")) {
        RatingDto dto = new RatingDto();
        answer.add(dto);

        dto.setItemNo(Integer.valueOf(id));
        // generate some random ratings
        dto.setRating(new Random().nextInt(100));
    }

    return answer;
}
 
Example #2
Source File: OrderService.java    From camelinaction with Apache License 2.0 6 votes vote down vote up
public void processOrder(Exchange exchange, InputOrder order,
                         @Header(Exchange.REDELIVERED) Boolean redelivered) throws Exception {

    // simulate CPU processing of the order by sleeping a bit
    Thread.sleep(1000);

    // simulate fatal error if we refer to a special no
    if (order.getRefNo().equals("FATAL")) {
        throw new IllegalArgumentException("Simulated fatal error");
    }

    // simulate fail once if we have not yet redelivered, which means its the first
    // time processOrder method is called
    if (order.getRefNo().equals("FAIL-ONCE") && redelivered == null) {
        throw new IOException("Simulated failing once");
    }

    // processing is okay
}
 
Example #3
Source File: RatingService.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
/**
 * Generate ratings for the items
 * <p/>
 * Notice how the items is mapped to @Header with the name ids, which
 * refers to the context-path {ids} in the rest-dsl service
 */
public List<RatingDto> ratings(@Header("ids") String items) {
    System.out.println("Rating items " + items);

    List<RatingDto> answer = new ArrayList<>();

    for (String id : items.split(",")) {
        RatingDto dto = new RatingDto();
        answer.add(dto);

        dto.setItemNo(Integer.valueOf(id));
        // generate some random ratings
        dto.setRating(new Random().nextInt(100));
    }

    return answer;
}
 
Example #4
Source File: OrderService.java    From camelinaction2 with Apache License 2.0 6 votes vote down vote up
public void processOrder(Exchange exchange, InputOrder order,
                         @Header(Exchange.REDELIVERED) Boolean redelivered) throws Exception {

    // simulate CPU processing of the order by sleeping a bit
    Thread.sleep(1000);

    // simulate fatal error if we refer to a special no
    if (order.getRefNo().equals("FATAL")) {
        throw new IllegalArgumentException("Simulated fatal error");
    }

    // simulate fail once if we have not yet redelivered, which means its the first
    // time processOrder method is called
    if (order.getRefNo().equals("FAIL-ONCE") && redelivered == null) {
        throw new IOException("Simulated failing once");
    }

    // processing is okay
}
 
Example #5
Source File: AuditLogService.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public void insertAuditLog(String order, @Header("JMSRedelivered") boolean redelivery) throws Exception {
    // using old-school JdbcTemplate to perform a SQL operation from Java code with spring-jdbc
    JdbcTemplate jdbc = new JdbcTemplate(dataSource);
    String orderId = "" + ++counter;
    String orderValue = order;
    String orderRedelivery = "" + redelivery;

    jdbc.execute(String.format("insert into bookaudit (order_id, order_book, order_redelivery) values ('%s', '%s', '%s')",
            orderId, orderValue, orderRedelivery));
}
 
Example #6
Source File: OrderService.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
public void sendMail(String body, @Header("to") String to) {
    // simulate fatal error if we refer to a special no
    if (to.equals("FATAL")) {
        throw new IllegalArgumentException("Simulated fatal error");
    }

    // simulate CPU processing of the order by sleeping a bit
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // ignore
    }
}
 
Example #7
Source File: DynamicRouterAnnotationBean.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
/**
 * The method invoked by Dynamic Router EIP to compute where to go next.
 * <p/>
 * Notice this method has been annotated with @DynamicRouter which means Camel turns this method
 * invocation into a Dynamic Router EIP automatically.
 *
 * @param body     the message body
 * @param previous the previous endpoint, is <tt>null</tt> on the first invocation
 * @return endpoint uri where to go, or <tt>null</tt> to indicate no more
 */
@DynamicRouter
public String route(String body, @Header(Exchange.SLIP_ENDPOINT) String previous) {
    if (previous == null) {
        // 1st time
        return "mock://a";
    } else if ("mock://a".equals(previous)) {
        // 2nd time - transform the message body using the simple language
        return "language://simple:Bye ${body}";
    } else {
        // no more, so return null to indicate end of dynamic router
        return null;
    }
}
 
Example #8
Source File: PurchaseOrderJSONTest.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
public PurchaseOrder lookup(@Header("id") String id) {
    LOG.info("Finding purchase order for id " + id);
    // just return a fixed response
    PurchaseOrder order = new PurchaseOrder();
    order.setPrice(49.95);
    order.setAmount(1);
    order.setName("Camel in Action");
    return order;
}
 
Example #9
Source File: CombineDataBean.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
public String combine(@Header("ERP") String erp, @Header("CRM") String crm, @Header("SHIPPING") String shipping) {
    StringBuilder sb = new StringBuilder("Customer overview");
    sb.append("\nERP: " + erp);
    sb.append("\nCRM: " + crm);
    sb.append("\nSHIPPING: " + shipping);
    return sb.toString();
}
 
Example #10
Source File: ActivitiRouteBuilder.java    From servicemix with Apache License 2.0 5 votes vote down vote up
@Handler
public Map getProcessVariables(@Body String body,
                               @Header(Exchange.FILE_NAME) String filename,
                               @Simple("${date:now:yyyy-MM-dd kk:mm:ss}") String timestamp) {
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put("message", body);
    variables.put("orderid", filename);
    variables.put("timestamp", timestamp);
    return variables;
}
 
Example #11
Source File: DynamicRouterAnnotationBean.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
/**
 * The method invoked by Dynamic Router EIP to compute where to go next.
 * <p/>
 * Notice this method has been annotated with @DynamicRouter which means Camel turns this method
 * invocation into a Dynamic Router EIP automatically.
 *
 * @param body     the message body
 * @param previous the previous endpoint, is <tt>null</tt> on the first invocation
 * @return endpoint uri where to go, or <tt>null</tt> to indicate no more
 */
@DynamicRouter
public String route(String body, @Header(Exchange.SLIP_ENDPOINT) String previous) {
    if (previous == null) {
        // 1st time
        return "mock://a";
    } else if ("mock://a".equals(previous)) {
        // 2nd time - transform the message body using the simple language
        return "language://simple:Bye ${body}";
    } else {
        // no more, so return null to indicate end of dynamic router
        return null;
    }
}
 
Example #12
Source File: PurchaseOrderJSONTest.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public PurchaseOrder lookup(@Header("id") String id) {
    LOG.info("Finding purchase order for id " + id);
    // just return a fixed response
    PurchaseOrder order = new PurchaseOrder();
    order.setPrice(69.99);
    order.setAmount(1);
    order.setName("Camel in Action");
    return order;
}
 
Example #13
Source File: OrderService.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public void sendMail(String body, @Header("to") String to) {
    // simulate fatal error if we refer to a special no
    if (to.equals("FATAL")) {
        throw new IllegalArgumentException("Simulated fatal error");
    }

    // simulate CPU processing of the order by sleeping a bit
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // ignore
    }
}
 
Example #14
Source File: OrderService.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public Order getOrder(@Header("id") String id) {
    if ("123".equals(id)) {
        Order order = new Order();
        order.setId(123);
        order.setAmount(1);
        order.setMotor("Honda");
        return order;
    } else {
        return null;
    }
}
 
Example #15
Source File: CombineDataBean.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public String combine(@Header("ERP") String erp, @Header("CRM") String crm, @Header("SHIPPING") String shipping) {
    StringBuilder sb = new StringBuilder("Customer overview");
    sb.append("\nERP: " + erp);
    sb.append("\nCRM: " + crm);
    sb.append("\nSHIPPING: " + shipping);
    return sb.toString();
}
 
Example #16
Source File: CartService.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public Set<CartDto> getItems(@Header("sessionId") String sessionId) {
    LOG.info("getItems {}", sessionId);
    Set<CartDto> answer = content.get(sessionId);
    if (answer == null) {
        answer = Collections.emptySet();
    }
    return answer;
}
 
Example #17
Source File: CartService.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public void removeItem(@Header("sessionId") String sessionId, @Header("itemId") String itemId) {
    LOG.info("removeItem {} {}", sessionId, itemId);

    Set<CartDto> dtos = content.get(sessionId);
    if (dtos != null) {
        dtos.removeIf(i -> i.getItemId() == itemId);
    }
}
 
Example #18
Source File: CartService.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public void addItem(@Header("sessionId") String sessionId, @Body CartDto dto) {
    LOG.info("addItem {} {}", sessionId, dto);

    Set<CartDto> dtos = content.get(sessionId);
    if (dtos == null) {
        dtos = new LinkedHashSet<>();
        content.put(sessionId, dtos);
    }
    dtos.add(dto);
}
 
Example #19
Source File: CartService.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public Set<CartDto> getItems(@Header("sessionId") String sessionId) {
    LOG.info("getItems {}", sessionId);
    Set<CartDto> answer = content.get(sessionId);
    if (answer == null) {
        answer = Collections.EMPTY_SET;
    }
    return answer;
}
 
Example #20
Source File: CartService.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public void removeItem(@Header("sessionId") String sessionId, @Header("itemId") String itemId) {
    LOG.info("removeItem {} {}", sessionId, itemId);

    Set<CartDto> dtos = content.get(sessionId);
    if (dtos != null) {
        dtos.remove(itemId);
    }
}
 
Example #21
Source File: CartService.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public void addItem(@Header("sessionId") String sessionId, @Body CartDto dto) {
    LOG.info("addItem {} {}", sessionId, dto);

    Set<CartDto> dtos = content.get(sessionId);
    if (dtos == null) {
        dtos = new LinkedHashSet<>();
        content.put(sessionId, dtos);
    }
    dtos.add(dto);
}
 
Example #22
Source File: LRAIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
public synchronized void reserveCredit(String id, @Header("amount") int amount) {
    int credit = getCredit();
    if (amount > credit) {
        throw new IllegalStateException("Insufficient credit");
    }
    reservations.put(id, amount);
}
 
Example #23
Source File: OrderBean.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
public String orderStatus(@Header("customerId") Integer customerId, @Body Integer orderId) {
    return "Order " + orderId + " from customer " + customerId;
}
 
Example #24
Source File: OrderStatusService.java    From camelinaction with Apache License 2.0 4 votes vote down vote up
public String checkStatus(@Header("id") String id) throws Exception {
    if ("123".equals(id)) {
        return "Processing";
    }
    return "Complete";
}
 
Example #25
Source File: Main.java    From funktion-connectors with Apache License 2.0 4 votes vote down vote up
public Object main(String body, @Header("name") String name) {
    return "Hello " + name + ". I got payload `" + body + "` and I am on host: " + System.getenv("HOSTNAME");
}
 
Example #26
Source File: DynamicRouterBean.java    From camelinaction with Apache License 2.0 2 votes vote down vote up
/**
 * The method invoked by Dynamic Router EIP to compute where to go next.
 *
 * @param body          the message body
 * @param previous   the previous endpoint, is <tt>null</tt> on the first invocation
 * @return endpoint uri where to go, or <tt>null</tt> to indicate no more
 */
public String route(String body, @Header(Exchange.SLIP_ENDPOINT) String previous) {
    return whereToGo(body, previous);
}
 
Example #27
Source File: DynamicRouterBean.java    From camelinaction2 with Apache License 2.0 2 votes vote down vote up
/**
 * The method invoked by Dynamic Router EIP to compute where to go next.
 *
 * @param body          the message body
 * @param previous   the previous endpoint, is <tt>null</tt> on the first invocation
 * @return endpoint uri where to go, or <tt>null</tt> to indicate no more
 */
public String route(String body, @Header(Exchange.SLIP_ENDPOINT) String previous) {
    return whereToGo(body, previous);
}
 
Example #28
Source File: Main.java    From funktion-connectors with Apache License 2.0 2 votes vote down vote up
/**
 * The method used as funktion
 *
 * @param body  the message body
 * @param name  the header with the key name
 * @return the response from the funktion
 */
public Object cheese(String body, @Header("name") String name) {
    return "Hello " + name + ". I got payload `" + body + "` and I am on host: " + System.getenv("HOSTNAME");
}