Skip to content

Commit 88a1fa4

Browse files
author
Vitalii Parfonov
authored
Base URL to the master will be provided by AppContext (eclipse-che#3658)
Add ability to take base endpoint to thews master from AppContext Mark RestContextProvider ad deprecated Signed-off-by: Vitalii Parfonov <vparfonov@codenvy.com>
1 parent a1ace7a commit 88a1fa4

25 files changed

Lines changed: 124 additions & 97 deletions

File tree

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/app/AppContext.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ public interface AppContext {
203203
*/
204204
void setWorkspace(Workspace workspace);
205205

206-
207206
ActiveRuntime getActiveRuntime();
208207

208+
209+
String getMasterEndpoint();
210+
211+
212+
String getDevAgentEndpoint();
209213
}

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/importer/AbstractImporter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ public Promise<Project> apply(PromiseError error) throws FunctionException {
7575
* @return returns instance of Promise
7676
*/
7777
protected abstract Promise<Project> importProject(Path path, SourceStorage sourceStorage);
78+
7879
}

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/machine/MachineServiceClientImpl.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,11 @@
1212

1313
import com.google.inject.Inject;
1414

15-
import org.eclipse.che.api.core.model.machine.Command;
16-
import org.eclipse.che.api.machine.shared.dto.CommandDto;
1715
import org.eclipse.che.api.machine.shared.dto.MachineDto;
18-
import org.eclipse.che.api.machine.shared.dto.MachineProcessDto;
1916
import org.eclipse.che.api.promises.client.Promise;
20-
import org.eclipse.che.commons.annotation.Nullable;
21-
import org.eclipse.che.ide.dto.DtoFactory;
17+
import org.eclipse.che.ide.api.app.AppContext;
2218
import org.eclipse.che.ide.rest.AsyncRequestFactory;
2319
import org.eclipse.che.ide.rest.DtoUnmarshallerFactory;
24-
import org.eclipse.che.ide.rest.RestContext;
2520
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
2621

2722
import javax.validation.constraints.NotNull;
@@ -44,14 +39,14 @@ public class MachineServiceClientImpl implements MachineServiceClient {
4439
private final String baseHttpUrl;
4540

4641
@Inject
47-
protected MachineServiceClientImpl(@RestContext String restContext,
42+
protected MachineServiceClientImpl(AppContext appContext,
4843
DtoUnmarshallerFactory dtoUnmarshallerFactory,
4944
AsyncRequestFactory asyncRequestFactory,
5045
LoaderFactory loaderFactory) {
5146
this.dtoUnmarshallerFactory = dtoUnmarshallerFactory;
5247
this.asyncRequestFactory = asyncRequestFactory;
5348
this.loaderFactory = loaderFactory;
54-
this.baseHttpUrl = restContext + "/workspace/";
49+
this.baseHttpUrl = appContext.getMasterEndpoint() + "/workspace/";
5550
}
5651

5752
@Override

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/machine/RecipeServiceClientImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
import org.eclipse.che.api.machine.shared.dto.recipe.RecipeUpdate;
1818
import org.eclipse.che.api.promises.client.Promise;
1919
import org.eclipse.che.commons.annotation.Nullable;
20+
import org.eclipse.che.ide.api.app.AppContext;
2021
import org.eclipse.che.ide.rest.AsyncRequestFactory;
2122
import org.eclipse.che.ide.rest.DtoUnmarshallerFactory;
22-
import org.eclipse.che.ide.rest.RestContext;
2323
import org.eclipse.che.ide.rest.StringUnmarshaller;
2424
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
2525

@@ -47,14 +47,14 @@ public class RecipeServiceClientImpl implements RecipeServiceClient {
4747
private final String baseHttpUrl;
4848

4949
@Inject
50-
protected RecipeServiceClientImpl(@RestContext String restContext,
50+
protected RecipeServiceClientImpl(AppContext appContext,
5151
DtoUnmarshallerFactory dtoUnmarshallerFactory,
5252
AsyncRequestFactory asyncRequestFactory,
5353
LoaderFactory loaderFactory) {
5454
this.dtoUnmarshallerFactory = dtoUnmarshallerFactory;
5555
this.asyncRequestFactory = asyncRequestFactory;
5656
this.loaderFactory = loaderFactory;
57-
this.baseHttpUrl = restContext + "/recipe";
57+
this.baseHttpUrl = appContext.getMasterEndpoint() + "/recipe";
5858
}
5959

6060
@Override

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/project/ProjectTemplateServiceClientImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
import com.google.inject.Inject;
1414

1515
import org.eclipse.che.api.project.templates.shared.dto.ProjectTemplateDescriptor;
16-
import org.eclipse.che.ide.api.project.ProjectTemplateServiceClient;
16+
import org.eclipse.che.ide.api.app.AppContext;
1717
import org.eclipse.che.ide.rest.AsyncRequestCallback;
1818
import org.eclipse.che.ide.rest.AsyncRequestFactory;
1919
import org.eclipse.che.ide.rest.AsyncRequestLoader;
20-
import org.eclipse.che.ide.rest.RestContext;
2120
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
2221

2322
import javax.validation.constraints.NotNull;
@@ -39,13 +38,13 @@ public class ProjectTemplateServiceClientImpl implements ProjectTemplateServiceC
3938
private String baseUrl;
4039

4140
@Inject
42-
protected ProjectTemplateServiceClientImpl(@RestContext String restContext,
41+
protected ProjectTemplateServiceClientImpl(AppContext appContext,
4342
AsyncRequestFactory asyncRequestFactory,
4443
LoaderFactory loaderFactory) {
4544
this.asyncRequestFactory = asyncRequestFactory;
4645
this.loader = loaderFactory.newLoader();
4746

48-
baseUrl = restContext + "/project-template/";
47+
baseUrl = appContext.getMasterEndpoint() + "/project-template/";
4948
}
5049

5150
@Override

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/ssh/SshServiceClientImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
import org.eclipse.che.api.ssh.shared.dto.GenerateSshPairRequest;
1717
import org.eclipse.che.api.ssh.shared.dto.SshPairDto;
1818
import org.eclipse.che.ide.MimeType;
19+
import org.eclipse.che.ide.api.app.AppContext;
1920
import org.eclipse.che.ide.dto.DtoFactory;
2021
import org.eclipse.che.ide.rest.AsyncRequestFactory;
2122
import org.eclipse.che.ide.rest.DtoUnmarshallerFactory;
2223
import org.eclipse.che.ide.rest.HTTPHeader;
23-
import org.eclipse.che.ide.rest.RestContext;
2424

2525
import java.util.List;
2626

@@ -36,14 +36,14 @@ public class SshServiceClientImpl implements SshServiceClient {
3636
private final String sshApi;
3737

3838
@Inject
39-
protected SshServiceClientImpl(@RestContext String baseUrl,
39+
protected SshServiceClientImpl(AppContext appContext,
4040
DtoFactory dtoFactory,
4141
AsyncRequestFactory asyncRequestFactory,
4242
DtoUnmarshallerFactory unmarshallerFactory) {
4343
this.dtoFactory = dtoFactory;
4444
this.asyncRequestFactory = asyncRequestFactory;
4545
this.unmarshallerFactory = unmarshallerFactory;
46-
this.sshApi = baseUrl + "/ssh";
46+
this.sshApi = appContext.getMasterEndpoint() + "/ssh";
4747
}
4848

4949
/**

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/context/AppContextImpl.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.google.inject.Provider;
1717
import com.google.inject.Singleton;
1818
import com.google.web.bindery.event.shared.EventBus;
19+
1920
import org.eclipse.che.api.core.model.workspace.Workspace;
2021
import org.eclipse.che.api.factory.shared.dto.FactoryDto;
2122
import org.eclipse.che.api.promises.client.Operation;
@@ -486,10 +487,35 @@ public void apply(Void arg) throws OperationException {
486487
public void onWindowClosed(WindowActionEvent event) {
487488
}
488489

490+
@Override
491+
public String getMasterEndpoint() {
492+
String fromUrl = this.browserQueryFieldRenderer.getParameterFromURLByName("master");
493+
if(fromUrl == null || fromUrl.isEmpty())
494+
return masterFromIDEConfig();
495+
else
496+
return fromUrl;
497+
}
498+
499+
@Override
500+
public String getDevAgentEndpoint() {
501+
String fromUrl = this.browserQueryFieldRenderer.getParameterFromURLByName("agent");
502+
if(fromUrl == null || fromUrl.isEmpty())
503+
return runtime.getDevMachine().getWsAgentBaseUrl();
504+
else
505+
return fromUrl;
506+
}
489507

490508
@Override
491509
public ActiveRuntime getActiveRuntime() {
492510
return runtime;
493511
}
494512

513+
514+
private static native String masterFromIDEConfig() /*-{
515+
if ($wnd.IDE && $wnd.IDE.config) {
516+
return $wnd.IDE.config.restContext;
517+
} else {
518+
return null;
519+
}
520+
}-*/;
495521
}

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/core/CoreGinModule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ protected void configure() {
122122

123123
bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
124124

125+
//TODO: don't remove binding until not fix Codenvy and other packaging
125126
bind(String.class).annotatedWith(RestContext.class).toProvider(RestContextProvider.class).in(Singleton.class);
126127

127128
install(new GinFactoryModuleBuilder().build(LoaderFactory.class));

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/oauth/OAuthApiModule.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import com.google.gwt.inject.client.multibindings.GinMultibinder;
1515
import com.google.inject.Singleton;
1616

17-
import org.eclipse.che.ide.api.auth.OAuthServiceClient;
18-
import org.eclipse.che.ide.api.auth.OAuthServiceClientImpl;
1917
import org.eclipse.che.ide.api.oauth.OAuth2Authenticator;
2018
import org.eclipse.che.ide.api.oauth.OAuth2AuthenticatorRegistry;
2119

@@ -28,7 +26,6 @@ public class OAuthApiModule extends AbstractGinModule {
2826

2927
@Override
3028
protected void configure() {
31-
bind(OAuthServiceClient.class).to(OAuthServiceClientImpl.class).in(Singleton.class);
3229

3330
GinMultibinder.newSetBinder(binder(), OAuth2Authenticator.class).addBinding().to(DefaultOAuthAuthenticatorImpl.class);
3431

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/preferences/PreferencesServiceClientImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import com.google.inject.Inject;
1414

1515
import org.eclipse.che.api.promises.client.Promise;
16+
import org.eclipse.che.ide.api.app.AppContext;
1617
import org.eclipse.che.ide.api.user.PreferencesServiceClient;
1718
import org.eclipse.che.ide.json.JsonHelper;
1819
import org.eclipse.che.ide.rest.AsyncRequestFactory;
19-
import org.eclipse.che.ide.rest.RestContext;
2020
import org.eclipse.che.ide.rest.StringMapUnmarshaller;
2121
import org.eclipse.che.ide.ui.loaders.request.LoaderFactory;
2222

@@ -38,16 +38,18 @@ public class PreferencesServiceClientImpl implements PreferencesServiceClient {
3838
private final AsyncRequestFactory asyncRequestFactory;
3939

4040
@Inject
41-
protected PreferencesServiceClientImpl(@RestContext String restContext,
41+
protected PreferencesServiceClientImpl(AppContext appContext,
4242
LoaderFactory loaderFactory,
4343
AsyncRequestFactory asyncRequestFactory) {
4444
this.loaderFactory = loaderFactory;
4545
this.asyncRequestFactory = asyncRequestFactory;
46-
PREFERENCES_PATH = restContext + "/preferences";
46+
PREFERENCES_PATH = appContext.getMasterEndpoint() + "/preferences";
4747
}
4848

4949
@Override
5050
public Promise<Map<String, String>> getPreferences() {
51+
52+
5153
return asyncRequestFactory.createGetRequest(PREFERENCES_PATH)
5254
.header(ACCEPT, APPLICATION_JSON)
5355
.header(CONTENT_TYPE, APPLICATION_JSON)

0 commit comments

Comments
 (0)