Skip to content

Commit

Permalink
Merge branch 'master' into CHE-1819
Browse files Browse the repository at this point in the history
  • Loading branch information
Valeriy Svydenko committed Jul 26, 2016
2 parents 330c8d6 + f0209eb commit 1dfa46c
Show file tree
Hide file tree
Showing 87 changed files with 1,653 additions and 710 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ public void shouldSkipRequestToProject() throws Exception {
when(request.getMethod()).thenReturn("GET");
when(request.getRequestURI()).thenReturn("/namespace/ws-id/project1");
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/namespace/ws-id/project1"));
EnvironmentContext context = new EnvironmentContext();
context.setWorkspaceId("ws-id");
EnvironmentContext.setCurrent(context);

//when
filter.doFilter(request, response, chain);
Expand All @@ -74,8 +71,6 @@ public void shouldRedirectIfRequestWithoutNamespace(String uri, String url) thro
when(request.getRequestURI()).thenReturn(uri);
when(request.getRequestURL()).thenReturn(new StringBuffer(url));
EnvironmentContext context = new EnvironmentContext();
context.setWorkspaceId("ws-id");
context.setWorkspaceTemporary(false);
context.setSubject(new SubjectImpl("id123", "name", "token123", false));
EnvironmentContext.setCurrent(context);

Expand All @@ -99,9 +94,6 @@ public void shouldSkipNotGETRequest(String method) throws Exception {
when(request.getMethod()).thenReturn(method);
when(request.getRequestURI()).thenReturn("/ws-id/project1");
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/ws-id/project1"));
EnvironmentContext context = new EnvironmentContext();
context.setWorkspaceId("ws-id");
EnvironmentContext.setCurrent(context);

//when
filter.doFilter(request, response, chain);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public class WsAgentAnalyticsAddresser {
void send() {
HttpURLConnection connection = null;
try {
final URL url = new URL("https://install.codenvycorp.com/che/telemetry/workspace");
final URL url = new URL("https://install.codenvycorp.com/che/init/workspace");
connection = (HttpsURLConnection)url.openConnection();
connection.getResponseCode();
} catch (IOException e) {
LOG.error("Failed to send agent analytics", e);
} finally {
if (connection != null) {
connection.disconnect();
}
if (connection != null) {
connection.disconnect();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,11 @@
import org.eclipse.che.api.ssh.server.SshServiceClient;
import org.eclipse.che.api.user.server.spi.PreferenceDao;
import org.eclipse.che.commons.lang.Pair;
import org.eclipse.che.everrest.CheAsynchronousJobPool;
import org.eclipse.che.api.git.LocalGitUserResolver;
import org.eclipse.che.git.impl.jgit.JGitConnectionFactory;
import org.eclipse.che.inject.DynaModule;
import org.eclipse.che.plugin.java.server.rest.WsAgentURLProvider;
import org.eclipse.che.security.oauth.RemoteOAuthTokenProvider;
import org.everrest.core.impl.async.AsynchronousJobPool;
import org.everrest.core.impl.async.AsynchronousJobService;
import org.everrest.guice.ServiceBindingHelper;

import javax.inject.Named;
import java.net.URI;
Expand Down Expand Up @@ -71,9 +67,6 @@ protected void configure() {
bind(GitUserResolver.class).to(LocalGitUserResolver.class);
bind(GitConnectionFactory.class).to(JGitConnectionFactory.class);

bind(AsynchronousJobPool.class).to(CheAsynchronousJobPool.class);
bind(ServiceBindingHelper.bindingKey(AsynchronousJobService.class, "/async/{ws-id}")).to(AsynchronousJobService.class);

bind(String.class).annotatedWith(Names.named("api.endpoint")).toProvider(ApiEndpointProvider.class);
bind(URI.class).annotatedWith(Names.named("api.endpoint")).toProvider(UriApiEndpointProvider.class);
bind(String.class).annotatedWith(Names.named("user.token")).toProvider(UserTokenProvider.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.google.inject.servlet.ServletModule;

import org.eclipse.che.api.core.cors.CheCorsFilter;
import org.eclipse.che.filters.WsAgentEnvironmentInitializationFilter;
import org.eclipse.che.filters.EnvironmentInitializationFilter;
import org.eclipse.che.inject.DynaModule;
import org.everrest.guice.servlet.GuiceEverrestServlet;
import org.everrest.websockets.WSConnectionTracker;
Expand All @@ -27,7 +27,7 @@ protected void configureServlets() {
getServletContext().addListener(new WSConnectionTracker());

filter("/*").through(CheCorsFilter.class);
filter("/ext/*").through(WsAgentEnvironmentInitializationFilter.class);
filter("/ext/*").through(EnvironmentInitializationFilter.class);

serveRegex("^/ext((?!(/(ws|eventbus)($|/.*)))/.*)").with(GuiceEverrestServlet.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class WsMasterAnalyticsAddresser {
void send() {
HttpURLConnection connection = null;
try {
final URL url = new URL("https://install.codenvycorp.com/che/telemetry/master");
final URL url = new URL("https://install.codenvycorp.com/che/init/server");
connection = (HttpsURLConnection)url.openConnection();
connection.getResponseCode();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.eclipse.che.api.machine.shared.Constants;
import org.eclipse.che.api.user.server.ProfileService;
import org.eclipse.che.inject.DynaModule;
import org.everrest.guice.ServiceBindingHelper;

/** @author andrew00x */
@DynaModule
Expand All @@ -37,9 +36,6 @@ protected void configure() {
bind(org.eclipse.che.api.workspace.server.stack.StackService.class);
bind(org.eclipse.che.api.workspace.server.WorkspaceService.class);
bind(org.eclipse.che.api.workspace.server.event.WorkspaceMessenger.class).asEagerSingleton();
bind(org.everrest.core.impl.async.AsynchronousJobPool.class).to(org.eclipse.che.everrest.CheAsynchronousJobPool.class);
bind(ServiceBindingHelper.bindingKey(org.everrest.core.impl.async.AsynchronousJobService.class, "/async/{ws-id}"))
.to(org.everrest.core.impl.async.AsynchronousJobService.class);
bind(org.eclipse.che.plugin.docker.machine.ext.DockerMachineExtServerChecker.class);
bind(org.eclipse.che.plugin.docker.machine.ext.DockerMachineTerminalChecker.class);
bind(org.eclipse.che.everrest.EverrestDownloadFileResponseFilter.class);
Expand Down Expand Up @@ -68,7 +64,7 @@ protected void configure() {

bindConstant().annotatedWith(Names.named(org.eclipse.che.api.machine.server.wsagent.WsAgentLauncherImpl.WS_AGENT_PROCESS_START_COMMAND))
.to("rm -rf ~/che && mkdir -p ~/che && unzip -qq /mnt/che/ws-agent.zip -d ~/che/ws-agent && " +
"sudo chown -R $(id -u -n) /projects && " +
"sudo sh -c \"chown -R $(id -u -n) /projects || true\" && " +
"export JPDA_ADDRESS=\"4403\" && ~/che/ws-agent/bin/catalina.sh jpda run");
bindConstant().annotatedWith(Names.named(org.eclipse.che.plugin.docker.machine.DockerMachineImplTerminalLauncher.START_TERMINAL_COMMAND))
.to("mkdir -p ~/che " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected void configureServlets() {

filter("/*").through(CorsFilter.class, corsFilterParams);

filter("/api/*").through(org.eclipse.che.api.local.filters.WsMasterEnvironmentInitializationFilter.class);
filter("/api/*").through(org.eclipse.che.api.local.filters.EnvironmentInitializationFilter.class);
serveRegex("^/api((?!(/(ws|eventbus)($|/.*)))/.*)").with(org.eclipse.che.api.local.CheGuiceEverrestServlet.class);
install(new org.eclipse.che.swagger.deploy.BasicSwaggerConfigurationModule());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.eclipse.che.dto.server.DtoFactory;
import org.everrest.core.ObjectFactory;
import org.everrest.core.ResourceBinder;
import org.everrest.core.resource.AbstractResourceDescriptor;
import org.everrest.core.resource.ResourceDescriptor;
import org.everrest.services.RestServicesList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -85,11 +85,11 @@ private ApiInfo readApiInfo() throws ServerException {
public RestServicesList.RootResourcesList listJSON(@Context ServletContext context) {
ResourceBinder binder = (ResourceBinder)context.getAttribute(ResourceBinder.class.getName());
return new RestServicesList.RootResourcesList(FluentIterable.from(binder.getResources()).transform(
new Function<ObjectFactory<AbstractResourceDescriptor>, RestServicesList.RootResource>() {
new Function<ObjectFactory<ResourceDescriptor>, RestServicesList.RootResource>() {
@Nullable
@Override
public RestServicesList.RootResource apply(ObjectFactory<AbstractResourceDescriptor> input) {
AbstractResourceDescriptor descriptor = input.getObjectModel();
public RestServicesList.RootResource apply(ObjectFactory<ResourceDescriptor> input) {
ResourceDescriptor descriptor = input.getObjectModel();
return new RestServicesList.RootResource(descriptor.getObjectClass().getName(), //
descriptor.getPathValue().getPath(), //
descriptor.getUriPattern().getRegex());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,11 @@ public static void reset() {

private Subject subject;

private String workspaceName;

private String workspaceId;

private boolean workspaceTemporary;


public EnvironmentContext() {
}

public EnvironmentContext(EnvironmentContext other) {
setSubject(other.getSubject());
setWorkspaceName(other.getWorkspaceName());
setWorkspaceId(other.getWorkspaceId());
setWorkspaceTemporary(other.isWorkspaceTemporary());
}

public Subject getSubject() {
Expand All @@ -74,28 +64,4 @@ public Subject getSubject() {
public void setSubject(Subject subject) {
this.subject = subject;
}

public String getWorkspaceName() {
return workspaceName;
}

public void setWorkspaceName(String workspaceName) {
this.workspaceName = workspaceName;
}

public String getWorkspaceId() {
return workspaceId;
}

public void setWorkspaceId(String workspaceId) {
this.workspaceId = workspaceId;
}

public boolean isWorkspaceTemporary() {
return workspaceTemporary;
}

public void setWorkspaceTemporary(boolean workspaceTemporary) {
this.workspaceTemporary = workspaceTemporary;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ public CheAsynchronousJobPool(EverrestConfiguration everrestConfiguration) {
super(everrestConfiguration);
}

@Override
protected UriBuilder getAsynchronousJobUriBuilder(AsynchronousJob job) {
final String wsId = EnvironmentContext.getCurrent().getWorkspaceId();
if (wsId == null) {
return super.getAsynchronousJobUriBuilder(job);
}
return UriBuilder.fromPath(asynchronousServicePath).path(wsId).path(Long.toString(job.getJobId()));
}

@Override
protected Callable<Object> newCallable(Object resource, Method method, Object[] params) {
return ThreadLocalPropagateContext.wrap((super.newCallable(resource, method, params)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.eclipse.che.api.core.UnauthorizedException;
import org.eclipse.che.dto.server.DtoFactory;
import org.everrest.core.method.MethodInvokerFilter;
import org.everrest.core.resource.GenericMethodResource;
import org.everrest.core.resource.GenericResourceMethod;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
Expand All @@ -33,7 +33,7 @@
*/
public abstract class CheMethodInvokerFilter implements MethodInvokerFilter {
@Override
public void accept(GenericMethodResource genericMethodResource, Object[] arguments) throws WebApplicationException {
public void accept(GenericResourceMethod genericMethodResource, Object[] arguments) throws WebApplicationException {
try {
filter(genericMethodResource, arguments);
} catch (ApiException exception) {
Expand Down Expand Up @@ -83,11 +83,11 @@ else if (exception instanceof BadRequestException) {
* Check does supplied method can be invoked.
*
* @param genericMethodResource
* See {@link GenericMethodResource}
* See {@link GenericResourceMethod}
* @param arguments
* actual method arguments that were created from request
* @throws ApiException
* if method can not be invoked cause current environment context, e.g. for current user, with current request attributes, etc.
*/
protected abstract void filter(GenericMethodResource genericMethodResource, Object[] arguments) throws ApiException;
protected abstract void filter(GenericResourceMethod genericMethodResource, Object[] arguments) throws ApiException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.everrest.core.Filter;
import org.everrest.core.GenericContainerResponse;
import org.everrest.core.ResponseFilter;
import org.everrest.core.impl.ApplicationContextImpl;

import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.EntityTag;
Expand Down Expand Up @@ -55,7 +54,7 @@ public enum EntityType {
* Filter the given container response
*
* @param containerResponse
* the reponse to use
* the response to use
*/
public void doFilter(GenericContainerResponse containerResponse) {

Expand All @@ -73,7 +72,7 @@ public void doFilter(GenericContainerResponse containerResponse) {
}

// Get the request
ApplicationContext applicationContext = ApplicationContextImpl.getCurrent();
ApplicationContext applicationContext = ApplicationContext.getCurrent();
Request request = applicationContext.getRequest();

// manage only GET requests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.everrest.core.Filter;
import org.everrest.core.GenericContainerResponse;
import org.everrest.core.ResponseFilter;
import org.everrest.core.impl.ApplicationContextImpl;

import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
Expand All @@ -33,13 +32,13 @@ public class EverrestDownloadFileResponseFilter extends DownloadFileResponseFilt
* Filter the given container response.
*
* @param containerResponse
* the reponse to use
* the response to use
*/
public void doFilter(GenericContainerResponse containerResponse) {
containerResponse.getResponse();

// Get the request
ApplicationContext applicationContext = ApplicationContextImpl.getCurrent();
ApplicationContext applicationContext = ApplicationContext.getCurrent();
Request request = applicationContext.getRequest();

// Apply header if all if correct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.che.everrest;

import com.google.common.base.MoreObjects;
import com.google.common.util.concurrent.ThreadFactoryBuilder;

import org.eclipse.che.commons.env.EnvironmentContext;
import org.eclipse.che.commons.subject.Subject;
import org.everrest.core.DependencySupplier;
Expand All @@ -18,6 +21,8 @@
import org.everrest.core.impl.EverrestConfiguration;
import org.everrest.core.impl.EverrestProcessor;
import org.everrest.core.impl.ProviderBinder;
import org.everrest.core.impl.RequestDispatcher;
import org.everrest.core.impl.RequestHandlerImpl;
import org.everrest.core.impl.provider.json.JsonException;
import org.everrest.core.tools.SimplePrincipal;
import org.everrest.core.tools.SimpleSecurityContext;
Expand Down Expand Up @@ -47,14 +52,10 @@
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicLong;

import static javax.websocket.server.ServerEndpointConfig.Builder.create;
import static javax.websocket.server.ServerEndpointConfig.Configurator;

import com.google.common.base.MoreObjects;

/**
* @author andrew00x
*/
Expand All @@ -66,8 +67,6 @@ public class ServerContainerInitializeListener implements ServletContextListener
public static final String EXECUTOR_ATTRIBUTE = "everrest.Executor";
public static final String SECURITY_CONTEXT = SecurityContext.class.getName();

private static final AtomicLong sequence = new AtomicLong(1);

private WebApplicationDeclaredRoles webApplicationDeclaredRoles;
private EverrestConfiguration everrestConfiguration;
private ServerEndpointConfig wsServerEndpointConfig;
Expand Down Expand Up @@ -161,9 +160,10 @@ protected EverrestProcessor getEverrestProcessor(ServletContext servletContext)
final DependencySupplier dependencies = (DependencySupplier)servletContext.getAttribute(DependencySupplier.class.getName());
final ResourceBinder resources = (ResourceBinder)servletContext.getAttribute(ResourceBinder.class.getName());
final ProviderBinder providers = (ProviderBinder)servletContext.getAttribute(ApplicationProviderBinder.class.getName());
final EverrestConfiguration copy = getEverrestConfiguration(servletContext);
copy.setProperty(EverrestConfiguration.METHOD_INVOKER_DECORATOR_FACTORY, WebSocketMethodInvokerDecoratorFactory.class.getName());
return new EverrestProcessor(resources, providers, dependencies, copy, null);
final EverrestConfiguration copyOfEverrestConfiguration = new EverrestConfiguration(getEverrestConfiguration(servletContext));
copyOfEverrestConfiguration.setProperty(EverrestConfiguration.METHOD_INVOKER_DECORATOR_FACTORY, WebSocketMethodInvokerDecoratorFactory.class.getName());
final RequestHandlerImpl requestHandler = new RequestHandlerImpl(new RequestDispatcher(resources), providers);
return new EverrestProcessor(copyOfEverrestConfiguration, dependencies, requestHandler, null);
}

protected EverrestConfiguration getEverrestConfiguration(ServletContext servletContext) {
Expand All @@ -172,15 +172,9 @@ protected EverrestConfiguration getEverrestConfiguration(ServletContext servletC

protected ExecutorService createExecutor(final ServletContext servletContext) {
final EverrestConfiguration everrestConfiguration = getEverrestConfiguration(servletContext);
return Executors.newFixedThreadPool(everrestConfiguration.getAsynchronousPoolSize(), new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
final Thread t =
new Thread(r, "everrest.WSConnection." + servletContext.getServletContextName() + sequence.getAndIncrement());
t.setDaemon(true);
return t;
}
});
final String threadNameFormat = "everrest.WSConnection." + servletContext.getServletContextName() + "-%d";
return Executors.newFixedThreadPool(everrestConfiguration.getAsynchronousPoolSize(),
new ThreadFactoryBuilder().setNameFormat(threadNameFormat).setDaemon(true).build());
}

protected SecurityContext createSecurityContext(final HandshakeRequest req) {
Expand Down
Loading

0 comments on commit 1dfa46c

Please sign in to comment.