Return-Path: X-Original-To: apmail-camel-dev-archive@www.apache.org Delivered-To: apmail-camel-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 03E3D9635 for ; Wed, 18 Apr 2012 08:00:34 +0000 (UTC) Received: (qmail 57810 invoked by uid 500); 18 Apr 2012 08:00:33 -0000 Delivered-To: apmail-camel-dev-archive@camel.apache.org Received: (qmail 57660 invoked by uid 500); 18 Apr 2012 08:00:29 -0000 Mailing-List: contact dev-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list dev@camel.apache.org Received: (qmail 57628 invoked by uid 99); 18 Apr 2012 08:00:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Apr 2012 08:00:28 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of bengt.rodehav@gmail.com designates 209.85.217.173 as permitted sender) Received: from [209.85.217.173] (HELO mail-lb0-f173.google.com) (209.85.217.173) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Apr 2012 08:00:19 +0000 Received: by lboi15 with SMTP id i15so2188991lbo.32 for ; Wed, 18 Apr 2012 00:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; bh=zNmMMIZHJLXhE+kuIFSuCX+F9cFnRDNkt3CN1Wv+EpY=; b=hfCyKT+HlQPWdgVHXt+p90mlZ+DxJgxVys6czlp5x9KRjy5c+nwpsMTWGDBJxw5R8N /nIZX8BWyKyw7i23CjSw0X3j6lqmuTDSmgJi6j6v5VbJ/giB8X1JpNFEMH48dUr75G9o jIcT6+6UJab9rNOXMYouIlWTCJ8ikq+1ZPETfl2Mhn/HH3hkMlN0OrrNbSvFKUC6qrc5 3GocjMCNP//M/P+NA9JsSbtQCVGTG4nERjWlLYyYnp7Kf2seHu/L6eHMJwO3C1z3xDTj 0w+TnqdMHpXYRZmw+/hqEK6M0sL/+rilXzl42ml5uFQsSvrdwuFDlFtXBrvRoicxkoK6 i+kw== MIME-Version: 1.0 Received: by 10.152.115.38 with SMTP id jl6mr1202292lab.24.1334735999074; Wed, 18 Apr 2012 00:59:59 -0700 (PDT) Sender: bengt.rodehav@gmail.com Received: by 10.152.24.74 with HTTP; Wed, 18 Apr 2012 00:59:59 -0700 (PDT) In-Reply-To: References: Date: Wed, 18 Apr 2012 09:59:59 +0200 X-Google-Sender-Auth: gatCUQF0FtYoRS6EFSX_gDhiIiQ Message-ID: Subject: Re: [HEADS UP] - TypeConverter improved in Camel 2.10 From: Bengt Rodehav To: dev@camel.apache.org Content-Type: multipart/alternative; boundary=f46d040891eb18038704bdef719b --f46d040891eb18038704bdef719b Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable +1 I've just spent two days trying to figure out what I did wrong. I had a case where all subsequent xml conversions would fail after I tried to process one xml message in invalid format. Then I found your post. Good job fixing it. /Bengt 2012/4/17 Christian M=FCller > +1, > > and thanks for your hard work... > > Best, > Christian > > On Tue, Apr 17, 2012 at 11:38 AM, Claus Ibsen > wrote: > > > Hi > > > > I am inclined to backport these changes to the 2.9 branch as I think > > the bug from CAMEL-5164 would bite other people as well. > > I have a workaround patch for 2.9 branch as work in progress. But I > > dont feel its an optimal solution, as would the backport of the > > changes from 2.10. > > > > There is only a slight API change in TypeConverter. Most people would > > use the @Converter for their custom converters, and if so, then they > > are okay (no problem there). Only for people who implement the > > TypeConverter directly, and then add that directly to the > > TypeConverterRegistry API. Frankly I dont see this used at all by end > > users (The @Converter is mich simpler). > > > > However there is a slight change in the API from Message.getBody(type) > > and Message.getHeader(name, Type), as they would now throw a > > TypeConversionException if failing. Where as beforehand a WARN would > > be logged and null returned. > > > > IMHO the changes from 2.10 is better and also allows end users to be > > in control of the failure first-hand. And frankly also what I would > > expect from the call. > > > > If nobody scream, then we should get this backported for the next 2.9.3 > > release. > > > > Any thoughts? > > > > > > PS: I have attached my ugly workaround patch. We can use that as a > > backup if someone scream really loud. > > > > > > > > On Tue, Apr 17, 2012 at 7:46 AM, Claus Ibsen > > wrote: > > > Hi > > > > > > Recently I have spent some time to improve the type converters in Cam= el > > 2.10. > > > > > > Most significant is the following changes > > > a) fix important bug > > > b) Fail fast > > > c) tryConvertTo > > > d) Expose utilization statistics > > > > > > > > > Ad a) > > > A bug was reported in https://issues.apache.org/jira/browse/CAMEL-516= 4 > > > > > > In summary if using camel-jaxb that offers a fallback type converter, > > > and a failure occurs during XML marshalling, > > > then subsequent new XML messages may fail, despite they were okay. > > > > > > Ad b) > > > Due to a we need to detect this faster and better. So now the type > > > converter system in Camel will fail fast > > > by throwing a new TypeConversionException (its runtime). That allows > > > Camel to detect the (a) failure faster > > > from a fallback type converter (regular non fallback would fail fast > > already) > > > > > > This means the API is also consistent from caller point of view. You > > > get a TypeConversionException if there > > > was a failure during a type conversion attempt. > > > > > > Ad c) > > > There is some places in camel-core where we want to only try to > > > convert. For example with the binary predicates > > > where you want to compare if X > Y. Then we try to coerce X and Y to > > > numeric values. > > > > > > Likewise there is a few other spots where we do this, such as the XSL= T > > > component, where we try to use StAX, SAX, before DOM etc. > > > So we have introduced a tryConvertTo API, which would not fail during > > > type conversion. > > > > > > Ad d) > > > The type converter system is used a lot in Camel during routing > > > messages. Now we expose utilization statistics, > > > which allow end users to spot if there is too many missing type > > > conversion attempts. For example a route may attempt to convert, wher= e > > > there is no suitable type converter. This can now more easily be > > > spotted, allowing the end user to either. Implement such a missing > > > type converter, or > > > correct a mistake in his application or the likes. > > > > > > The statistics is exposed in JMX and as well when Camel shutdown as a > > log line. > > > > > > > > > > > > > > > On another note I am also hunting down to avoid using the > > > PropertiesEditorTypeConverter, as it has many flaws > > > - its not thread safe > > > - its slow > > > - and 3rd party projects can add property editors that influence > > > Camel's type converts (eg ActiveMQ has a String -> List) properties > > > editor that turns a String into a List of ActiveMQDestination > > > instances. > > > - it does not understand generics in List/Collection type, eg the > > > ActiveMQ example above > > > > > > And basically we uses it only in Camel for doing some of the simpler > > > basic conversions: String <-> Numeric. And so forth. But over the tim= e > > > we have added those as type converter directly in Camel, as they are > > > faster as well. > > > > > > > > > > > > > > > -- > > > Claus Ibsen > > > ----------------- > > > CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com > > > FuseSource > > > Email: cibsen@fusesource.com > > > Web: http://fusesource.com > > > Twitter: davsclaus, fusenews > > > Blog: http://davsclaus.blogspot.com/ > > > Author of Camel in Action: http://www.manning.com/ibsen/ > > > > > > > > -- > > Claus Ibsen > > ----------------- > > CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com > > FuseSource > > Email: cibsen@fusesource.com > > Web: http://fusesource.com > > Twitter: davsclaus, fusenews > > Blog: http://davsclaus.blogspot.com/ > > Author of Camel in Action: http://www.manning.com/ibsen/ > > > --f46d040891eb18038704bdef719b--