[
https://issues.apache.org/jira/browse/CXF-4704?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13533889#comment-13533889
]
Valdas Jasaitis commented on CXF-4704:
--------------------------------------
Yes, I use bundle Activator:
{noformat}
public void start(BundleContext context) throws Exception {
ServiceReference sRef =
context.getServiceReference(HttpService.class.getName());
if (sRef != null) {
HttpService service = (HttpService) context.getService(sRef);
final Dictionary<String, Object> properties = new Hashtable<String,
Object>();
properties.put("jaxrs.serviceClasses", "com.MyProxyImpl");
service.registerServlet(PATH, new CXFNonSpringJaxrsServlet(),
properties, null);
}
}
{noformat}
And then I get
{noformat}
Caused by: java.lang.ClassNotFoundException: com.MyProxyImpl not found by
bundle [233]
at
org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787)
at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71)
at
org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1768)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at
org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass2(ClassLoaderUtils.java:271)
at
org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass(ClassLoaderUtils.java:245)
at
org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.loadClass(CXFNonSpringJaxrsServlet.java:430)
{noformat}
A workaround would be to use a correct class loader:
{noformat}
public void start(BundleContext context) throws Exception {
ServiceReference sRef =
context.getServiceReference(HttpService.class.getName());
if (sRef != null) {
HttpService service = (HttpService) context.getService(sRef);
final Dictionary<String, Object> properties = new Hashtable<String,
Object>();
properties.put("jaxrs.serviceClasses", "com.MyProxyImpl");
// patch TCCL as it is used here
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
service.registerServlet(PATH, new CXFNonSpringJaxrsServlet(),
properties, null);
Thread.currentThread().setContextClassLoader(oldCl);
}
}
{noformat}
> Do you mean adding "setClassLoader" setter to it so that the servlet can use
> this loader instead of delegating to ClassLoaderUtils ?
Yes, it would be nice to have such setter.
> Class loading problem using CXFNonSpringJaxrsServlet in OSGi environment
> ------------------------------------------------------------------------
>
> Key: CXF-4704
> URL: https://issues.apache.org/jira/browse/CXF-4704
> Project: CXF
> Issue Type: Bug
> Components: JAX-RS
> Affects Versions: 2.6.2
> Environment: Apache Felix
> Reporter: Valdas Jasaitis
>
> The JAX-RS proxy classes are not loaded when I try to use
> CXFNonSpringJaxrsServlet in Apache Felix. I get ClassNotFoundException.
> The problem is that currently CXFNonSpringJaxrsServlet.loadClass always uses
> the ClassLoadUtils.loadClass which tries the following class loaders:
> ThreadContextClassloader,
> ClassLoader from CXFNonSpringJaxrsServlet,
> Classloader from ClassLoaderUtils.
> All of them are not compatible with OSGi. It would be good, to set an
> explicit classloader for the servlet.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira