Search in sources :

Example 1 with ClassLoaderManager

use of org.xwiki.classloader.ClassLoaderManager in project xwiki-platform by xwiki.

the class WebJarsResourceReferenceHandlerTest method configure.

@Before
public void configure() throws Exception {
    Container container = this.componentManager.getInstance(Container.class);
    this.response = mock(ServletResponse.class);
    ByteArrayOutputStream responseOutputStream = new ByteArrayOutputStream();
    when(this.response.getOutputStream()).thenReturn(responseOutputStream);
    HttpServletResponse httpResponse = mock(HttpServletResponse.class);
    when(this.response.getHttpServletResponse()).thenReturn(httpResponse);
    when(container.getResponse()).thenReturn(this.response);
    this.request = mock(ServletRequest.class);
    HttpServletRequest httpRequest = mock(HttpServletRequest.class);
    when(this.request.getHttpServletRequest()).thenReturn(httpRequest);
    when(container.getRequest()).thenReturn(this.request);
    this.handler = this.componentManager.getComponentUnderTest();
    this.classLoader = mock(NamespaceURLClassLoader.class);
    ClassLoaderManager clm = this.componentManager.getInstance(ClassLoaderManager.class);
    when(clm.getURLClassLoader("wiki:wiki", true)).thenReturn(this.classLoader);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletResponse(org.xwiki.container.servlet.ServletResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(org.xwiki.container.servlet.ServletRequest) Container(org.xwiki.container.Container) NamespaceURLClassLoader(org.xwiki.classloader.NamespaceURLClassLoader) HttpServletResponse(javax.servlet.http.HttpServletResponse) ClassLoaderManager(org.xwiki.classloader.ClassLoaderManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Before(org.junit.Before)

Example 2 with ClassLoaderManager

use of org.xwiki.classloader.ClassLoaderManager in project xwiki-platform by xwiki.

the class XWiki method getAuthService.

// added some log statements to make debugging easier - LBlaze 2005.06.02
public XWikiAuthService getAuthService() {
    synchronized (this.AUTH_SERVICE_LOCK) {
        if (this.authService == null) {
            LOGGER.info("Initializing AuthService...");
            String authClass = getConfiguration().getProperty("xwiki.authentication.authclass");
            if (StringUtils.isNotEmpty(authClass)) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Using custom AuthClass " + authClass + ".");
                }
            } else {
                if (isLDAP()) {
                    authClass = "com.xpn.xwiki.user.impl.LDAP.XWikiLDAPAuthServiceImpl";
                } else {
                    authClass = "com.xpn.xwiki.user.impl.xwiki.XWikiAuthServiceImpl";
                }
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Using default AuthClass " + authClass + ".");
                }
            }
            try {
                // Get the current ClassLoader
                @SuppressWarnings("deprecation") ClassLoaderManager clManager = Utils.getComponent(ClassLoaderManager.class);
                ClassLoader classloader = null;
                if (clManager != null) {
                    classloader = clManager.getURLClassLoader("wiki:xwiki", false);
                }
                // Get the class
                if (classloader != null) {
                    this.authService = (XWikiAuthService) Class.forName(authClass, true, classloader).newInstance();
                } else {
                    this.authService = (XWikiAuthService) Class.forName(authClass).newInstance();
                }
                LOGGER.debug("Initialized AuthService using Relfection.");
            } catch (Exception e) {
                LOGGER.warn("Failed to initialize AuthService " + authClass + " using Reflection, trying default implementations using 'new'.", e);
                this.authService = new XWikiAuthServiceImpl();
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Initialized AuthService " + this.authService.getClass().getName() + " using 'new'.");
                }
            }
        }
        return this.authService;
    }
}
Also used : XWikiAuthServiceImpl(com.xpn.xwiki.user.impl.xwiki.XWikiAuthServiceImpl) ClassLoaderManager(org.xwiki.classloader.ClassLoaderManager) XWikiPageClassLoader(com.xpn.xwiki.render.groovy.XWikiPageClassLoader) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) ParseException(org.xwiki.rendering.parser.ParseException) QueryException(org.xwiki.query.QueryException) URIException(org.apache.commons.httpclient.URIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException)

Aggregations

ClassLoaderManager (org.xwiki.classloader.ClassLoaderManager)2 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)1 XWikiPageClassLoader (com.xpn.xwiki.render.groovy.XWikiPageClassLoader)1 XWikiAuthServiceImpl (com.xpn.xwiki.user.impl.xwiki.XWikiAuthServiceImpl)1 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 NamingException (javax.naming.NamingException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 URIException (org.apache.commons.httpclient.URIException)1 HibernateException (org.hibernate.HibernateException)1 Before (org.junit.Before)1 NamespaceURLClassLoader (org.xwiki.classloader.NamespaceURLClassLoader)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 Container (org.xwiki.container.Container)1 ServletRequest (org.xwiki.container.servlet.ServletRequest)1