org.apache.camel.language.XPath Java Examples

The following examples show how to use org.apache.camel.language.XPath. 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: PartnerServiceBean.java    From camelinaction2 with Apache License 2.0 7 votes vote down vote up
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;
}
 
Example #2
Source File: PartnerServiceBean.java    From camelinaction with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #3
Source File: ValidatorBean.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public void validate(@XPath("/order/@name") String partName, Exchange exchange) {
    // only motors are valid parts in this simple test bean
    if ("motor".equals(partName)) {
        exchange.getOut().setBody("Valid");
    } else {
        exchange.getOut().setBody("Invalid");
    }
}
 
Example #4
Source File: PartnerServiceBean.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #5
Source File: RecipientListBean.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
@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"};
    }
}
 
Example #6
Source File: XmlOrderNamespaceService.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: XmlOrderService.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #8
Source File: ValidatorBean.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
public void validate(@XPath("/order/@name") String partName, Exchange exchange) {
    // only motors are valid parts in this simple test bean
    if ("motor".equals(partName)) {
        exchange.getOut().setBody("Valid");
    } else {
        exchange.getOut().setBody("Invalid");
    }
}
 
Example #9
Source File: OrderToSqlBean.java    From camelinaction with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #10
Source File: RecipientsBean.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
public String[] recipients(@XPath("/order/@customer") String customer) {
    if (isGoldCustomer(customer)) {
        return new String[] {"jms:accounting", "jms:production"};
    } else {
        return new String[] {"jms:accounting"};
    }
}
 
Example #11
Source File: AnnotatedRecipientList.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
@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"};
    }
}
 
Example #12
Source File: PartnerServiceBean.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #13
Source File: PartnerServiceBean.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #14
Source File: PartnerServiceBean.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #15
Source File: XmlOrderNamespaceService.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #16
Source File: XmlOrderService.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #17
Source File: OrderToSqlBean.java    From camelinaction2 with Apache License 2.0 5 votes vote down vote up
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)";
}
 
Example #18
Source File: MyPredicateBeanBinding.java    From camel-cookbook-examples with Apache License 2.0 4 votes vote down vote up
public boolean isWhatIWant(@XPath("/someXml/city/text()") String city) {
    return "Boston".equals(city);
}