use of javax.naming.Binding in project Payara by payara.
the class WebappClassLoader method modified.
/**
* Have one or more classes or resources been modified so that a reload
* is appropriate?
*/
@Override
public boolean modified() {
if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER, "modified()");
}
// Checking for modified loaded resources
int pathsLength = paths.length;
// A rare race condition can occur in the updates of the two arrays
// It's totally ok if the latest class added is not checked (it will
// be checked the next time
int lastModifiedDatesLength = lastModifiedDates.length;
if (pathsLength > lastModifiedDatesLength) {
pathsLength = lastModifiedDatesLength;
}
for (int i = 0; i < pathsLength; i++) {
try {
long lastModified = ((ResourceAttributes) resources.getAttributes(paths[i])).getLastModified();
if (lastModified != lastModifiedDates[i]) {
if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER, " Resource ''{0}'' was modified; Date is now: {1} Was: {2}", new Object[] { paths[i], new java.util.Date(lastModified), new java.util.Date(lastModifiedDates[i]) });
}
return true;
}
} catch (NamingException e) {
logger.log(Level.SEVERE, LogFacade.MISSING_RESOURCE, paths[i]);
return true;
}
}
pathsLength = jarNames.size();
// Check if JARs have been added or removed
if (getJarPath() != null) {
try {
NamingEnumeration<Binding> enumeration = resources.listBindings(getJarPath());
int i = 0;
while (enumeration.hasMoreElements() && (i < pathsLength)) {
NameClassPair ncPair = enumeration.nextElement();
String name = ncPair.getName();
// START OF IASRI 4657979
if (!name.endsWith(".jar") && !name.endsWith(".zip")) {
// END OF IASRI 4657979
continue;
}
if (!name.equals(jarNames.get(i))) {
// Missing JAR
logger.log(Level.FINER, " Additional JARs have been added : ''{0}''", name);
return true;
}
i++;
}
if (enumeration.hasMoreElements()) {
while (enumeration.hasMoreElements()) {
NameClassPair ncPair = enumeration.nextElement();
String name = ncPair.getName();
// START OF IASRI 4657979
if (name.endsWith(".jar") || name.endsWith(".zip")) {
// END OF IASRI 4657979
// There was more JARs
logger.log(Level.FINER, " Additional JARs have been added");
return true;
}
}
} else if (i < jarNames.size()) {
// There was less JARs
logger.log(Level.FINER, " Additional JARs have been added");
return true;
}
} catch (NamingException e) {
if (logger.isLoggable(Level.FINER)) {
logger.log(Level.FINER, " Failed tracking modifications of ''{0}''", getJarPath());
}
} catch (ClassCastException e) {
logger.log(Level.SEVERE, LogFacade.FAILED_TRACKING_MODIFICATIONS, new Object[] { getJarPath(), e.getMessage() });
}
}
// No classes have been modified
return false;
}
use of javax.naming.Binding in project Payara by payara.
the class WebappLoader method setRepositories.
/**
* Configure the repositories for our class loader, based on the
* associated Context.
*/
private void setRepositories() throws IOException {
if (!(container instanceof Context))
return;
ServletContext servletContext = ((Context) container).getServletContext();
if (servletContext == null)
return;
// Loading the work directory
File workDir = (File) servletContext.getAttribute(ServletContext.TEMPDIR);
if (workDir == null) {
if (log.isLoggable(Level.INFO)) {
log.log(Level.INFO, LogFacade.NO_WORK_DIR_INFO, servletContext);
}
}
if (log.isLoggable(Level.FINEST) && workDir != null)
log.log(Level.FINEST, "Deploying class repositories to work directory{0}", workDir.getAbsolutePath());
DirContext resources = container.getResources();
// Setting up the class repository (/WEB-INF/classes), if it exists
String classesPath = "/WEB-INF/classes";
DirContext classes = null;
try {
Object object = resources.lookup(classesPath);
if (object instanceof DirContext) {
classes = (DirContext) object;
}
} catch (NamingException e) {
// Silent catch: it's valid that no /WEB-INF/classes collection
// exists
}
if (classes != null) {
File classRepository = null;
String absoluteClassesPath = servletContext.getRealPath(classesPath);
if (absoluteClassesPath != null) {
classRepository = new File(absoluteClassesPath);
} else {
classRepository = new File(workDir, classesPath);
if (!classRepository.mkdirs() && !classRepository.isDirectory()) {
throw new IOException(rb.getString(LogFacade.FAILED_CREATE_DEST_DIR));
}
if (!copyDir(classes, classRepository)) {
throw new IOException(rb.getString(LogFacade.FAILED_COPY_RESOURCE));
}
}
if (log.isLoggable(Level.FINEST))
log.log(Level.FINEST, "Deploy class files {0} to {1}", new Object[] { classesPath, classRepository.getAbsolutePath() });
}
// Setting up the JAR repository (/WEB-INF/lib), if it exists
String libPath = "/WEB-INF/lib";
classLoader.setJarPath(libPath);
DirContext libDir = null;
// Looking up directory /WEB-INF/lib in the context
try {
Object object = resources.lookup(libPath);
if (object instanceof DirContext)
libDir = (DirContext) object;
} catch (NamingException e) {
// Silent catch: it's valid that no /WEB-INF/lib collection
// exists
}
if (libDir != null) {
boolean copyJars = false;
String absoluteLibPath = servletContext.getRealPath(libPath);
File destDir = null;
if (absoluteLibPath != null) {
destDir = new File(absoluteLibPath);
} else {
copyJars = true;
destDir = new File(workDir, libPath);
if (!destDir.mkdirs() && !destDir.isDirectory()) {
log.log(Level.SEVERE, LogFacade.FAILED_CREATE_WORK_DIR_EXCEPTION, destDir.getAbsolutePath());
}
}
if (!copyJars) {
return;
}
// Looking up directory /WEB-INF/lib in the context
try {
NamingEnumeration<Binding> enumeration = resources.listBindings(libPath);
while (enumeration.hasMoreElements()) {
Binding binding = enumeration.nextElement();
String filename = libPath + "/" + binding.getName();
// START OF IASRI 4657979
if (!filename.endsWith(".jar") && !filename.endsWith(".zip"))
// END OF IASRI 4657979
continue;
// START PWC 1.1 6314481
if (binding.getName() != null && binding.getName().startsWith(".") && ignoreHiddenJarFiles) {
continue;
}
// END PWC 1.1 6314481
File destFile = new File(destDir, binding.getName());
if (log.isLoggable(Level.FINEST)) {
log.log(Level.FINEST, "Deploy JAR {0} to {1}", new Object[] { filename, destFile.getAbsolutePath() });
}
Object obj = binding.getObject();
if (!(obj instanceof Resource))
continue;
Resource jarResource = (Resource) obj;
try (FileOutputStream fos = new FileOutputStream(destFile)) {
if (!copy(jarResource.streamContent(), fos)) {
continue;
}
}
}
} catch (NamingException e) {
// Silent catch: it's valid that no /WEB-INF/lib directory
// exists
} catch (IOException e) {
log("Unable to configure repositories", e);
}
}
}
use of javax.naming.Binding in project Payara by payara.
the class NamingContextBindingsEnumeration method nextElementInternal.
private Binding nextElementInternal() throws NamingException {
NamingEntry entry = iterator.next();
Object value;
// If the entry is a reference, resolve it
if (entry.type == NamingEntry.REFERENCE || entry.type == NamingEntry.LINK_REF) {
try {
value = ctx.lookup(new CompositeName(entry.name));
} catch (NamingException e) {
throw e;
} catch (Exception e) {
NamingException ne = new NamingException(e.getMessage());
ne.initCause(e);
throw ne;
}
} else {
value = entry.value;
}
return new Binding(entry.name, value.getClass().getName(), value, true);
}
use of javax.naming.Binding in project keycloak by keycloak.
the class LDAPOperationManager method destroySubcontext.
/**
* <p>
* Destroys a subcontext with the given DN from the LDAP tree.
* </p>
*
* @param dn
*/
private void destroySubcontext(LdapContext context, final String dn) {
try {
NamingEnumeration<Binding> enumeration = null;
try {
enumeration = context.listBindings(new LdapName(dn));
while (enumeration.hasMore()) {
Binding binding = enumeration.next();
String name = binding.getNameInNamespace();
destroySubcontext(context, name);
}
context.unbind(new LdapName(dn));
} finally {
try {
enumeration.close();
} catch (Exception e) {
}
}
} catch (Exception e) {
throw new ModelException("Could not unbind DN [" + dn + "]", e);
}
}
use of javax.naming.Binding in project wildfly by wildfly.
the class ServiceBasedNamingStore method listBindings.
public List<Binding> listBindings(final Name name) throws NamingException {
final ServiceName lookupName = buildServiceName(name);
final ServiceName floor = boundServices.floor(lookupName);
boolean isContextBinding = false;
if (floor != null && floor.isParentOf(lookupName)) {
// Parent might be a reference or a link
Object obj = lookup(name.toString(), floor, true);
if (obj instanceof NamingContext) {
isContextBinding = true;
} else if (obj != null) {
throw new RequireResolveException(convert(floor));
}
}
final List<ServiceName> children = listChildren(lookupName, isContextBinding);
final String[] lookupParts = lookupName.toArray();
final Set<String> childContexts = new HashSet<String>();
final List<Binding> results = new ArrayList<Binding>();
for (ServiceName child : children) {
final String[] childParts = child.toArray();
if (childParts.length > lookupParts.length + 1) {
childContexts.add(childParts[lookupParts.length]);
} else {
final Object binding = lookup(name.toString(), child, true);
results.add(new Binding(childParts[childParts.length - 1], binding));
}
}
for (String contextName : childContexts) {
results.add(new Binding(contextName, new NamingContext(((Name) name.clone()).add(contextName), this, null)));
}
return results;
}
Aggregations