this.serviceLocator = serviceLocator;
this.wadlGeneratorConfig = WadlGeneratorConfigLoader.loadWadlGeneratorsFromConfig(configuration.getProperties());
// TODO perhaps this should be done another way for the moment
// create a temporary generator just to do this one task
final WadlGenerator wadlGenerator = wadlGeneratorConfig.createWadlGenerator(serviceLocator);
JAXBContext jaxbContextCandidate;
final ClassLoader contextClassLoader = AccessController.doPrivileged(ReflectionHelper.getContextClassLoaderPA());
try {
// Nasty ClassLoader magic. JAXB-API has some strange limitation about what classloader can
// be used in OSGi environment - it must be same as context ClassLoader. Following code just
// workarounds this limitation
// see JERSEY-1818
// see JSR222-46
final ClassLoader jerseyModuleClassLoader =
AccessController.doPrivileged(ReflectionHelper.getClassLoaderPA(wadlGenerator.getClass()));
AccessController.doPrivileged(ReflectionHelper.setContextClassLoaderPA(jerseyModuleClassLoader));
jaxbContextCandidate = JAXBContext.newInstance(wadlGenerator.getRequiredJaxbContextPath(), jerseyModuleClassLoader);
} catch (final JAXBException ex) {
try {
// fallback for glassfish
LOGGER.log(Level.FINE, LocalizationMessages.WADL_JAXB_CONTEXT_FALLBACK(), ex);
jaxbContextCandidate = JAXBContext.newInstance(wadlGenerator.getRequiredJaxbContextPath());
} catch (final JAXBException innerEx) {
throw new ProcessingException(LocalizationMessages.ERROR_WADL_JAXB_CONTEXT(), ex);
}
} finally {
AccessController.doPrivileged(ReflectionHelper.setContextClassLoaderPA(contextClassLoader));