-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
JavaClasspathServiceClientImpl.java
76 lines (64 loc) · 2.96 KB
/
JavaClasspathServiceClientImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*******************************************************************************
* Copyright (c) 2012-2016 Codenvy, S.A.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Codenvy, S.A. - initial API and implementation
*******************************************************************************/
package org.eclipse.che.ide.ext.java.client.dependenciesupdater;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.ide.api.machine.WsAgentStateController;
import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.ext.java.shared.dto.ClassPathBuilderResult;
import org.eclipse.che.ide.websocket.Message;
import org.eclipse.che.ide.websocket.MessageBuilder;
import org.eclipse.che.ide.websocket.MessageBus;
import org.eclipse.che.ide.websocket.WebSocketException;
import org.eclipse.che.ide.websocket.rest.RequestCallback;
import javax.validation.constraints.NotNull;
import static com.google.gwt.http.client.RequestBuilder.GET;
import static org.eclipse.che.ide.MimeType.APPLICATION_JSON;
import static org.eclipse.che.ide.rest.HTTPHeader.ACCEPT;
/**
* Implementation of {@link JavaClasspathServiceClient}.
*
* @author Artem Zatsarynnyi
*/
@Singleton
public class JavaClasspathServiceClientImpl implements JavaClasspathServiceClient {
private final WsAgentStateController wsAgentStateController;
private final String baseHttpUrl;
@Inject
protected JavaClasspathServiceClientImpl(AppContext appContext,
WsAgentStateController wsAgentStateController) {
this.wsAgentStateController = wsAgentStateController;
this.baseHttpUrl = "/java/";
}
/** {@inheritDoc} */
@Override
public void updateDependencies(String projectPath, RequestCallback<ClassPathBuilderResult> callback) {
final String requestUrl = baseHttpUrl + "/classpath/update?projectpath=" + projectPath;
MessageBuilder builder = new MessageBuilder(GET, requestUrl);
builder.header(ACCEPT, APPLICATION_JSON);
Message message = builder.build();
sendMessageToWS(message, callback);
}
private void sendMessageToWS(final @NotNull Message message, final @NotNull RequestCallback<?> callback) {
wsAgentStateController.getMessageBus().then(new Operation<MessageBus>() {
@Override
public void apply(MessageBus arg) throws OperationException {
try {
arg.send(message, callback);
} catch (WebSocketException e) {
throw new OperationException(e.getMessage(), e);
}
}
});
}
}