Permalink
Browse files

got something working here. can now retrieve a file from the filesyst…

…em which is used to enrich the response
  • Loading branch information...
1 parent 12434a7 commit a930c71707c657a54c20bb792c3364090c6f94e4 @christian-posta committed Apr 24, 2012
View
@@ -10,6 +10,7 @@
<properties>
<camel.version>2.8.0-fuse-04-01</camel.version>
+ <cxf.version>2.4.3-fuse-02-02</cxf.version>
</properties>
<dependencies>
@@ -18,6 +19,21 @@
<artifactId>camel-cxf</artifactId>
<version>${camel.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-transports-http-jetty</artifactId>
+ <version>${cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.6.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.6.4</version>
+ </dependency>
</dependencies>
<repositories>
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Customer><id>123</id><name>John</name></Customer>
@@ -0,0 +1,22 @@
+package com.fusesource.samples;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: cposta
+ * Date: 4/24/12
+ * Time: 2:35 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class CustomerEnricher implements AggregationStrategy {
+
+ @Override
+ public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+ oldExchange.getIn().setHeader("OrigId", oldExchange.getIn().getBody(String.class));
+// oldExchange.getOut().setBody(newExchange.getIn().getBody(String.class));
+ oldExchange.getIn().setBody(newExchange.getIn().getBody(String.class));
+ return oldExchange;
+ }
+}
@@ -4,6 +4,8 @@
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.component.cxf.common.message.CxfConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.ws.rs.core.Response;
import java.util.HashMap;
@@ -17,6 +19,7 @@
* To change this template use File | Settings | File Templates.
*/
public class CustomerServiceProcessor implements Processor {
+ private static final Logger LOG = LoggerFactory.getLogger(CustomerServiceProcessor.class);
private Map<Long, Customer> customers = new HashMap<Long, Customer>();
private Map<Long, Order> orders = new HashMap<Long, Order>();
@@ -41,8 +44,8 @@ public void process(Exchange exchange) throws Exception {
Message inMessage = exchange.getIn();
String operationName = inMessage.getHeader(CxfConstants.OPERATION_NAME, String.class);
if ("getCustomer".equalsIgnoreCase(operationName)) {
- String id = inMessage.getBody(String.class);
- System.out.println("----invoking getCustomer, Customer id is: " + id);
+ String id = inMessage.getHeader("OrigId", String.class);
+ LOG.info("----invoking getCustomer, Customer id is: " + id);
long idNumber = Long.parseLong(id);
@@ -54,7 +57,7 @@ public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody(response);
}
- exchange.getOut().setBody(c);
+// exchange.getOut().setBody(c);
}
@@ -0,0 +1,25 @@
+package com.fusesource.samples;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: cposta
+ * Date: 4/24/12
+ * Time: 2:03 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class CustomerServiceRoute extends RouteBuilder {
+ @Override
+ public void configure() throws Exception {
+ getContext().setTracing(true);
+
+
+ from("cxfrs://http://localhost:9090/route?resourceClasses=com.fusesource.samples.CustomerServiceResource")
+ .setHeader(Exchange.FILE_NAME, simple("test-${body}.xml"))
+ .pollEnrich("file:src/data?noop=true", 1000, new CustomerEnricher())
+ .process(new CustomerServiceProcessor())
+ .log("Here is the message that was enriched: ${body}");
+ }
+}
@@ -7,15 +7,18 @@
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<cxf:rsServer id="rsServer" address="http://localhost:9090/route"
- serviceClass="org.fusesource.examples.cxf.jaxrs.CustomerService"/>
+ serviceClass="com.fusesource.samples.CustomerServiceResource"/>
<bean id="customerServProcessor" class="com.fusesource.samples.CustomerServiceProcessor"/>
+ <bean id="routeBuilder" class="com.fusesource.samples.CustomerServiceRoute"/>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
- <route id="customerRoute">
- <from uri="cxfrs:bean:rsServer"/>
- <process ref="customerServProcessor"/>
- </route>
+ <!--<route id="customerRoute">-->
+ <!--<from uri="cxfrs:bean:rsServer"/>-->
+ <!--<log message="Received a message: ${body}"/>-->
+ <!--<process ref="customerServProcessor"/>-->
+ <!--</route>-->
+ <routeBuilder ref="routeBuilder"/>
</camelContext>
@@ -0,0 +1,10 @@
+log4j.rootCategory=INFO, stdout
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout.ConversionPattern=%t %p [%c] - %m%n
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.threshold=TRACE
+
+#log4j.logger.org.springframework.osgi=DEBUG
+#log4j.logger.org.springframework=DEBUG
+log4j.logger.com.fusesource=DEBUG
+log4j.additivity.org.apache.camel.impl.DefaultCamelContext=false

0 comments on commit a930c71

Please sign in to comment.