use of org.apache.tomee.catalina.TomEERuntimeException in project tomee by apache.
the class LazyValve method instance.
private Valve instance() {
if (delegate == null) {
synchronized (this) {
if (delegate == null) {
final Object instance;
ClassLoader cl = loader();
if (cl == null) {
return null;
}
final Class<?> clazz;
try {
clazz = cl.loadClass(delegateClassName);
} catch (final ClassNotFoundException e) {
throw new TomEERuntimeException(e);
}
try {
final ObjectRecipe recipe = new ObjectRecipe(clazz);
recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
recipe.allow(Option.FIELD_INJECTION);
recipe.allow(Option.PRIVATE_PROPERTIES);
if (properties != null) {
final Properties props = new PropertiesAdapter().unmarshal(properties.trim().replaceAll("\\p{Space}*(\\p{Alnum}*)=", "\n$1="));
recipe.setAllProperties(props);
}
instance = recipe.create();
} catch (final Exception e) {
throw new TomEERuntimeException(e);
}
delegate = Valve.class.cast(instance);
delegate.setNext(next);
if (Contained.class.isInstance(delegate)) {
Contained.class.cast(delegate).setContainer(container);
}
if (Lifecycle.class.isInstance(delegate)) {
if (init) {
try {
final Lifecycle lifecycle = Lifecycle.class.cast(delegate);
for (final LifecycleListener listener : lifecycleListeners) {
lifecycle.addLifecycleListener(listener);
}
lifecycle.init();
if (start) {
lifecycle.start();
}
} catch (final LifecycleException e) {
// no-op
}
}
}
if (ClusterValve.class.isInstance(delegate)) {
ClusterValve.class.cast(delegate).setCluster(cluster);
}
}
}
}
return delegate;
}
use of org.apache.tomee.catalina.TomEERuntimeException in project tomee by apache.
the class EmbeddedTomEEContainer method close.
@Override
public void close() {
final Collection<Exception> errors = new ArrayList<>();
final EmbeddedTomEEContainer etc = tomEEContainer.get();
if (null != etc) {
for (final String id : deployedIds) {
if (etc.container.getAppContexts(id) != null) {
try {
etc.container.undeploy(id);
} catch (final Exception ex) {
Logger.getInstance(LogCategory.OPENEJB, EmbeddedTomEEContainer.class).error(ex.getMessage(), ex);
errors.add(ex);
}
}
}
try {
etc.container.close();
} catch (final Exception ex) {
errors.add(ex);
Logger.getInstance(LogCategory.OPENEJB, EmbeddedTomEEContainer.class).error(ex.getMessage(), ex);
}
}
deployedIds.clear();
tomEEContainer.set(null);
if (!errors.isEmpty()) {
throw Exceptions.newEJBException(new TomEERuntimeException(errors.toString()));
}
}
use of org.apache.tomee.catalina.TomEERuntimeException in project tomee by apache.
the class Container method getBaseDir.
private String getBaseDir() {
File file;
try {
final String dir = configuration.getDir();
if (dir != null) {
final File dirFile = new File(dir);
if (dirFile.exists()) {
return dir;
}
return Files.mkdir(dirFile).getAbsolutePath();
}
try {
final File target = new File("target");
file = File.createTempFile("apache-tomee", "-home", target.exists() ? target : null);
} catch (final Exception e) {
final File tmp = new File(configuration.getTempDir());
if (!tmp.exists() && !tmp.mkdirs()) {
throw new IOException("Failed to create local tmp directory: " + tmp.getAbsolutePath());
}
file = File.createTempFile("apache-tomee", "-home", tmp);
}
return file.getAbsolutePath();
} catch (final IOException e) {
throw new TomEERuntimeException("Failed to get or create base dir: " + configuration.getDir(), e);
}
}
use of org.apache.tomee.catalina.TomEERuntimeException in project tomee by apache.
the class LazyRealm method instance.
private Realm instance() {
if (delegate == null) {
synchronized (this) {
if (delegate == null) {
final Object instance;
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (container != null && container.getLoader() != null && container.getLoader().getClassLoader() != null) {
cl = container.getLoader().getClassLoader();
}
final Class<?> clazz;
try {
clazz = cl.loadClass(realmClass);
} catch (final ClassNotFoundException e) {
throw new TomEERuntimeException(e);
}
if (!cdi) {
try {
final ObjectRecipe recipe = new ObjectRecipe(clazz);
recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
recipe.allow(Option.FIELD_INJECTION);
recipe.allow(Option.PRIVATE_PROPERTIES);
if (properties != null) {
final Properties props = new PropertiesAdapter().unmarshal(properties.trim().replaceAll("\\p{Space}*(\\p{Alnum}*)=", "\n$1="));
recipe.setAllProperties(props);
}
instance = recipe.create();
} catch (final Exception e) {
throw new TomEERuntimeException(e);
}
} else {
final WebBeansContext webBeansContext;
try {
webBeansContext = WebBeansContext.currentInstance();
if (webBeansContext == null) {
return null;
}
} catch (final IllegalStateException ise) {
// too early to have a cdi bean, skip these methods - mainly init() but @PostConstruct works then
return null;
}
final BeanManager bm = webBeansContext.getBeanManagerImpl();
final Set<Bean<?>> beans = bm.getBeans(clazz);
final Bean<?> bean = bm.resolve(beans);
if (bean == null) {
return null;
}
creationalContext = bm.createCreationalContext(null);
instance = bm.getReference(bean, clazz, creationalContext);
}
if (instance == null) {
throw new TomEERuntimeException("realm can't be retrieved from cdi");
}
if (instance instanceof Realm) {
delegate = (Realm) instance;
delegate.setContainer(container);
delegate.setCredentialHandler(credentialHandler);
if (Lifecycle.class.isInstance(delegate)) {
if (init) {
try {
final Lifecycle lifecycle = Lifecycle.class.cast(delegate);
lifecycle.init();
if (start) {
lifecycle.start();
}
} catch (final LifecycleException e) {
// no-op
}
}
}
} else {
delegate = new LowTypedRealm(instance);
delegate.setContainer(container);
delegate.setCredentialHandler(credentialHandler);
}
for (final PropertyChangeListener listener : support.getPropertyChangeListeners()) {
delegate.addPropertyChangeListener(listener);
}
}
}
}
return delegate;
}
use of org.apache.tomee.catalina.TomEERuntimeException in project tomee by apache.
the class TomcatWsRegistry method removeWsContainer.
@Override
public void removeWsContainer(String path, final String moduleId) {
if (path == null) {
return;
}
// assure context root with a leading slash
path = Strings.slashify(path);
if (TomcatHelper.isStopping()) {
return;
}
Context context = webserviceContexts.remove(new Key(path, moduleId));
if (context == null) {
// fake
context = webserviceContexts.remove(new Key(path, null));
}
// > 0 to avoid to destroy the context if not mandatory
Integer refs = 1;
if (context != null) {
final String name = context.getName();
refs = fakeContextReferences.remove(name);
if (refs != null && refs > 0) {
fakeContextReferences.put(name, refs - 1);
}
}
if ((WEBSERVICE_OLDCONTEXT_ACTIVE || (refs != null && refs == 0)) && context != null) {
try {
context.stop();
context.destroy();
} catch (final Exception e) {
throw new TomEERuntimeException(e);
}
final Host host = (Host) context.getParent();
host.removeChild(context);
}
// else let tomcat manages its context
}
Aggregations