/** * Get the region code that corresponds to the given country code. * * This method can be used as a plain Java method. However, when it is used inside a Camel route, the @XPath annotation will * evaluate the XPath expression and use the result as the method parameter. In this case, it will fetch the country code * from the order XML message. So, the method will determine the region code for the country that is in the XML message. * * @param country the country code * @return the region code */ public String getRegion(@XPath(value = "/order:order/order:customer/order:country", namespaces = @NamespacePrefix(prefix = "order", uri = "http://fabric8.com/examples/order/v7")) String country) { if (country.equals("AU")) { return APAC; } else if (country.equals("US")) { return AMER; } else { return EMEA; } } }
public Document handleIncomingOrder(@Body Document xml, @XPath(value = "/c:order/@customerId", namespaces = @NamespacePrefix( prefix = "c", uri = "http://camelinaction.com/order")) int customerId, @Bean(ref = "guid", method = "generate") int orderId) { Attr attr = xml.createAttribute("orderId"); attr.setValue("" + orderId); Node node = xml.getElementsByTagName("order").item(0); node.getAttributes().setNamedItem(attr); return xml; }
public Document handleIncomingOrder(@Body Document xml, @XPath("/order/@customerId") int customerId, @Bean(ref = "guid", method = "generate") int orderId) { Attr attr = xml.createAttribute("orderId"); attr.setValue("" + orderId); Node node = xml.getElementsByTagName("order").item(0); node.getAttributes().setNamedItem(attr); return xml; }
public String handleIncomingOrder(@JsonPath("$.order.customerId") int customerId, @JsonPath("$.order.item") String item, @Bean(ref = "guid", method = "generate") int orderId) { // convert the order to a CSV and inject the generated order id return String.format("%d,%d,%s", orderId, customerId, item); }
@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; } }
/** * Validate the order date - orders should only be place from Monday to Saturday. * <p/> * This method can be used as a plain Java method, but when it is used inside a Camel route, the @XPath annotation will kick * in, evaluating the XPath expression and using the result as the method parameter. In this case, it will fetch the order * date from the order XML message. * * @param date the order date * @throws OrderValidationException when the order date is a Sunday */ public void validateOrderDate( @XPath(value = "/order:order/order:date", namespaces = @NamespacePrefix(prefix = "order", uri = "http://fabric8.com/examples/order/v7")) String date) throws OrderValidationException { final Calendar calendar = new GregorianCalendar(); try { calendar.setTime(DATE_FORMAT.parse(date)); if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) { LOGGER.warn("Order validation failure: order date " + date + " should not be a Sunday"); throw new OrderValidationException("Order date should not be a Sunday: " + date); } } catch (ParseException e) { throw new OrderValidationException("Invalid order date: " + date); } }
public String getMail(@XPath("/item/@vendor") String vendor) { return mailMap.get(vendor); } }
public Map toMap(@XPath("partner/@id") int partnerId, @XPath("partner/date/text()") String date, @XPath("partner/code/text()") int statusCode, @XPath("partner/time/text()") long responseTime) { Map map = new HashMap(); map.put("id", partnerId); map.put("date", date); map.put("code", statusCode); map.put("time", responseTime); return map; } }
public Map toMap(@XPath("partner/@id") int partnerId, @XPath("partner/date/text()") String date, @XPath("partner/code/text()") int statusCode, @XPath("partner/time/text()") long responseTime) { Map map = new HashMap(); map.put("id", partnerId); map.put("date", date); map.put("code", statusCode); map.put("time", responseTime); return map; } }
public Map toMap(@XPath("partner/@id") int partnerId, @XPath("partner/date/text()") String date, @XPath("partner/code/text()") int statusCode, @XPath("partner/time/text()") long responseTime) { Map map = new HashMap(); map.put("id", partnerId); map.put("date", date); map.put("code", statusCode); map.put("time", responseTime); return map; } }
public String toSql(@XPath("partner/@id") int partnerId, @XPath("partner/date/text()") String date, @XPath("partner/code/text()") int statusCode, @XPath("partner/time/text()") long responsTime) { StringBuilder sb = new StringBuilder(); sb.append("INSERT INTO PARTNER_METRIC (partner_id, time_occurred, status_code, perf_time) VALUES ("); sb.append("'").append(partnerId).append("', "); sb.append("'").append(date).append("', "); sb.append("'").append(statusCode).append("', "); sb.append("'").append(responsTime).append("') "); return sb.toString(); } }
public String toSql(@XPath("order/@name") String name, @XPath("order/@amount") int amount, @XPath("order/@customer") String customer, @Headers Map<String, Object> outHeaders) { outHeaders.put("partName", name); outHeaders.put("quantity", amount); outHeaders.put("customer", customer); return "insert into incoming_orders (part_name, quantity, customer) values (:?partName, :?quantity, :?customer)"; } }
public String[] recipients(@XPath("/order/@customer") String customer) { if (isGoldCustomer(customer)) { return new String[] {"jms:accounting", "jms:production"}; } else { return new String[] {"jms:accounting"}; } }
public String toSql(@XPath("order/@name") String name, @XPath("order/@amount") int amount, @XPath("order/@customer") String customer) { StringBuilder sb = new StringBuilder(); sb.append("insert into incoming_orders (part_name, quantity, customer) values ("); sb.append("'").append(name).append("', "); sb.append("'").append(amount).append("', "); sb.append("'").append(customer).append("') "); System.out.println(sb.toString()); return sb.toString(); } }
public Map toMap(@XPath("partner/@id") int partnerId, @XPath("partner/date/text()") String date, @XPath("partner/code/text()") int statusCode, @XPath("partner/time/text()") long responseTime) { if (partnerId <= 0) { throw new IllegalArgumentException("PartnerId is invalid, was " + partnerId); } Map map = new HashMap(); map.put("id", partnerId); map.put("date", date); map.put("code", statusCode); map.put("time", responseTime); return map; }
public String toSql(@XPath("partner/@id") int partnerId, @XPath("partner/date/text()") String date, @XPath("partner/code/text()") int statusCode, @XPath("partner/time/text()") long responseTime) { if (partnerId <= 0) { throw new IllegalArgumentException("PartnerId is invalid, was " + partnerId); } StringBuilder sb = new StringBuilder(); sb.append("INSERT INTO PARTNER_METRIC (partner_id, time_occurred, status_code, perf_time) VALUES ("); sb.append("'").append(partnerId).append("', "); sb.append("'").append(date).append("', "); sb.append("'").append(statusCode).append("', "); sb.append("'").append(responseTime).append("') "); return sb.toString(); } }
@RecipientList public String[] route(@XPath("/order/@customer") String customer) { if (isGoldCustomer(customer)) { return new String[] {"jms:accounting", "jms:production"}; } else { return new String[] {"jms:accounting"}; } }
@RecipientList public String[] route(@XPath("/order/@customer") String customer) { if (isGoldCustomer(customer)) { return new String[] {"jms:accounting", "jms:production"}; } else { return new String[] {"jms:accounting"}; } }