users@jersey.java.net

[Jersey] JUnit initialization exception due to JSONObjectProvider.

From: james.whetstone <james.whetstone.x_at_gmail.com>
Date: Thu, 18 Aug 2011 02:48:41 -0700 (PDT)

Hi,

I've got a web app that uses POJO serialization. I've set up my
Application classes to use
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider and it works
perfectly when I run my application and test it with a browser.

But when I run my junit test, it fails with the following exception that
shows that it couldn't instantiate JSONObjectProvider:

=================================================================
INFO: Instantiated the Application class
com.structuredcode.web.MyApplication
Aug 18, 2011 2:37:50 AM com.sun.jersey.core.spi.component.ProviderFactory
__getComponentProvider
SEVERE: The provider class, class
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider, could not be
instantiated. Processing will continue but the class will not be utilized
java.lang.IllegalAccessException: Class
com.sun.jersey.core.spi.component.ComponentConstructor can not access a
member of class com.sun.jersey.json.impl.provider.entity.JSONObjectProvider
with modifiers ""
        at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
        at java.lang.Class.newInstance0(Class.java:349)
        at java.lang.Class.newInstance(Class.java:308)
        at
com.sun.jersey.core.spi.component.ComponentConstructor._getInstance(ComponentConstructor.java:192)
        at
com.sun.jersey.core.spi.component.ComponentConstructor.getInstance(ComponentConstructor.java:179)
        at
com.sun.jersey.core.spi.component.ProviderFactory.__getComponentProvider(ProviderFactory.java:166)
        at
com.sun.jersey.core.spi.component.ProviderFactory._getComponentProvider(ProviderFactory.java:159)
        at
com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider(ProviderFactory.java:153)
        at
com.sun.jersey.core.spi.component.ProviderServices.getComponent(ProviderServices.java:251)
        at
com.sun.jersey.core.spi.component.ProviderServices.getProviders(ProviderServices.java:148)
        at
com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:175)
        at
com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:162)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1277)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
        at
com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
        at
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
        at
com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
        at
com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
        at
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
        at
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
        at javax.servlet.GenericServlet.init(GenericServlet.java:241)
        at
org.glassfish.grizzly.servlet.ServletHandler.loadServlet(ServletHandler.java:440)
        at
org.glassfish.grizzly.servlet.ServletHandler.doServletService(ServletHandler.java:365)
        at
org.glassfish.grizzly.servlet.ServletHandler.service(ServletHandler.java:322)
        at
org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:162)
        at
org.glassfish.grizzly.http.server.HttpHandlerChain.service(HttpHandlerChain.java:195)
        at
org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:162)
        at
org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:160)
        at
org.glassfish.grizzly.filterchain.ExecutorResolver$3.execute(ExecutorResolver.java:95)
        at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:444)
        at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:364)
        at
org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:290)
        at
org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:133)
        at
org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:76)
        at
org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:63)
        at
org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:823)
        at
org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
        at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:116)
        at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$000(WorkerThreadIOStrategy.java:55)
        at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$1.run(WorkerThreadIOStrategy.java:98)
        at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:508)
        at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:488)
        at java.lang.Thread.run(Thread.java:662)
Aug 18, 2011 2:37:50 AM com.sun.jersey.core.spi.component.ProviderFactory
__getComponentProvider
SEVERE: The provider class, class
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider, could not be
instantiated. Processing will continue but the class will not be utilized
java.lang.IllegalAccessException: Class
com.sun.jersey.core.spi.component.ComponentConstructor can not access a
member of class com.sun.jersey.json.impl.provider.entity.JSONObjectProvider
with modifiers ""
        at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:65)
        at java.lang.Class.newInstance0(Class.java:349)
        at java.lang.Class.newInstance(Class.java:308)
        at
com.sun.jersey.core.spi.component.ComponentConstructor._getInstance(ComponentConstructor.java:192)
        at
com.sun.jersey.core.spi.component.ComponentConstructor.getInstance(ComponentConstructor.java:179)
        at
com.sun.jersey.core.spi.component.ProviderFactory.__getComponentProvider(ProviderFactory.java:166)
        at
com.sun.jersey.core.spi.component.ProviderFactory._getComponentProvider(ProviderFactory.java:159)
        at
com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider(ProviderFactory.java:153)
        at
com.sun.jersey.core.spi.component.ProviderServices.getComponent(ProviderServices.java:251)
        at
