Search in sources :

Example 1 with ResourceFinder

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);
    }
}
Also used : ResourceFinder(org.glassfish.jersey.server.ResourceFinder) NoSuchElementException(java.util.NoSuchElementException) Test(org.junit.Test)

Example 2 with ResourceFinder

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();
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceFinder(org.glassfish.jersey.server.ResourceFinder) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) InputStream(java.io.InputStream) Closeable(java.io.Closeable) TempFileProvider(org.jboss.vfs.TempFileProvider) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) URI(java.net.URI) Test(org.junit.Test)

Example 3 with ResourceFinder

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();
}
Also used : ResourceFinder(org.glassfish.jersey.server.ResourceFinder)

Aggregations

ResourceFinder (org.glassfish.jersey.server.ResourceFinder)3 Test (org.junit.Test)2 Closeable (java.io.Closeable)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 NoSuchElementException (java.util.NoSuchElementException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1 TempFileProvider (org.jboss.vfs.TempFileProvider)1 VirtualFile (org.jboss.vfs.VirtualFile)1