You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@tiles.apache.org by "Bjorn Harvold (JIRA)" <ji...@apache.org> on 2009/04/02 07:45:02 UTC

[jira] Issue Comment Edited: (TILES-387) Creating a tilesConfigurer for Spring Web does not work in an OSGi environment

    [ https://issues.apache.org/struts/browse/TILES-387?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45822#action_45822 ] 

Bjorn Harvold edited comment on TILES-387 at 4/1/09 10:44 PM:
--------------------------------------------------------------

I looked at the documentation for a pure Java configuration. I am not quite sure what to do in this case. Is there sample code for this? Regardless of which way we initialize Tiles, if there is a class loader in one bundle that tries to instantiate a class from another bundle and the former bundle doesn't have the latter bundle as part of its osgi imports, it won't work. I am going to fiddle around with the pure configuration in the mean time. If you have some sample code, that would be great.. or should I just extend the BasicTilesContainerFactory or the ServletTilesApplicationContextFactory?

E.g.
protected TilesContainer createTilesContainer() throws TilesException {
        ServletContextAdapter adaptedContext = new ServletContextAdapter(new DelegatingServletConfig());
        TilesApplicationContext preliminaryContext = new ServletTilesApplicationContext(adaptedContext);
        AbstractTilesApplicationContextFactory contextFactory = MyServletTilesApplicationContextFactory.createFactory(preliminaryContext);
        this.tilesContext = contextFactory.createApplicationContext(adaptedContext);
        AbstractTilesContainerFactory factory = MyBasicTilesContainerFactory.getTilesContainerFactory(this.tilesContext);

        return factory.createContainer(this.tilesContext);
    }

where both of my classes do nothing but extend. This will of course throw the same classnotfoundexception. Also if you just specify those classes in web.xml.

      was (Author: bjornharvold):
    I looked at the documentation for a pure Java configuration. I am not quite sure what to do in this case. Is there sample code for this? Regardless of which way we initialize Tiles, if there is a class loader in one bundle that tries to instantiate a class from another bundle and the former bundle doesn't have the latter bundle as part of its osgi imports, it won't work. I am going to fiddle around with the pure configuration in the mean time. If you have some sample code, that would be great.. or should I just extend the BasicTilesContainerFactory or the ServletTilesApplicationContextFactory?
  
> Creating a tilesConfigurer for Spring Web does not work in an OSGi environment
> ------------------------------------------------------------------------------
>
>                 Key: TILES-387
>                 URL: https://issues.apache.org/struts/browse/TILES-387
>             Project: Tiles
>          Issue Type: Bug
>          Components: tiles-api, tiles-servlet
>    Affects Versions: 2.1.2
>         Environment: Any
>            Reporter: Bjorn Harvold
>
> As of Tiles 2.1.1, the TilesConfigurer that was written by the Spring guys no longer works as they are using deprecated attributes in Tiles. They are working on a new tiles configurer for v3 of Spring. In the meantime, there have been some solutions submitted by the community. They work in a regular environment but not within an OSGi environment. 
> (see here for details on the issue raised: http://jira.springframework.org/browse/SPR-5411)
> The problem is this:
> public SpringTilesConfigurer() {
>         this.tilesPropertyMap.put(
>                 AbstractTilesApplicationContextFactory.APPLICATION_CONTEXT_FACTORY_INIT_PARAM,
>                 WildcardServletTilesApplicationContextFactory.class.getName());
>         this.tilesPropertyMap.put(
>                 TilesContainerFactory.PREPARER_FACTORY_INIT_PARAM,
>                 BasicPreparerFactory.class.getName());
>         this.tilesPropertyMap.put(
>                 DefinitionsFactory.LOCALE_RESOLVER_IMPL_PROPERTY,
>                 SpringLocaleResolver.class.getName());
>         this.tilesPropertyMap.put(TilesContainerFactory.ATTRIBUTE_EVALUATOR_INIT_PARAM, ELAttributeEvaluator.class.getName());
>         this.tilesPropertyMap.put(TilesContainerFactory.CONTAINER_FACTORY_MUTABLE_INIT_PARAM,
>                 Boolean.toString(false));
>     }
> protected TilesContainer createTilesContainer() throws TilesException {
>         ServletContextAdapter adaptedContext = new ServletContextAdapter(new DelegatingServletConfig());
>         TilesApplicationContext preliminaryContext = new ServletTilesApplicationContext(adaptedContext);
>         AbstractTilesApplicationContextFactory contextFactory = AbstractTilesApplicationContextFactory.createFactory(preliminaryContext);
>         this.tilesContext = contextFactory.createApplicationContext(adaptedContext);
>         AbstractTilesContainerFactory factory = AbstractTilesContainerFactory.getTilesContainerFactory(this.tilesContext);
>         return factory.createContainer(this.tilesContext);
>     } 
> When trying to create the context factory, it will try to initialize WildcardServletTilesApplicationContextFactory in AbstractTilesApplicationContextFactory:80 with the help of ClassUtil. Now WildcardServletTilesApplicationContextFactory is located in the tiles-servlet bundle while ClassUtil is located in tiles-api. Tiles-api does not have an import dependency on tiles-servlet (as it should be) so when ClassUtil tries to instantiate the class it cannot find it. This problem also occurs when trying to instantiate the TilesContainerFactory.
> Is there something the Tiles team needs to do in order to make this a work within OSGi or is the Spring community going at it the wrong way?
> Cheers
> bjorn

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


Re: [jira] Issue Comment Edited: (TILES-387) Creating a tilesConfigurer for Spring Web does not work in an OSGi environment

Posted by Antonio Petrelli <an...@gmail.com>.
You can see some sample code in the Tiles test webapp:
http://svn.eu.apache.org/repos/asf/tiles/framework/trunk/tiles-test/

See also:
http://tiles.apache.org/framework/tutorial/configuration.html#Startup_with_Java_code

Pure Java configuration does not use reflection to instantiate
objects, you need to create them yourself extending basic elements.
(e.g BasicTilesContainerFactory, TilesListener).

2009/4/2 Bjorn Harvold (JIRA) <ji...@apache.org>:
>
>    [ https://issues.apache.org/struts/browse/TILES-387?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45822#action_45822 ]
>
> Bjorn Harvold edited comment on TILES-387 at 4/1/09 10:44 PM:
> --------------------------------------------------------------
>
> I looked at the documentation for a pure Java configuration. I am not quite sure what to do in this case. Is there sample code for this? Regardless of which way we initialize Tiles, if there is a class loader in one bundle that tries to instantiate a class from another bundle and the former bundle doesn't have the latter bundle as part of its osgi imports, it won't work. I am going to fiddle around with the pure configuration in the mean time. If you have some sample code, that would be great.. or should I just extend the BasicTilesContainerFactory or the ServletTilesApplicationContextFactory?
>
> E.g.
> protected TilesContainer createTilesContainer() throws TilesException {
>        ServletContextAdapter adaptedContext = new ServletContextAdapter(new DelegatingServletConfig());
>        TilesApplicationContext preliminaryContext = new ServletTilesApplicationContext(adaptedContext);
>        AbstractTilesApplicationContextFactory contextFactory = MyServletTilesApplicationContextFactory.createFactory(preliminaryContext);
>        this.tilesContext = contextFactory.createApplicationContext(adaptedContext);
>        AbstractTilesContainerFactory factory = MyBasicTilesContainerFactory.getTilesContainerFactory(this.tilesContext);
>
>        return factory.createContainer(this.tilesContext);
>    }
>
> where both of my classes do nothing but extend. This will of course throw the same classnotfoundexception. Also if you just specify those classes in web.xml.
>
>      was (Author: bjornharvold):
>    I looked at the documentation for a pure Java configuration. I am not quite sure what to do in this case. Is there sample code for this? Regardless of which way we initialize Tiles, if there is a class loader in one bundle that tries to instantiate a class from another bundle and the former bundle doesn't have the latter bundle as part of its osgi imports, it won't work. I am going to fiddle around with the pure configuration in the mean time. If you have some sample code, that would be great.. or should I just extend the BasicTilesContainerFactory or the ServletTilesApplicationContextFactory?
>
>> Creating a tilesConfigurer for Spring Web does not work in an OSGi environment
>> ------------------------------------------------------------------------------
>>
>>                 Key: TILES-387
>>                 URL: https://issues.apache.org/struts/browse/TILES-387
>>             Project: Tiles
>>          Issue Type: Bug
>>          Components: tiles-api, tiles-servlet
>>    Affects Versions: 2.1.2
>>         Environment: Any
>>            Reporter: Bjorn Harvold
>>
>> As of Tiles 2.1.1, the TilesConfigurer that was written by the Spring guys no longer works as they are using deprecated attributes in Tiles. They are working on a new tiles configurer for v3 of Spring. In the meantime, there have been some solutions submitted by the community. They work in a regular environment but not within an OSGi environment.
>> (see here for details on the issue raised: http://jira.springframework.org/browse/SPR-5411)
>> The problem is this:
>> public SpringTilesConfigurer() {
>>         this.tilesPropertyMap.put(
>>                 AbstractTilesApplicationContextFactory.APPLICATION_CONTEXT_FACTORY_INIT_PARAM,
>>                 WildcardServletTilesApplicationContextFactory.class.getName());
>>         this.tilesPropertyMap.put(
>>                 TilesContainerFactory.PREPARER_FACTORY_INIT_PARAM,
>>                 BasicPreparerFactory.class.getName());
>>         this.tilesPropertyMap.put(
>>                 DefinitionsFactory.LOCALE_RESOLVER_IMPL_PROPERTY,
>>                 SpringLocaleResolver.class.getName());
>>         this.tilesPropertyMap.put(TilesContainerFactory.ATTRIBUTE_EVALUATOR_INIT_PARAM, ELAttributeEvaluator.class.getName());
>>         this.tilesPropertyMap.put(TilesContainerFactory.CONTAINER_FACTORY_MUTABLE_INIT_PARAM,
>>                 Boolean.toString(false));
>>     }
>> protected TilesContainer createTilesContainer() throws TilesException {
>>         ServletContextAdapter adaptedContext = new ServletContextAdapter(new DelegatingServletConfig());
>>         TilesApplicationContext preliminaryContext = new ServletTilesApplicationContext(adaptedContext);
>>         AbstractTilesApplicationContextFactory contextFactory = AbstractTilesApplicationContextFactory.createFactory(preliminaryContext);
>>         this.tilesContext = contextFactory.createApplicationContext(adaptedContext);
>>         AbstractTilesContainerFactory factory = AbstractTilesContainerFactory.getTilesContainerFactory(this.tilesContext);
>>         return factory.createContainer(this.tilesContext);
>>     }
>> When trying to create the context factory, it will try to initialize WildcardServletTilesApplicationContextFactory in AbstractTilesApplicationContextFactory:80 with the help of ClassUtil. Now WildcardServletTilesApplicationContextFactory is located in the tiles-servlet bundle while ClassUtil is located in tiles-api. Tiles-api does not have an import dependency on tiles-servlet (as it should be) so when ClassUtil tries to instantiate the class it cannot find it. This problem also occurs when trying to instantiate the TilesContainerFactory.
>> Is there something the Tiles team needs to do in order to make this a work within OSGi or is the Spring community going at it the wrong way?
>> Cheers
>> bjorn
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>