camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Björn Bength (JIRA) <j...@apache.org>
Subject [jira] Commented: (CAMEL-3143) OsgiDefaultCamelContext.getTypeConverterRegistry() returns null
Date Wed, 22 Sep 2010 09:48:40 GMT

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

Björn Bength commented on CAMEL-3143:
-------------------------------------

Hello Claus,

I'm a colleague of Claes, 
This ticket (as I assume you understand) is not related directly to Dozer. The same null pointer
is encountered for me
when i try to explicitly add type converters and fallback converters using java code in our
routebuilders in servicemix 4.3.


About dozer:
I can confirm that Dozer could be simpler to use in OSGi but we currently have it running
in a few bundles in camel contexts 
in ServiceMix 4.2 with mapping files. 
An upgrade to ServiceMix 4.3 encountered this problem that Claes did work around . However,
as you you know,
the camel and osgi refactoring last time around seems to have hidden a few camel osgi packages
as private, which means that, with this workaround we need access to these hidden osgi classes.
But thats another story..




> 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
>             Fix For: 2.5.0
>
>
> 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