Search in sources :

Example 46 with NamingException

use of javax.naming.NamingException in project tomcat by apache.

the class ApplicationContext method createServlet.

@Override
public <T extends Servlet> T createServlet(Class<T> c) throws ServletException {
    try {
        @SuppressWarnings("unchecked") T servlet = (T) context.getInstanceManager().newInstance(c.getName());
        context.dynamicServletCreated(servlet);
        return servlet;
    } catch (InvocationTargetException e) {
        ExceptionUtils.handleThrowable(e.getCause());
        throw new ServletException(e);
    } catch (IllegalAccessException | NamingException | InstantiationException | ClassNotFoundException e) {
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) NamingException(javax.naming.NamingException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 47 with NamingException

use of javax.naming.NamingException in project tomcat by apache.

the class AsyncContextImpl method createListener.

@SuppressWarnings("unchecked")
@Override
public <T extends AsyncListener> T createListener(Class<T> clazz) throws ServletException {
    check();
    T listener = null;
    try {
        listener = (T) getInstanceManager().newInstance(clazz.getName(), clazz.getClassLoader());
    } catch (InstantiationException | IllegalAccessException | NamingException | ClassNotFoundException e) {
        ServletException se = new ServletException(e);
        throw se;
    } catch (Exception e) {
        ExceptionUtils.handleThrowable(e.getCause());
        ServletException se = new ServletException(e);
        throw se;
    }
    return listener;
}
Also used : ServletException(javax.servlet.ServletException) NamingException(javax.naming.NamingException) ServletException(javax.servlet.ServletException) NamingException(javax.naming.NamingException) IOException(java.io.IOException)

Example 48 with NamingException

use of javax.naming.NamingException in project tomcat by apache.

the class NamingContextListener method addResourceEnvRef.

/**
     * Set the specified resources in the naming context.
     *
     * @param resourceEnvRef the resource reference
     */
public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {
    // Create a reference to the resource env.
    Reference ref = new ResourceEnvRef(resourceEnvRef.getType());
    // Adding the additional parameters, if any
    Iterator<String> params = resourceEnvRef.listProperties();
    while (params.hasNext()) {
        String paramName = params.next();
        String paramValue = (String) resourceEnvRef.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        if (log.isDebugEnabled())
            log.debug("  Adding resource env ref " + resourceEnvRef.getName());
        createSubcontexts(envCtx, resourceEnvRef.getName());
        envCtx.bind(resourceEnvRef.getName(), ref);
    } catch (NamingException e) {
        log.error(sm.getString("naming.bindFailed", e));
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) NamingException(javax.naming.NamingException) ResourceEnvRef(org.apache.naming.ResourceEnvRef) ContextResourceEnvRef(org.apache.tomcat.util.descriptor.web.ContextResourceEnvRef)

Example 49 with NamingException

use of javax.naming.NamingException in project tomcat by apache.

the class NamingContextListener method createSubcontexts.

/**
     * Create all intermediate subcontexts.
     */
private void createSubcontexts(javax.naming.Context ctx, String name) throws NamingException {
    javax.naming.Context currentContext = ctx;
    StringTokenizer tokenizer = new StringTokenizer(name, "/");
    while (tokenizer.hasMoreTokens()) {
        String token = tokenizer.nextToken();
        if ((!token.equals("")) && (tokenizer.hasMoreTokens())) {
            try {
                currentContext = currentContext.createSubcontext(token);
            } catch (NamingException e) {
                // Silent catch. Probably an object is already bound in
                // the context.
                currentContext = (javax.naming.Context) currentContext.lookup(token);
            }
        }
    }
}
Also used : NamingContext(org.apache.naming.NamingContext) Context(org.apache.catalina.Context) StringTokenizer(java.util.StringTokenizer) NamingException(javax.naming.NamingException)

Example 50 with NamingException

use of javax.naming.NamingException in project tomcat by apache.

the class NamingContextListener method addEjb.

/**
     * Set the specified EJBs in the naming context.
     *
     * @param ejb the EJB descriptor
     */
public void addEjb(ContextEjb ejb) {
    // Create a reference to the EJB.
    Reference ref = new EjbRef(ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
    // Adding the additional parameters, if any
    Iterator<String> params = ejb.listProperties();
    while (params.hasNext()) {
        String paramName = params.next();
        String paramValue = (String) ejb.getProperty(paramName);
        StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
        ref.add(refAddr);
    }
    try {
        createSubcontexts(envCtx, ejb.getName());
        envCtx.bind(ejb.getName(), ref);
    } catch (NamingException e) {
        log.error(sm.getString("naming.bindFailed", e));
    }
}
Also used : StringRefAddr(javax.naming.StringRefAddr) Reference(javax.naming.Reference) EjbRef(org.apache.naming.EjbRef) NamingException(javax.naming.NamingException)

Aggregations

NamingException (javax.naming.NamingException)698 InitialContext (javax.naming.InitialContext)234 Context (javax.naming.Context)169 IOException (java.io.IOException)82 NameNotFoundException (javax.naming.NameNotFoundException)67 SQLException (java.sql.SQLException)58 Reference (javax.naming.Reference)53 DataSource (javax.sql.DataSource)52 Test (org.junit.Test)51 Attribute (javax.naming.directory.Attribute)49 DirContext (javax.naming.directory.DirContext)48 Properties (java.util.Properties)45 ArrayList (java.util.ArrayList)41 Name (javax.naming.Name)36 SearchResult (javax.naming.directory.SearchResult)35 Hashtable (java.util.Hashtable)34 InitialDirContext (javax.naming.directory.InitialDirContext)34 Connection (java.sql.Connection)33 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)32 Attributes (javax.naming.directory.Attributes)30