Hello,
I am trying to upgrade to Jersey 1.2 (can not upgrade to 1.4 because we
are limited by Java 1.5). The application uses several custom
InjectableProviders which work perfectly fine in 1.0.3.1, but in 1.2
the injection does not work. Below is a sample of the custom
InjectableProvider and the resource class that uses it. Both the
resource and the injectable provider are found by Jersey (they are
listed in the log trace on startup), and the provider is instantiated
since a break point in the constructor does trigger. getScope() is
also called, however getInjectable or getValue are never called, and
Jersey throws an exception shown below. What exactly should I be doing
to get this to work under Jersey 1.2.
Thanks,
George
@Provider
public class DataServiceProvider implements InjectableProvider<Inject,
Type>, Injectable<DataService>
{
private DataService m_service;
/**
* Contruct a data service provider.
*/
public DataServiceProvider()
{
m_service = new SoaDataService();
}
/* (non-Javadoc)
* @see com.sun.jersey.spi.inject.InjectableProvider#getScope()
*/
public ComponentScope getScope()
{
return ComponentScope.Singleton;
}
/* (non-Javadoc)
* @see
com.sun.jersey.spi.inject.InjectableProvider#getInjectable(com.sun.jers
ey.core.spi.component.ComponentContext,
java.lang.annotation.Annotation, java.lang.Object)
*/
public Injectable<DataService> getInjectable(ComponentContext
context, Inject annotation, Type clazz)
{
if (clazz.equals(DataService.class))
{
return this;
}
return null;
}
/* (non-Javadoc)
* @see com.sun.jersey.spi.inject.Injectable#getValue()
*/
public DataService getValue()
{
return m_service;
}
}
@Path("/mypath")
public class MyResource
{
private DataService m_service;
/**
* Construct a ContactUsResource bound to the specified data
service.
*
* @param service data service.
*/
public DealerResource(@Inject DataService service)
{
m_service = service;
}
@GET
@Path("/find/{someparam}")
public String doSomething(@Context HttpServletRequest request,
@PathParam("someparam") String param)
{
return param;
}
}
Exception thrown
[java] com.sun.jersey.api.container.ContainerException: Unable to
create resource class com.subaru.datalayer.data.rest.MyResource
[java] at
com.sun.jersey.server.impl.resource.PerRequestFactory$PerRequest._getIn
stance(PerRequestFactory.java:190)
[java] at
com.sun.jersey.server.impl.resource.PerRequestFactory$AbstractPerReques
t.getInstance(PerRequestFactory.java:141)
[java] at
com.sun.jersey.server.impl.application.WebApplicationContext.getResourc
e(WebApplicationContext.java:181)
[java] at
com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceC
lassRule.java:66)
[java] at
com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHand
PathRule.java:133)
[java] at
com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(Roo
tResourceClassesRule.java:71)
[java] at
com.sun.jersey.server.impl.application.WebApplicationImpl._handleReques
t(WebApplicationImpl.java:996)
[java] at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest
(WebApplicationImpl.java:947)
[java] at
com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest
(WebApplicationImpl.java:938)
[java] at
com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.
java:399)
[java] at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletCo
ntainer.java:478)
[java] at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletCo
ntainer.java:663)
[java] at
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
[java] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applic
ationFilterChain.java:269)
[java] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFil
terChain.java:188)
[java] at
com.subaru.servlet.ExpiredSessionRedirectFilter.doFilter(ExpiredSession
RedirectFilter.java:121)
[java] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applic
ationFilterChain.java:215)
[java] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFil
terChain.java:188)
[java] at
com.subaru.servlet.RedirectFilter.doFilter(RedirectFilter.java:160)
[java] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applic
ationFilterChain.java:215)
[java] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFil
terChain.java:188)
[java] at
com.subaru.servlet.LocalSslRedirectFilter.doFilter(LocalSslRedirectFilt
er.java:104)
[java] at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applic
ationFilterChain.java:215)
[java] at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFil
terChain.java:188)
[java] at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVal
ve.java:213)
[java] at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextVal
ve.java:174)
[java] at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.jav
a:127)
[java] at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.jav
a:117)
[java] at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve
.java:108)
[java] at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
174)
[java] at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:8
74)
[java] at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.pro
cessConnection(Http11BaseProtocol.java:665)
[java] at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoin
t.java:528)
[java] at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollo
werWorkerThread.java:81)
[java] at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPoo
l.java:689)
[java] at java.lang.Thread.run(Thread.java:662)
[java] Caused by: com.sun.jersey.api.container.ContainerException:
Unable to create resource interface
com.subaru.datalayer.webservices.DataService
[java] at
com.sun.jersey.server.impl.resource.PerRequestFactory$PerRequest._getIn
stance(PerRequestFactory.java:181)
[java] at
com.sun.jersey.server.impl.resource.PerRequestFactory$AbstractPerReques
t.getInstance(PerRequestFactory.java:141)
[java] at
com.sun.jersey.server.impl.application.WebApplicationImpl$8$1.getValue(
WebApplicationImpl.java:692)
[java] at
com.sun.jersey.server.impl.inject.AbstractHttpContextInjectable$1.getVa
lue(AbstractHttpContextInjectable.java:100)
[java] at
com.sun.jersey.server.spi.component.ResourceComponentConstructor._const
ruct(ResourceComponentConstructor.java:175)
[java] at
com.sun.jersey.server.spi.component.ResourceComponentConstructor.constr
uct(ResourceComponentConstructor.java:159)
[java] at
com.sun.jersey.server.impl.resource.PerRequestFactory$PerRequest._getIn
stance(PerRequestFactory.java:179)
[java] ... 35 more
[java] Caused by: java.lang.InstantiationException:
com.subaru.datalayer.webservices.DataService
[java] at java.lang.Class.newInstance0(Class.java:340)
[java] at java.lang.Class.newInstance(Class.java:308)
[java] at
com.sun.jersey.server.spi.component.ResourceComponentConstructor._const
ruct(ResourceComponentConstructor.java:170)
[java] at
com.sun.jersey.server.spi.component.ResourceComponentConstructor.constr
uct(ResourceComponentConstructor.java:159)
[java] at
com.sun.jersey.server.impl.resource.PerRequestFactory$PerRequest._getIn
stance(PerRequestFactory.java:179)
[java] ... 41 more