Skip to content

Instantly share code, notes, and snippets.

@hsyed
Last active October 31, 2015 17:03
Show Gist options
  • Save hsyed/76573e255c8de6d2f83b to your computer and use it in GitHub Desktop.
Save hsyed/76573e255c8de6d2f83b to your computer and use it in GitHub Desktop.
@Override
public void run() {
if( application.isDirty() ) {
ClassLoader original = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader( Request.class.getClassLoader() );
synchronized( this ) {
if( !isJerseyReady() ) {
Activator.logger.info("Initializing JAX-RS Container.");
// if jersey has not been initialized - use the init method
getServletContainer().init( servletConfig );
Activator.logger.info("JAX-RS Container initialized.");
} else {
// otherwise reload
isJerseyReady = false;
getServletContainer().reload( ResourceConfig.forApplication( application ) );
}
isJerseyReady = true;
}
} catch(Throwable t) {
handleTerminalError(t);
} finally {
Thread.currentThread().setContextClassLoader( original );
}
}
}
private void handleTerminalError(Throwable t) {
Activator.logger.error("Error during JAX-RS Container initialization. Taking bundle down.", t);
try {
FrameworkUtil.getBundle(this.getClass()).stop();
} catch (BundleException e) {
e.printStackTrace();
Activator.logger.error("error during bundle teardown", e);
throw new RuntimeException(e);
}
throw new RuntimeException(t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment