You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by PJ Walstroem <wa...@hotmail.com> on 2012/08/24 13:53:16 UTC

UTF-8 and TypeConversionException

hello,
I have an XML which is UTF-8 encoded (according to itself, at least). The
XML (unfortunately) contains a Triple DES encrypted password, which is
stored in a database as VARCHAR (encoded in UTF-8 according to the DBA).
When Camel (2.10) receives this message, I get an exception and the message
ends up in a configured dead letter queue. Please see exception and
configuration below.

Most messages pass through fine, but we loose maybe 1% of all messages due
to this. The irony is that we are not interested in the USER_PWD field at
all, but it is unfortunately not possible to prevent it from being sent.
Does anyone have any suggestion how to handle this? Should we handle it in
the onException, remove the value of USER_PWD and retry? How would that
configuration look like, in that case?

Any help would be highly appreciated as production date is getting close :-)

2012-08-24 12:28:22,167  WARN o.a.c.p.DefaultErrorHandler - Failed delivery
for (MessageId: 1 on ExchangeId: 1). On delivery attempt: 0 caught:
org.apache.camel.TypeConversionException: Error during type conversion from
type: java.lang.String to the required type: org.w3c.dom.Node with value 
<?xml version="1.0" encoding="UTF-8"?>
<cell name="USER_PWD" type="VARCHAR">wT)^Q&amp;^@#S</cell>
due org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x11)
was found in the element content of the document.

The route is configured as follows:

        errorHandler(defaultErrorHandler()
                .maximumRedeliveries(1)
                .redeliveryDelay(2000)
                .useOriginalMessage()
                .logStackTrace(true)
                .retryAttemptedLogLevel(LoggingLevel.WARN));

        onException(Exception.class)
                .log(LoggingLevel.ERROR, "DEADLETTER QUEUE: ${exception}")
                .handled(true)
                .useOriginalMessage()
                .to(DEAD_LETTER_QUEUE);

        from(extServerQueue, EndPointUri.EXTSERVER_QUEUE)
                .convertBodyTo(String.class)
                .filter(header("JMSRedelivered").isNotEqualTo("true"))
                .to(EndPointUri.INCOMING_QUEUE);






--
View this message in context: http://camel.465427.n5.nabble.com/UTF-8-and-TypeConversionException-tp5717996.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: UTF-8 and TypeConversionException

Posted by PJ Walstroem <wa...@hotmail.com>.
ok, the solution was quite simple by using the charset as a parameter to
convertBodyTo

.convertBodyTo(String.class, com.google.common.base.Charsets.UTF_8.name())



--
View this message in context: http://camel.465427.n5.nabble.com/UTF-8-and-TypeConversionException-tp5717996p5718032.html
Sent from the Camel - Users mailing list archive at Nabble.com.