Open
Description
I am facing issue with JaxbRepresentation in Osgi Container. Scenario is as follows:
- I have installed a bundle which sends JaxbRepresentation as response for a request.
- I uninstall bundle and then re install it and try to send same request but do not get response. I get exception.
Reason for issue:
private final static Map<String, JAXBContext> contexts = new ConcurrentHashMap<String, JAXBContext>();
public static synchronized JAXBContext getContext(String contextPath,
ClassLoader classLoader) throws JAXBException {
// Contexts are thread-safe so reuse those.
JAXBContext result = contexts.get(contextPath);
if (result == null) {
result = (classLoader == null) ? JAXBContext
.newInstance(contextPath) : JAXBContext.newInstance(
contextPath, classLoader);
contexts.put(contextPath, result);
}
return result;
}
Since our contexts is final static map and Osgi container does not shutdown and only bundle is shutdown that is why contexts map contain old reference loaded even after my bundle is uninstalled. So when I re install bundle I start getting exception as "javax.xml.bind.JAXBException: class *** nor any of its super class is known to this context.".
To resolve this there should be some mechanism by which I can clear those contexts which were created by my bundle which is getting uninstalled. If we have a method in place which can allow me to remove a context then I can clear specific contexts at time on stopping bundle.
Eg:
public void removeContext(String contextPath){ ... }