Hi,
I'm trying to do a simple xslt transformation. Here is my simple main method. Sorry if it is difficult to read.
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
CamelContext context = new DefaultCamelContext();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
from("test-jms:queue:test.queue").process(new Processor() {
public void process(Exchange e) throws Exception {
System.out.println("Received exchange: " + e.getIn());
File styleSheet = new File("rugby_fixtures.xslt");
XsltBuilder xsltBuilder = XsltBuilder.xslt(styleSheet);
XsltBuilder xsltBuilder1 = xsltBuilder.outputString();
ProcessorType processorType = from("jms:ss.input.rugby_union").process(XsltBuilder.xslt(styleSheet));
from("jms:ss.input.rugby_union").process(XsltBuilder.xslt(styleSheet)).to("file://rugbyFixutes/fixtures.inc");
System.out.println("Received exchange: " + e.getIn());
}
});
}
});
CamelTemplate template = new CamelTemplate(context);
context.start();
File file = new File("rugbyFixturesCollated.xml");
XPP3Reader reader = new XPP3Reader();
Document rugbyFixtures = reader.read(file);
String xmlMessage = rugbyFixtures.asXML();
template.sendBody("test-jms:queue:test.queue", xmlMessage );
Thread.sleep(1000);
context.stop();
}
So I know the xslt works as I've tested it in a browser. The println line outputs the message as well and I can see the complete xml.
However what I really wanted to do was to be able to see the result of the transformation which is me playing around with the outputString method but that just sets the output. Is there a way I can look the output for debuggins purposes.
Also this doesn't appear to output a file. I'd expect a directory and rugbyFixtures/fixtures.inc to be created but one isn't.
Apologies if this is a bit basic.
Jonathan
James.Strachan wrote
On 05/10/2007, jpcook <jonathan.cook@erars.plus.com> wrote:
>
> Doh. ignore last post.
> URL styleSheet = getClass().getResource("/xslt/rugbyFixtures.xslt");
> from("jms:ss.service.solrenderservice").process(XsltBuilder.xslt(styleSheet)).to("file:rugbyFixtures");
Yeah - one of the downsides with the current DSL is often we use
static imports to make things extensible; so the use of xslt in that
one was probably a static import you saw. We should try and remove
those and add things like xpath, xslt and the like to the DSL so that
IDEs properly smart complete etc.
> What I would like to be able to do is. read in a message from my jms. Then
> get one of the xml attributes from the message to lookup the location of
> where I want to send the output.
>
> I think it is that recipientList pattern. Would that be possible?
Yeah - you could either do a content based router using XPath
predicates, or use an XPath expression to determine the URL to send
to.
e.g.
from("activemq:myQueue").recipientList(xpath("'activemq:my.' + /foo/bar"));
i.e. using an XPath expression to determine the URI to send the message to.
> Finally I'm not quite sure what I should be doing with exceptions. Just
> logging them, and which log will they appear in?
There's an error handler plugin you can use to customize what to do
with exceptions and errors...
http://activemq.apache.org/camel/error-handler.htmlso for example you can use a dead letter channel to retry on
exceptions until some number of times and then log it to some queue or
log.
--
James
-------
http://macstrac.blogspot.com/Open Source SOA
http://open.iona.com