camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CAMEL-3143) OsgiDefaultCamelContext.getTypeConverterRegistry() returns null
Date Wed, 22 Sep 2010 06:32:41 GMT

    [ https://issues.apache.org/activemq/browse/CAMEL-3143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=61979#action_61979
] 

Claus Ibsen commented on CAMEL-3143:
------------------------------------

Yeah lets add a dozer test in camel-itest-osgi. Then we can look at a nicer solution to this

> OsgiDefaultCamelContext.getTypeConverterRegistry() returns null 
> ----------------------------------------------------------------
>
>                 Key: CAMEL-3143
>                 URL: https://issues.apache.org/activemq/browse/CAMEL-3143
>             Project: Apache Camel
>          Issue Type: Bug
>          Components: osgi
>    Affects Versions: 2.4.0
>            Reporter: Claes Redestad
>            Assignee: Claus Ibsen
>
> The showed up when using dozer as shown in http://camel.apache.org/dozer-type-conversion.html,
whose DozerTypeConverterLoader tries to get the type converter registry using: {{{TypeConverterRegistry
registry = camelContext.getTypeConverterRegistry();}}}
> Plausible error:
> {code:title=OsgiDefaultCamelContext.java}
>    @Override
>     protected TypeConverter createTypeConverter() {
>         return new OsgiTypeConverter(bundleContext, getInjector());
>     }
> {code}
> {code:title=DefaultCamelContext.java}
> public TypeConverterRegistry getTypeConverterRegistry() {
>         if (typeConverterRegistry == null) {
>             // init type converter as its lazy
>             if (typeConverter == null) {
>                 getTypeConverter();
>             }
>             // type converter is usually the default one that also is the registry
>             if (typeConverter instanceof DefaultTypeConverter) {
>                 typeConverterRegistry = (DefaultTypeConverter) typeConverter;
>             }
>         }
>         return typeConverterRegistry;
>     }
> {code}
> Error:
> getTypeConverter() returns an OsgiTypeConverter 
> OsgiTypeConverter does not inherit from DefaultTypeConverter, thus the instanceof returns
false
> => null is returned
> Solution:
> Lots of different ways to do this, and it's getting late here. In this case, maybe it's
OsgiDefaultCamelContext's responsibility to also override getTypeConverterRegistry with something
along the lines of:
> {code}
> @Override
> public TypeConverterRegistry getTypeConverterRegistry() {
>         if (typeConverterRegistry == null) {
>             // init type converter as its lazy
>             if (typeConverter == null) {
>                 getTypeConverter();
>             }
>             // type converter is usually the default one that also is the registry
>             if (typeConverter instanceof OsgiDefaultTypeConverter) {
>                 typeConverterRegistry = ((OsgiDefaultTypeConverter) typeConverter).getRegistry();
>             }
>         }
>         return typeConverterRegistry;
>     }
> {code}
> We've employed an (ugly) workaround in a local version of DozerTypeConverterLoader.java:
> {code:java}
>         TypeConverter typeConverter = camelContext.getTypeConverter();
>         DefaultTypeConverter registry = null;
>         if (typeConverter instanceof DefaultTypeConverter) {
>             registry = (DefaultTypeConverter)typeConverter;
>         } else if (typeConverter instanceof OsgiTypeConverter) {
>             OsgiTypeConverter osgiTypeConverter = (OsgiTypeConverter)typeConverter;
>             registry = osgiTypeConverter.getRegistry();
>         }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message