use of org.eclipse.che.commons.env.EnvironmentContext in project che by eclipse.
the class MachineProcessManagerTest method setUp.
@BeforeMethod
public void setUp() throws Exception {
final EventService eventService = mock(EventService.class);
final String machineLogsDir = targetDir().resolve("logs-dir").toString();
IoUtil.deleteRecursive(new File(machineLogsDir));
manager = spy(new MachineProcessManager(machineLogsDir, eventService, environmentEngine));
EnvironmentContext envCont = new EnvironmentContext();
envCont.setSubject(CREATOR);
EnvironmentContext.setCurrent(envCont);
doReturn(logConsumer).when(manager).getProcessLogger(MACHINE_ID, 111, "outputChannel");
when(command.getCommandLine()).thenReturn("CommandLine");
when(command.getName()).thenReturn("CommandName");
when(command.getType()).thenReturn("CommandType");
when(instance.createProcess(command, "outputChannel")).thenReturn(instanceProcess);
when(instanceProcess.getPid()).thenReturn(111);
when(environmentEngine.getMachine(WORKSPACE_ID, MACHINE_ID)).thenReturn(instance);
}
use of org.eclipse.che.commons.env.EnvironmentContext in project che by eclipse.
the class WebSocketMethodInvokerDecorator method invokeMethod.
@Override
public Object invokeMethod(Object resource, GenericResourceMethod genericMethodResource, ApplicationContext context) {
WSConnection wsConnection = (WSConnection) org.everrest.core.impl.EnvironmentContext.getCurrent().get(WSConnection.class);
if (wsConnection != null) {
EnvironmentContext environmentContext = (EnvironmentContext) wsConnection.getAttribute(ENVIRONMENT_CONTEXT);
if (environmentContext != null) {
try {
EnvironmentContext.setCurrent(environmentContext);
LOG.debug("Websocket {} in http session {}", wsConnection.getId(), wsConnection.getHttpSession());
return super.invokeMethod(resource, genericMethodResource, context);
} finally {
EnvironmentContext.reset();
}
} else {
LOG.warn("EnvironmentContext is null");
}
}
return super.invokeMethod(resource, genericMethodResource, context);
}
use of org.eclipse.che.commons.env.EnvironmentContext in project che by eclipse.
the class EnvironmentInitializationFilter method doFilter.
@Override
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
final HttpServletRequest httpRequest = (HttpServletRequest) request;
Subject subject = new SubjectImpl("che", "che", "dummy_token", false);
HttpSession session = httpRequest.getSession();
session.setAttribute("codenvy_user", subject);
final EnvironmentContext environmentContext = EnvironmentContext.getCurrent();
try {
environmentContext.setSubject(subject);
filterChain.doFilter(addUserInRequest(httpRequest, subject), response);
} finally {
EnvironmentContext.reset();
}
}
Aggregations