dev@javaserverfaces.java.net

RE: Re: Extending JSF Classloader

From: Freire, Jose Luis (PT - Lisbon) <"Freire,>
Date: Mon, 25 Jun 2007 20:36:52 +0100

Hello Imre,

Thank you very much for your answer. I've taken your solution one step further. Instead of building a filter, I've build a PhaseListener and added my classloader like this:

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

public class ClassLoaderPhaseListener implements PhaseListener {

        private static final Log logger = LogFactory.getLog(ClassLoaderPhaseListener.class);

        private static final long serialVersionUID = 1L;

        public void beforePhase(PhaseEvent arg0) {
                logger.info("Setting classloader for this thread");
                logger.info("Current Classloader:" + contextClassLoader.getClass().getName());
                ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
                Thread.currentThread().setContextClassLoader(new MyClassLoader(contextClassLoader));
        }

        public void afterPhase(PhaseEvent arg0) {
                // Do Nothing
        }

        public PhaseId getPhaseId() {
                return PhaseId.RESTORE_VIEW;
        }

}

It works great! Now I only need to build my classloader to search OSGI plugins to find my classes.

I'm aware this is only a workaround to make an OSGI application running on JSF, and would appreciate if anyone could give me some pointers to do this correctly.

Is anyone making any work towards JSF OSGI?

Thanks,

José

________________________________________
From: Imre Oßwald [mailto:io_at_mx.jevelopers.com]
Sent: segunda-feira, 25 de Junho de 2007 14:26
To: dev_at_javaserverfaces.dev.java.net
Subject: Re: Extending JSF Classloader

Hello Jose,

while I was experimenting with classloaders in JSF, I had success with Thread.get / setContextClassloader.
The Problem will then be to get hold of every Thread before JSF loads classes. I wrote a Filter to wrap the Classloader of every requests Thread and a ContextListener for the startup of the webapp.

I hope there are better ways to do it, so I am too interested if someone else has a better approach.

(Apart from that probably most appserver have (a non portable) way to define classloaders.

Imre Oßwald


On 25.06.2007, at 13:20, Freire, Jose Luis ((PT - Lisbon)) wrote:


I'm doing some experimental work to run JSF in an OSGI environment and I'm trying a new approach since I'm finding that it's very hard to make JSF a OSGI Bundle, so I'm going for smaller steps.
 
What is the best way to extend JSF classloader (if one exists...) ?
 
José Freire
Consulting - Financial Services Industry
Deloitte & Touche, Quality Firm, S.A.


Main:    +(351) 21 042 25 00
Fax:      +(351) 21 042 29 50
jfreire_at_deloitte.pt
www.deloitte.com/pt

Deloitte
Edifício Atrium Saldanha
Praça Duque de Saldanha, 1 - 7º
1050-094 Lisboa
Portugal
 
 
*Disclaimer:*
Deloitte refers to one or more of Deloitte Touche Tohmatsu, a Swiss Verein, its member firms, and their respective subsidiaries and affiliates.  As a Swiss Verein (association), neither Deloitte Touche Tohmatsu nor any of its member firms has any liability for each other's acts or omissions.  Each of the member firms is a separate and independent legal entity operating under the names "Deloitte," "Deloitte & Touche," "Deloitte Touche Tohmatsu," or other related names.  Services are provided by the member firms or their subsidiaries or affiliates and not by the Deloitte Touche Tohmatsu Verein.
Privileged/Confidential Information may be contained in this message. If you are not the addressee indicated in this message (or responsible for delivery of the message to such person), you may not copy or deliver this message to anyone. In such case, you should destroy this message and kindly notify the sender by reply email. Please advise immediately if you or your employer do not consent to Internet email for messages of this kind. Opinions, conclusions and other information in this message that do not relate to the official business of my firm shall be understood as neither given nor endorsed by it.