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);
}
}
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;
}
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));
}
}
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);
}
}
}
}
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));
}
}
Aggregations