java.lang.NullPointerException at org.apache.wink.common.internal.utils.FileLoader.loadFileUsingClassLoaders

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

java.lang.NullPointerException at org.apache.wink.common.internal.utils.FileLoader.loadFileUsingClassLoaders

gSharma
I am trying to run integration tests on my scim restful server implementation via an embedded jetty server and apache wink REST Client but failing to run the tests. Here is my EmbeddedServerBase class

    package org.picketlink.test.scim;

    import java.net.URL;

    import org.eclipse.jetty.server.Connector;
    import org.eclipse.jetty.server.Server;
    import org.eclipse.jetty.server.bio.SocketConnector;
    import org.eclipse.jetty.servlet.FilterHolder;
    import org.eclipse.jetty.servlet.FilterMapping;
    import org.eclipse.jetty.servlet.ServletHolder;
    import org.eclipse.jetty.webapp.WebAppContext;
    import org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher;
    import org.junit.After;
    import org.junit.Before;
    import org.picketlink.scim.PicketLinkSCIMApplication;

    public class EmbeddedWebServerBase {
    protected Server server = null;

    @Before
    public void setUp() throws Exception {
        // Start the Jetty embedded container
        server = new Server();

        server.setConnectors(getConnectors());

        this.establishUserApps();

        server.start();
    }

    @After
    public void tearDown() throws Exception {
        if (server != null) {
            server.stop();
            try {
                server.destroy();
            } catch (Exception e) {
                //Don't bother
            }
            server = null;
        }
    }

    /**
     * Return the connectors that need to be configured on the server. Subclasses can create as many connectors as they want
     *
     * @return
     */
    protected Connector[] getConnectors() {
        Connector connector = new SocketConnector();
        connector.setPort(11080);
        return new Connector[] { connector };
    }

    /**
     * Establish the user applications - context, servlets etc
     */
    protected void establishUserApps() {
        ClassLoader tcl = Thread.currentThread().getContextClassLoader();
        if (tcl == null) {
            tcl = getClass().getClassLoader();
        }

        final String WEBAPPDIR = "scim";

        final String CONTEXTPATH = "/*";

        // for localhost:port/admin/index.html and whatever else is in the webapp directory
        final URL warUrl = tcl.getResource(WEBAPPDIR);
        final String warUrlString = warUrl.toExternalForm();

        WebAppContext context = createWebApp(CONTEXTPATH, warUrlString);
        context.setClassLoader(getClass().getClassLoader());
        context.setExtraClasspath(warUrlString + "/..");

        context.setConfigurationClasses(new String[] { "org.eclipse.jetty.webapp.WebInfConfiguration",
                "org.eclipse.jetty.webapp.WebXmlConfiguration", "org.eclipse.jetty.webapp.MetaInfConfiguration",
                "org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration",
                //"org.eclipse.jetty.plus.webapp.PlusConfiguration",
                "org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.webapp.TagLibConfiguration" });

        context.setContextPath("/");

        ServletHolder servletHolder = new ServletHolder(new HttpServletDispatcher());
        servletHolder.setInitParameter("javax.ws.rs.Application", PicketLinkSCIMApplication.class.getName());
        context.addServlet(servletHolder, "/*");

        server.setHandler(context);
    }

    protected FilterMapping createFilterMapping(String pathSpec, FilterHolder filterHolder)      {
        FilterMapping filterMapping = new FilterMapping();
        filterMapping.setPathSpec(pathSpec);
        filterMapping.setFilterName(filterHolder.getName());
        return filterMapping;
    }

    protected WebAppContext createWebApp(String contextPath, String warURLString) {
        WebAppContext webapp = new WebAppContext();
        webapp.setContextPath(contextPath);
        webapp.setWar(warURLString);

        Thread.currentThread().setContextClassLoader(webapp.getClassLoader());
        return webapp;
    }
    }

The exception is most probably thrown at "webapp.getClassLoader()" in Thread.currentThread().setContextClassLoader(webapp.getClassLoader());

