use of org.eclipse.che.ide.websocket.WebSocketException in project che by eclipse.
the class WorkspaceEventsHandler method subscribeToWorkspaceStatusEvents.
private void subscribeToWorkspaceStatusEvents(final WorkspaceDto workspace) {
final Link workspaceEventsLink = workspace.getLink(LINK_REL_GET_WORKSPACE_EVENTS_CHANNEL);
if (workspaceEventsLink == null) {
//should never be
notificationManager.notify(locale.workspaceSubscribeOnEventsFailed(), FAIL, EMERGE_MODE);
Log.error(getClass(), "Link " + LINK_REL_GET_WORKSPACE_EVENTS_CHANNEL + " not found in workspace links. So events will be not handle");
return;
}
workspaceStatusChannel = workspaceEventsLink.getParameter("channel").getDefaultValue();
if (isNullOrEmpty(workspaceStatusChannel)) {
//should never be
notificationManager.notify(locale.workspaceSubscribeOnEventsFailed(), FAIL, EMERGE_MODE);
Log.error(getClass(), "Channel for handling Workspace events not provide. So events will be not handle");
return;
}
try {
workspaceStatusSubscriptionHandler = new WorkspaceStatusSubscriptionHandler(workspace);
messageBus.subscribe(workspaceStatusChannel, workspaceStatusSubscriptionHandler);
} catch (WebSocketException exception) {
Log.error(getClass(), exception);
}
}
use of org.eclipse.che.ide.websocket.WebSocketException in project che by eclipse.
the class AbstractDebugger method addHandlers.
private void addHandlers(final MessageBusProvider messageBusProvider) {
eventBus.addHandler(WsAgentStateEvent.TYPE, new WsAgentStateHandler() {
@Override
public void onWsAgentStarted(WsAgentStateEvent event) {
messageBus = messageBusProvider.getMachineMessageBus();
if (!isConnected()) {
return;
}
Promise<DebugSessionDto> promise = service.getSessionInfo(debugSessionDto.getId());
promise.then(new Operation<DebugSessionDto>() {
@Override
public void apply(DebugSessionDto arg) throws OperationException {
debuggerManager.setActiveDebugger(AbstractDebugger.this);
setDebugSession(arg);
DebuggerInfo debuggerInfo = arg.getDebuggerInfo();
String info = debuggerInfo.getName() + " " + debuggerInfo.getVersion();
String address = debuggerInfo.getHost() + ":" + debuggerInfo.getPort();
DebuggerDescriptor debuggerDescriptor = new DebuggerDescriptor(info, address);
JsPromise<Void> promise = Promises.resolve(null);
for (DebuggerObserver observer : observers) {
observer.onDebuggerAttached(debuggerDescriptor, promise);
}
startCheckingEvents();
}
}).catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
if (!isConnected()) {
invalidateDebugSession();
}
}
});
}
@Override
public void onWsAgentStopped(WsAgentStateEvent event) {
}
});
this.debuggerEventsHandler = new SubscriptionHandler<DebuggerEventDto>(new DebuggerEventUnmarshaller(dtoFactory)) {
@Override
public void onMessageReceived(DebuggerEventDto result) {
if (!isConnected()) {
return;
}
onEventListReceived(result);
}
@Override
public void onErrorReceived(Throwable exception) {
if (!isConnected()) {
return;
}
try {
messageBus.unsubscribe(eventChannel, this);
} catch (WebSocketException e) {
Log.error(AbstractDebugger.class, e);
}
if (exception instanceof ServerException) {
ServerException serverException = (ServerException) exception;
if (HTTPStatus.INTERNAL_ERROR == serverException.getHTTPStatus() && serverException.getMessage() != null && serverException.getMessage().contains("not found")) {
disconnect();
}
}
}
};
}
use of org.eclipse.che.ide.websocket.WebSocketException in project che by eclipse.
the class JavaSearchServiceWS method findUsages.
@Override
public Promise<FindUsagesResponse> findUsages(final FindUsagesRequest request) {
final MessageBus messageBus = provider.getMachineMessageBus();
return createFromAsyncRequest(callback -> {
final MessageBuilder builder = new MessageBuilder(POST, pathToService + "find/usages");
builder.data(dtoFactory.toJson(request)).header(CONTENTTYPE, APPLICATION_JSON).header(ACCEPT, APPLICATION_JSON);
loader.show();
try {
messageBus.send(builder.build(), new RequestCallback<FindUsagesResponse>(unmarshallerFactory.newWSUnmarshaller(FindUsagesResponse.class)) {
@Override
protected void onSuccess(FindUsagesResponse result) {
loader.hide();
callback.onSuccess(result);
}
@Override
protected void onFailure(Throwable exception) {
loader.hide();
callback.onFailure(exception);
}
});
} catch (WebSocketException e) {
loader.hide();
callback.onFailure(e);
}
});
}
use of org.eclipse.che.ide.websocket.WebSocketException in project che by eclipse.
the class MavenMessagesHandler method handleOperations.
private void handleOperations(final DtoFactory factory, final WsAgentStateController wsAgentStateController) {
eventBus.addHandler(WsAgentStateEvent.TYPE, new WsAgentStateHandler() {
@Override
public void onWsAgentStarted(WsAgentStateEvent event) {
wsAgentStateController.getMessageBus().then(new Operation<MessageBus>() {
@Override
public void apply(MessageBus messageBus) throws OperationException {
try {
handleMavenServerEvents(messageBus);
handleMavenArchetype(messageBus);
} catch (WebSocketException e) {
dependencyResolver.hide();
Log.error(getClass(), e);
}
}
});
}
@Override
public void onWsAgentStopped(WsAgentStateEvent event) {
dependencyResolver.hide();
}
});
eventBus.addHandler(WorkspaceStoppedEvent.TYPE, new WorkspaceStoppedEvent.Handler() {
@Override
public void onWorkspaceStopped(WorkspaceStoppedEvent event) {
dependencyResolver.hide();
}
});
}
use of org.eclipse.che.ide.websocket.WebSocketException in project che by eclipse.
the class ProjectServiceClientImpl method importProject.
/** {@inheritDoc} */
@Override
public Promise<Void> importProject(final Path path, final SourceStorageDto source) {
return createFromAsyncRequest(callback -> {
final String url = PROJECT + IMPORT + path(path.toString());
final Message message = new MessageBuilder(POST, url).data(dtoFactory.toJson(source)).header(CONTENTTYPE, APPLICATION_JSON).build();
wsAgentStateController.getMessageBus().then(messageBus -> {
try {
messageBus.send(message, new RequestCallback<Void>() {
@Override
protected void onSuccess(Void result) {
callback.onSuccess(result);
}
@Override
protected void onFailure(Throwable exception) {
callback.onFailure(exception);
}
});
} catch (WebSocketException e) {
callback.onFailure(e);
}
}).catchError(error -> {
callback.onFailure(error.getCause());
});
});
}
Aggregations