Package org.dspace.kernel

Examples of org.dspace.kernel.DSpaceKernelManager


     * @throws IllegalStateException if the Kernel cannot be created
     */
    public static DSpaceKernelImpl getKernel(String name) {
        if (name != null) {
            try {
                DSpaceKernel kernel = new DSpaceKernelManager().getKernel(name);
                if (kernel != null) {
                    if (kernel instanceof DSpaceKernelImpl) {
                        return (DSpaceKernelImpl)kernel;
                    }

View Full Code Here


     *
     * @param kernelName the name of the kernel to use (null to use the default kernel)
     * @throws IllegalStateException if the kernel is not already running or no kernel exists with this name
     */
    public DSpace(String kernelName) {
        DSpaceKernel kernel = new DSpaceKernelManager().getKernel(kernelName);
        this.kernel = kernel;
    }
View Full Code Here

    /**
     * @return the current DSpace kernel or fail
     */
    public DSpaceKernel getKernel() {
        DSpaceKernel kernel = new DSpaceKernelManager().getKernel();
        if (! kernel.isRunning()) {
            throw new IllegalStateException("The DSpace kernel is not running: " + kernel);
        }
        return kernel;
    }
View Full Code Here

            assertNotNull(e.getMessage());
        }

        DSpaceKernelImpl kernelImpl = DSpaceKernelInit.getKernel(null);
        kernelImpl.start(); // triggers the init
        DSpaceKernel kernel = new DSpaceKernelManager().getKernel();
        assertNotNull(kernel);
        assertEquals(kernel, kernelImpl);

        DSpace dspace = new DSpace();
        Object o = dspace.getServiceManager();
        assertNotNull(o);
        assertEquals(o, kernel.getServiceManager());

        // repeat a few times
        o = dspace.getServiceManager();
        assertNotNull(o);
        assertEquals(o, kernel.getServiceManager());

        o = dspace.getServiceManager();
        assertNotNull(o);
        assertEquals(o, kernel.getServiceManager());

        DSpace dspace2 = new DSpace();
        assertNotNull(dspace2.getServiceManager());
        assertEquals(dspace.getServiceManager(), dspace2.getServiceManager());

        // REPEAT
        kernel = new DSpaceKernelManager().getKernel();

        o = dspace.getServiceManager();
        assertNotNull(o);
        assertEquals(o, kernel.getServiceManager());
View Full Code Here

    @Before
    public void init() {
        kernelImpl = DSpaceKernelInit.getKernel(null);
        kernelImpl.start(); // init the kernel
        kernelManager = new DSpaceKernelManager();
    }
View Full Code Here

    @Override
    public void init() throws ServletException {
        super.init();
        try {
            DSpaceKernel kernel = new DSpaceKernelManager().getKernel();
            if (kernel == null) {
                throw new IllegalStateException("Could not get the DSpace Kernel");
            }
            if (! kernel.isRunning()) {
                throw new IllegalStateException("DSpace Kernel is not running, cannot startup the DirectServlet");
View Full Code Here

    @Test
    public void testSampleRequest() {
        // make sure no kernel yet
        try {
            new DSpaceKernelManager().getKernel();
            fail("Should have thrown exception");
        } catch (IllegalStateException e) {
            assertNotNull(e.getMessage());
        }

        ServletTester tester = new ServletTester();
        tester.setContextPath("/");
        tester.getContext().addEventListener(new DSpaceKernelServletContextListener());
        tester.addFilter(DSpaceWebappServletFilter.class, "/*", Handler.REQUEST);
        tester.addServlet(SampleServlet.class, "/dspace");
        try {
            tester.start();
        } catch (Exception e) {
            fail("Could not start the jetty server: " + e.getMessage());
        }

        // now there should be a kernel
        assertNotNull( new DSpaceKernelManager().getKernel() );

        // now fire the request
        String jettyRequest =
            "GET /dspace HTTP/1.1\r\n"+
            "Host: tester\r\n"+
            "\r\n";
        try {
            String content = tester.getResponses(jettyRequest);
            assertNotNull(content);
            assertTrue(content.contains("DSpaceTest"));
//            assertFalse(content.contains("session=null"));
//            assertFalse(content.contains("request=null"));
        } catch (Exception e) {
            fail("Could not fire request: " + e.getMessage());
        }

        // now there should be a kernel
        assertNotNull( new DSpaceKernelManager().getKernel() );

        // try a request a different way
        HttpTester request = new HttpTester();
        HttpTester response = new HttpTester();
        request.setMethod("GET");
        request.setHeader("Host","tester");
        request.setVersion("HTTP/1.0");
        request.setURI("/dspace");

        try {
            response.parse( tester.getResponses(request.generate()) );
        } catch (IOException e1) {
            fail("Could not parse response: " + e1.getMessage());
        } catch (Exception e1) {
            fail("Could not parse response: " + e1.getMessage());
        }

        assertTrue(response.getMethod() == null);
        assertEquals(200, response.getStatus());
        String content = response.getContent();
        assertNotNull(content);
        assertTrue(content.contains("DSpaceTest"));
//        assertFalse(content.contains("session=null"));
//        assertFalse(content.contains("request=null"));

        // now there should be a kernel
        assertNotNull( new DSpaceKernelManager().getKernel() );

        try {
            tester.stop();
        } catch (Exception e) {
            fail("Could not stop the jetty server: " + e.getMessage());
        }

        // back to no kernel again
        try {
            new DSpaceKernelManager().getKernel();
            fail("Should have thrown exception");
        } catch (IllegalStateException e) {
            assertNotNull(e.getMessage());
        }
       
View Full Code Here

     */
    @Test
    public void testKernelIsInitializedAndWorking() {
        assertNotNull(kernel);
        assertTrue(kernel.isRunning());
        DSpaceKernel k2 = new DSpaceKernelManager().getKernel();
        assertNotNull(k2);
        assertEquals(kernel, k2);
    }
View Full Code Here

TOP

Related Classes of org.dspace.kernel.DSpaceKernelManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.