Search in sources :

Example 6 with EnvironmentContext

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);
}
Also used : EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) EventService(org.eclipse.che.api.core.notification.EventService) File(java.io.File) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with EnvironmentContext

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);
}
Also used : EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) WSConnection(org.everrest.websockets.WSConnection)

Example 8 with EnvironmentContext

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();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) HttpSession(javax.servlet.http.HttpSession) SubjectImpl(org.eclipse.che.commons.subject.SubjectImpl) Subject(org.eclipse.che.commons.subject.Subject)

Aggregations

EnvironmentContext (org.eclipse.che.commons.env.EnvironmentContext)8 SubjectImpl (org.eclipse.che.commons.subject.SubjectImpl)5 BeforeMethod (org.testng.annotations.BeforeMethod)3 Subject (org.eclipse.che.commons.subject.Subject)2 Test (org.testng.annotations.Test)2 File (java.io.File)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 AccountImpl (org.eclipse.che.account.spi.AccountImpl)1 MachineConfig (org.eclipse.che.api.core.model.machine.MachineConfig)1 EventService (org.eclipse.che.api.core.notification.EventService)1 RecipeImpl (org.eclipse.che.api.machine.server.recipe.RecipeImpl)1 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)1 ContainerCreated (org.eclipse.che.plugin.docker.client.json.ContainerCreated)1 CreateContainerParams (org.eclipse.che.plugin.docker.client.params.CreateContainerParams)1 InspectContainerParams (org.eclipse.che.plugin.docker.client.params.InspectContainerParams)1 WSConnection (org.everrest.websockets.WSConnection)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1