use of org.glassfish.jersey.server.ResourceFinder in project jersey by jersey.
the class CompositeResourceFinderTest method test.
@Test
public void test() {
final ResourceFinder i = new MyIterator();
final ResourceFinder j = new MyIterator();
final CompositeResourceFinder iteratorStack = new CompositeResourceFinder();
iteratorStack.push(i);
iteratorStack.push(j);
assertEquals(iteratorStack.next(), "value");
assertEquals(iteratorStack.next(), "value");
try {
iteratorStack.next();
assertTrue(false);
} catch (final NoSuchElementException nsee) {
assertTrue(true);
}
}
use of org.glassfish.jersey.server.ResourceFinder in project jersey by jersey.
the class VFSSchemeResourceFinderTest method testClassEnumeration.
/**
* Test case for JERSEY-2197, JERSEY-2175.
*/
@Test
public void testClassEnumeration() throws Exception {
// Count actual entries.
int actualEntries = 0;
try (JarFile jarFile = new JarFile(jaxRsApiPath)) {
final Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
final JarEntry entry = entries.nextElement();
if (entry.getName().endsWith(".class")) {
actualEntries++;
}
}
}
// Scan entries using VFS scanner.
final VirtualFile mountDir = VFS.getChild("content");
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
try (TempFileProvider provider = TempFileProvider.create("test", executor, false);
Closeable mount = VFS.mountZip(VFS.getChild(jaxRsApiPath), mountDir, provider)) {
ResourceFinder finder = new VfsSchemeResourceFinderFactory().create(new URI(mountDir.toURI().toString() + "/javax/ws/rs"), true);
int scannedEntryCount = 0;
while (finder.hasNext()) {
// Fetch next entry.
finder.next();
try (InputStream classStream = finder.open()) {
scannedEntryCount++;
}
}
assertThat("Failed to enumerate all contents of javax.ws.rs-api.", scannedEntryCount, equalTo(actualEntries));
} finally {
executor.shutdownNow();
}
}
use of org.glassfish.jersey.server.ResourceFinder in project jersey by jersey.
the class CompositeResourceFinder method close.
@Override
public void close() {
if (current != null) {
// Insert the currently processed resource finder at the top of the stack.
stack.addFirst(current);
current = null;
}
for (final ResourceFinder finder : stack) {
try {
finder.close();
} catch (final RuntimeException e) {
LOGGER.log(Level.CONFIG, LocalizationMessages.ERROR_CLOSING_FINDER(finder.getClass()), e);
}
}
stack.clear();
}
Aggregations