Here is a snippet from CrudTest.java

    package org.picketlink.scim.restful.client.test;

    import org.junit.Before;
    import org.junit.Ignore;
    import org.junit.Test;
    import org.picketlink.scim.core.entities.ObjectFactory;
    import org.picketlink.scim.restful.client.Client;
    import org.picketlink.scim.restful.client.Tests;
    import org.picketlink.test.scim.EmbeddedWebServerBase;

    public class CrudTest extends EmbeddedWebServerBase {
    private Client client = null;
    private ObjectFactory factory = null;

    @Before
    public void onBefore() {
        // create a client to send the user/group crud requests
        client = new Client("http://localhost:11080/scim", "matt", "password");

        // create an object factory to create the user/group objects
        factory = new ObjectFactory();
    }
   
    @Test
    public void testBasicCrud() {
        // test the create user functionality
        String gid = Tests.createGroupTest(client, factory);
    }
    }

Here is a snippet from Client.java

    import javax.ws.rs.core.MediaType;
    import javax.xml.bind.JAXBElement;

    import org.picketlink.scim.core.entities.Group;
    import org.picketlink.scim.core.entities.ObjectFactory;
    import org.picketlink.scim.core.entities.User;

    import org.apache.wink.client.ClientConfig;
    import org.apache.wink.client.ClientResponse;
    import org.apache.wink.client.Resource;
    import org.apache.wink.client.RestClient;

    public class Client {
    private ObjectFactory factory = null;
    private ClientConfig config = null;
    private RestClient client = null;
    private String url = null;

    public Client(String url, String username, String password) {
        // setup the object factory
        factory = new ObjectFactory();

        // setup the client config
        config = new ClientConfig();

        // setup the rest client
        client = new RestClient(config);

        // remove any trailing slash
        url = url.replaceAll("/$", "");

        // store the url for later
        this.url = url;
    }
    //Other methods
    }

Exception is most probably thrown at:
   
    client = new RestClient(config);

The Stacktrace

    java.lang.NullPointerException
            at org.apache.wink.common.internal.utils.FileLoader.loadFileUsingClassLoaders(FileLoader.java:130)
            at org.apache.wink.common.internal.utils.FileLoader.loadFileAsStream(FileLoader.java:96)
            at org.apache.wink.common.internal.application.ApplicationFileLoader.<init>(ApplicationFileLoader.java:97)
            at org.apache.wink.common.internal.application.ApplicationFileLoader.<init>(ApplicationFileLoader.java:66)
            at org.apache.wink.client.ClientConfig$1.run(ClientConfig.java:112)
            at java.security.AccessController.doPrivileged(Native Method)
            at org.apache.wink.client.ClientConfig.initDefaultApplication(ClientConfig.java:109)
            at org.apache.wink.client.ClientConfig.clone(ClientConfig.java:408)
            at org.apache.wink.client.RestClient.<init>(RestClient.java:81)
            at org.picketlink.scim.restful.client.Client.<init>(Client.java:60)
            at org.picketlink.scim.restful.client.test.CrudTest.onBefore(CrudTest.java:35)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:606)
            at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
            at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
            at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
            at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
            at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
            at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
            at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
            at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
            at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
            at org.apache.maven.surefire.junitcore.pc.Scheduler$1.run(Scheduler.java:318)
            at org.apache.maven.surefire.junitcore.pc.InvokerStrategy.schedule(InvokerStrategy.java:41)
            at org.apache.maven.surefire.junitcore.pc.Scheduler.schedule(Scheduler.java:274)
            at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
            at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
            at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
            at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
            at org.junit.runners.Suite.runChild(Suite.java:128)
            at org.junit.runners.Suite.runChild(Suite.java:24)
            at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
            at org.apache.maven.surefire.junitcore.pc.Scheduler$1.run(Scheduler.java:318)
            at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
            at java.util.concurrent.FutureTask.run(FutureTask.java:262)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
            at java.lang.Thread.run(Thread.java:745)

Here is the link to complete [log](http://pastebin.com/SF9UFAMa)