org.apache.openejb.tomcat.catalina.TomcatJndiSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openejb-tomcat-catalina Show documentation
Show all versions of openejb-tomcat-catalina Show documentation
This module contains the classes that will be added to the catalina class loader
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.openejb.tomcat.catalina;
import org.apache.openejb.OpenEJBException;
import org.apache.openejb.RpcContainer;
import org.apache.openejb.DeploymentInfo;
import org.apache.openejb.core.RpcContainerWrapper;
import org.apache.openejb.core.CoreDeploymentInfo;
import javax.naming.Context;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class TomcatJndiSupport extends RpcContainerWrapper {
private final Method bindContext;
private final Method bindThread;
private final Method unbindThread;
public TomcatJndiSupport(RpcContainer container) throws OpenEJBException {
super(container);
try {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Class contextBindings = classLoader.loadClass("org.apache.naming.ContextBindings");
bindContext = contextBindings.getMethod("bindContext", Object.class, Context.class, Object.class);
bindThread = contextBindings.getMethod("bindThread", Object.class, Object.class);
unbindThread = contextBindings.getMethod("unbindThread", Object.class, Object.class);
} catch (ClassNotFoundException e) {
throw new OpenEJBException("Unable to setup Tomcat JNDI support. Support requires the org.apache.naming.ContextBindings class to be available.");
} catch (NoSuchMethodException e) {
throw new OpenEJBException("Unable to setup Tomcat JNDI support. Method of org.apache.naming.ContextBindings was not found:" + e.getMessage());
}
DeploymentInfo[] deploymentInfos = container.deployments();
for (DeploymentInfo deploymentInfo : deploymentInfos) {
CoreDeploymentInfo deployment = (CoreDeploymentInfo) deploymentInfo;
setupDeployment(deployment);
}
}
@SuppressWarnings({"UnusedDeclaration"})
public void init(Object containerId, HashMap deployments, Properties properties) throws OpenEJBException {
}
public void deploy(DeploymentInfo info) throws OpenEJBException {
super.deploy(info);
setupDeployment((org.apache.openejb.core.CoreDeploymentInfo) info);
}
public static Map