Hi

Ups the link was wrong. Here it is
http://svn.apache.org/viewvc?view=rev&revision=782887

On Tue, Jun 9, 2009 at 8:02 AM, Claus Ibsen<[email protected]> wrote:
> Hi
>
> I have re produced an unit test that is a bit similar to yours.
> I cannot get the type converter issue.
>
> I am using Camel 1.6.1.
>
> See the code here
> http://svn.apache.org/viewvc?view=rev
>
> I suggest that you check that the file really exists. That could be the issue.
> You can use the file.exist() to check if there is a file.
>
>
> On Mon, Jun 8, 2009 at 10:04 AM, cgveld<[email protected]> wrote:
>>
>> Hi,
>>
>> Thanks for your amazingly quick reply. :)
>>
>> Here is the part of the route what it is all about:
>> from("activemq:out." + getPortalId())
>>    // Because the xml fragment does not contain the usual <?xml version...
>> etc.
>>    // we have to force the encoding on the input read from the queue.
>>    .setProperty(Exchange.CHARSET_NAME, constant("UTF-8"))
>>
>>    .setHeader(AGENT_ID, new XPathExpression("/agent/@id"))
>>
>>    .process(new FixateHeaderValuesProcessor())
>>
>>    // reading objects per agent
>>    .setHeader(FileComponent.HEADER_FILE_NAME, new
>> SimpleExpression(getCacheLocation() + "/${in.header." + AGENT_ID +
>> "}/agent.xml"))
>>    .process(new ReadLocalFile())
>>
>>    .to("direct:filterxml")
>>
>>    .setHeader("portal.id", constant(getPortalId()))
>>
>>    .multicast()
>>    .to("direct:portalxml", "direct:historyxml")
>>    ;
>>
>> from("direct:filterxml")
>>    .process(new FilterProcessor())
>>    ;
>>
>> from("direct:portalxml")
>>    .to("xslt:" + getPortalXsltUri())
>>    .setHeader(FileComponent.HEADER_FILE_NAME, new
>> SimpleExpression("${in.header." + AGENT_ID + "}/agent.xml"))
>>    .to("file://" + getPublishLocation() + "/" + getPortalId() +
>> "?append=false")
>>    ;
>>
>> from("direct:historyxml")
>>    .to("xslt:" + getHistoryXsltUri())
>>    .setHeader(FileComponent.HEADER_FILE_NAME, new
>> SimpleExpression("${in.header." + AGENT_ID + "}/history.xml"))
>>    .to("file://" + getPublishLocation() + "/" + getPortalId() +
>> "?append=false")
>>    ;
>>
>> And here are the custom processors:
>> /**
>>  * type convert a few headers to string, otherwise they will not survive
>> hops to jms ques.
>>  */
>> private class FixateHeaderValuesProcessor implements Processor {
>>
>>    public void process(Exchange arg0) throws Exception {
>>        String id = arg0.getIn().getHeader(AGENT_ID, String.class);
>>        arg0.getIn().setHeader(AGENT_ID, id);
>>    }
>> }
>>
>> /*
>>  *
>>  */
>> private class ReadLocalFile implements Processor {
>>
>>    public void process(Exchange exchange) throws Exception {
>>        // get the filename from our custom header
>>        String filename =
>> exchange.getIn().getHeader(FileComponent.HEADER_FILE_NAME, String.class);
>>        exchange.getIn().setBody(new File(filename));
>>    }
>> }
>>
>> /*
>>  * Remove objects from xml by xpath queries
>>  */
>> private class FilterProcessor implements Processor {
>>
>>    public void process(Exchange exchange) throws Exception {
>>        String portalId = getPortalId();
>>
>>        XPathFactory factory = XPathFactory.newInstance();
>>        XPath xpath = factory.newXPath();
>>
>>        List<String> expressions = new ArrayList<String>();
>>        expressions.add("//object[count(.//port...@id=" + portalId + "]) =
>> 0]");
>>        expressions.add("//object[(.//action != 'DELETE') and
>> (language!='de')]");
>>        expressions.add("//object[(.//action != 'DELETE') and
>> (string-length(postalcode) <= 0)]");
>>        expressions.add("//object[(.//action != 'DELETE') and
>> (string-length(cityname) <= 0)]");
>>
>>        Document document = exchange.getIn().getBody(Document.class);
>>
>>        for (String expr : expressions) {
>>
>>                NodeList nodes = (NodeList) 
>> xpath.compile(expr).evaluate(document,
>> XPathConstants.NODESET);
>>
>>            for (int i = 0; i < nodes.getLength(); i++) {
>>                Node node = nodes.item(i);
>>                    node.getParentNode().removeChild(node);
>>            }
>>        }
>>
>>        exchange.getIn().setBody(document);
>>    }
>> }
>>
>> I tried your solution with the default message. This gave me another
>> exception:
>> WARN  efaultMessageListenerContainer - Execution of JMS message listener
>> failed
>> org.apache.camel.RuntimeCamelException: java.lang.ClassCastException:
>> org.apache.camel.impl.DefaultMessage
>>        at
>> org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:842)
>>        at
>> org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:95)
>>        at
>> org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:531)
>>        at
>> org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:466)
>>        at
>> org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:435)
>>        at
>> org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:322)
>>        at
>> org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:260)
>>        at
>> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:944)
>>        at
>> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:875)
>>        at java.lang.Thread.run(Thread.java:613)
>> Caused by: java.lang.ClassCastException:
>> org.apache.camel.impl.DefaultMessage
>>        at 
>> org.apache.camel.component.jms.JmsExchange.getIn(JmsExchange.java:52)
>>        at 
>> org.apache.camel.component.jms.JmsExchange.getIn(JmsExchange.java:32)
>>        at
>> org.apache.camel.processor.Pipeline.createNextExchange(Pipeline.java:185)
>>        at org.apache.camel.processor.Pipeline.process(Pipeline.java:86)
>>        at
>> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:68)
>>        at
>> org.apache.camel.processor.interceptor.StreamCachingInterceptor.proceed(StreamCachingInterceptor.java:87)
>>        at
>> org.apache.camel.processor.interceptor.StreamCachingInterceptor.process(StreamCachingInterceptor.java:82)
>>        at
>> org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:52)
>>        at
>> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:41)
>>        at
>> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:66)
>>        at
>> org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:72)
>>        ... 8 more
>>
>>
>> --
>> View this message in context: 
>> http://www.nabble.com/Exception-on-typeconversion%2C-but-result-is-ok--tp23887671p23919884.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Reply via email to