use of org.eclipse.jetty.util.thread.ThreadClassLoaderScope in project jetty.project by eclipse.
the class WebSocketCdiInitializer method onStartup.
@Override
public void onStartup(Set<Class<?>> c, ServletContext context) throws ServletException {
ContextHandler handler = ContextHandler.getContextHandler(context);
if (handler == null) {
throw new ServletException("Not running on Jetty, WebSocket+CDI support unavailable");
}
if (!(handler instanceof ServletContextHandler)) {
throw new ServletException("Not running in Jetty ServletContextHandler, WebSocket+CDI support unavailable");
}
ServletContextHandler jettyContext = (ServletContextHandler) handler;
try (ThreadClassLoaderScope scope = new ThreadClassLoaderScope(context.getClassLoader())) {
addListeners(jettyContext);
}
}
use of org.eclipse.jetty.util.thread.ThreadClassLoaderScope in project ligoj-api by ligoj.
the class PluginsClassLoaderTest method getInstance.
@Test
public void getInstance() {
ThreadClassLoaderScope scope = null;
try {
scope = new ThreadClassLoaderScope(new URLClassLoader(new URL[0], Mockito.mock(PluginsClassLoader.class)));
Assertions.assertNotNull(PluginsClassLoader.getInstance());
} finally {
IOUtils.closeQuietly(scope);
}
}
use of org.eclipse.jetty.util.thread.ThreadClassLoaderScope in project jetty.project by eclipse.
the class WebSocketSession method open.
/**
* Open/Activate the session
*/
public void open() {
if (LOG_OPEN.isDebugEnabled())
LOG_OPEN.debug("[{}] {}.open()", policy.getBehavior(), this.getClass().getSimpleName());
if (remote != null) {
// already opened
return;
}
try (ThreadClassLoaderScope scope = new ThreadClassLoaderScope(classLoader)) {
// Upgrade success
connection.getIOState().onConnected();
// Connect remote
remote = remoteEndpointFactory.newRemoteEndpoint(connection, outgoingHandler, getBatchMode());
if (LOG_OPEN.isDebugEnabled())
LOG_OPEN.debug("[{}] {}.open() remote={}", policy.getBehavior(), this.getClass().getSimpleName(), remote);
// Open WebSocket
websocket.openSession(this);
// Open connection
connection.getIOState().onOpened();
if (LOG.isDebugEnabled()) {
LOG.debug("open -> {}", dump());
}
if (openFuture != null) {
openFuture.complete(this);
}
} catch (CloseException ce) {
LOG.warn(ce);
close(ce.getStatusCode(), ce.getMessage());
} catch (Throwable t) {
LOG.warn(t);
// Exception on end-user WS-Endpoint.
// Fast-fail & close connection with reason.
int statusCode = StatusCode.SERVER_ERROR;
if (policy.getBehavior() == WebSocketBehavior.CLIENT) {
statusCode = StatusCode.POLICY_VIOLATION;
}
close(statusCode, t.getMessage());
}
}
use of org.eclipse.jetty.util.thread.ThreadClassLoaderScope in project plugin-prov by ligoj.
the class TerraformResourceTest method toFile.
@Test
public void toFile() throws IOException {
ThreadClassLoaderScope scope = null;
try {
final PluginsClassLoader classLoader = Mockito.mock(PluginsClassLoader.class);
scope = new ThreadClassLoaderScope(new URLClassLoader(new URL[0], classLoader));
final File file = new File("");
final Subscription entity = new Subscription();
entity.setId(15);
Mockito.when(classLoader.toFile(entity, "15", "some")).thenReturn(file);
Assertions.assertSame(file, resource.toFile(entity, "some"));
Assertions.assertNotNull(PluginsClassLoader.getInstance());
} finally {
IOUtils.closeQuietly(scope);
}
}
Aggregations