com.sun.jersey.core.spi.component.ProviderServices.getProviders(ProviderServices.java:148)
        at
com.sun.jersey.core.spi.factory.MessageBodyFactory.initWriters(MessageBodyFactory.java:206)
        at
com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:163)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1277)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
        at
com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
        at
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
        at
com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
        at
com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
        at
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
        at
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
        at javax.servlet.GenericServlet.init(GenericServlet.java:241)
        at
org.glassfish.grizzly.servlet.ServletHandler.loadServlet(ServletHandler.java:440)
        at
org.glassfish.grizzly.servlet.ServletHandler.doServletService(ServletHandler.java:365)
        at
org.glassfish.grizzly.servlet.ServletHandler.service(ServletHandler.java:322)
        at
org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:162)
        at
org.glassfish.grizzly.http.server.HttpHandlerChain.service(HttpHandlerChain.java:195)
        at
org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:162)
        at
org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:160)
        at
org.glassfish.grizzly.filterchain.ExecutorResolver$3.execute(ExecutorResolver.java:95)
        at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:444)
        at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:364)
        at
org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:290)
        at
org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:133)
        at
org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:76)
        at
org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:63)
        at
org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:823)
        at
org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
        at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:116)
        at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$000(WorkerThreadIOStrategy.java:55)
        at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$1.run(WorkerThreadIOStrategy.java:98)
        at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:508)
        at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:488)
        at java.lang.Thread.run(Thread.java:662)
Aug 18, 2011 2:37:51 AM com.sun.jersey.spi.inject.Errors
processErrorMessages
SEVERE: The following errors and warnings have been detected with resource
and/or provider classes:
  SEVERE: The class
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider does not have a
public constructor and cannot be instantiated.
  SEVERE: The class
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider does not have a
public constructor and cannot be instantiated.
Aug 18, 2011 2:37:51 AM org.glassfish.grizzly.servlet.ServletHandler
doServletService
SEVERE: service exception:
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
        at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
        at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
        at
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
        at
com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
        at
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
        at
com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
        at
com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
        at
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
        at
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
        at javax.servlet.GenericServlet.init(GenericServlet.java:241)
        at
org.glassfish.grizzly.servlet.ServletHandler.loadServlet(ServletHandler.java:440)
        at
org.glassfish.grizzly.servlet.ServletHandler.doServletService(ServletHandler.java:365)
        at
org.glassfish.grizzly.servlet.ServletHandler.service(ServletHandler.java:322)
        at
org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:162)
        at
org.glassfish.grizzly.http.server.HttpHandlerChain.service(HttpHandlerChain.java:195)
        at
org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:162)
        at
org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:160)
        at
org.glassfish.grizzly.filterchain.ExecutorResolver$3.execute(ExecutorResolver.java:95)
        at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:444)
        at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:364)
        at
org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:290)
        at
org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:133)
        at
org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:76)
        at
org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:63)
        at
org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:823)
        at
org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
        at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:116)
        at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$000(WorkerThreadIOStrategy.java:55)
        at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$1.run(WorkerThreadIOStrategy.java:98)
        at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:508)
        at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:488)
        at java.lang.Thread.run(Thread.java:662)
Aug 18, 2011 2:37:51 AM
com.sun.jersey.test.framework.spi.container.grizzly2.web.GrizzlyWebTestContainerFactory$GrizzlyWebTestContainer
stop
INFO: Stopping the Grizzly2 Web Container...
=====================================================================

I'm using Grizzly2 as my test container and my test class is defined as
follows:

import org.junit.Test;

import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.json.JSONConfiguration;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.WebAppDescriptor;


public class MainTest extends JerseyTest {

    public MainTest()throws Exception {
            super(new WebAppDescriptor.Builder("javax.ws.rs.Application",
MyApplication.class.getName()).initParam(JSONConfiguration.FEATURE_POJO_MAPPING,
"true").build());

    }

    @Test
    public void testAccountResource() {
        WebResource r = resource();
        String responseMsg =
r.path("/api/1.0/account").accept("application/json").get(String.class);
        
    }
}


Can anyone help me out with this?

---James



--
View this message in context: http://jersey.576304.n2.nabble.com/JUnit-initialization-exception-due-to-JSONObjectProvider-tp6698759p6698759.html
Sent from the Jersey mailing list archive at Nabble.com.