Search in sources :

Example 1 with WebSocketException

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);
    }
}
Also used : WebSocketException(org.eclipse.che.ide.websocket.WebSocketException) Link(org.eclipse.che.api.core.rest.shared.dto.Link)

Example 2 with WebSocketException

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();
                }
            }
        }
    };
}
Also used : DebuggerInfo(org.eclipse.che.api.debug.shared.model.DebuggerInfo) ServerException(org.eclipse.che.ide.websocket.rest.exceptions.ServerException) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException) WsAgentStateHandler(org.eclipse.che.ide.api.machine.events.WsAgentStateHandler) DebuggerDescriptor(org.eclipse.che.ide.debug.DebuggerDescriptor) JsPromise(org.eclipse.che.api.promises.client.js.JsPromise) Operation(org.eclipse.che.api.promises.client.Operation) JsPromise(org.eclipse.che.api.promises.client.js.JsPromise) Promise(org.eclipse.che.api.promises.client.Promise) DebuggerEventDto(org.eclipse.che.api.debug.shared.dto.event.DebuggerEventDto) JsPromiseError(org.eclipse.che.api.promises.client.js.JsPromiseError) PromiseError(org.eclipse.che.api.promises.client.PromiseError) DebugSessionDto(org.eclipse.che.api.debug.shared.dto.DebugSessionDto) WsAgentStateEvent(org.eclipse.che.ide.api.machine.events.WsAgentStateEvent) DebuggerObserver(org.eclipse.che.ide.debug.DebuggerObserver) OperationException(org.eclipse.che.api.promises.client.OperationException)

Example 3 with WebSocketException

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);
        }
    });
}
Also used : MessageBus(org.eclipse.che.ide.websocket.MessageBus) FindUsagesResponse(org.eclipse.che.ide.ext.java.shared.dto.search.FindUsagesResponse) MessageBuilder(org.eclipse.che.ide.websocket.MessageBuilder) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException)

Example 4 with WebSocketException

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();
        }
    });
}
Also used : MessageBus(org.eclipse.che.ide.websocket.MessageBus) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException) WsAgentStateHandler(org.eclipse.che.ide.api.machine.events.WsAgentStateHandler) Operation(org.eclipse.che.api.promises.client.Operation) WsAgentStateEvent(org.eclipse.che.ide.api.machine.events.WsAgentStateEvent) WorkspaceStoppedEvent(org.eclipse.che.ide.api.workspace.event.WorkspaceStoppedEvent)

Example 5 with WebSocketException

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());
        });
    });
}
Also used : AsyncPromiseHelper.createFromAsyncRequest(org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest) AsyncRequestFactory(org.eclipse.che.ide.rest.AsyncRequestFactory) NewProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto) Inject(com.google.inject.Inject) RequestCallback(org.eclipse.che.ide.websocket.rest.RequestCallback) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) DELETE(com.google.gwt.http.client.RequestBuilder.DELETE) Promise(org.eclipse.che.api.promises.client.Promise) AppContext(org.eclipse.che.ide.api.app.AppContext) Map(java.util.Map) URL(com.google.gwt.http.client.URL) Message(org.eclipse.che.ide.websocket.Message) MessageBuilder(org.eclipse.che.ide.websocket.MessageBuilder) CONTENT_TYPE(org.eclipse.che.ide.rest.HTTPHeader.CONTENT_TYPE) DtoUnmarshallerFactory(org.eclipse.che.ide.rest.DtoUnmarshallerFactory) DtoFactory(org.eclipse.che.ide.dto.DtoFactory) LoaderFactory(org.eclipse.che.ide.ui.loaders.request.LoaderFactory) CONTENTTYPE(org.eclipse.che.ide.rest.HTTPHeader.CONTENTTYPE) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) APPLICATION_JSON(org.eclipse.che.ide.MimeType.APPLICATION_JSON) WsAgentStateController(org.eclipse.che.ide.api.machine.WsAgentStateController) StringUnmarshaller(org.eclipse.che.ide.rest.StringUnmarshaller) SourceStorageDto(org.eclipse.che.api.workspace.shared.dto.SourceStorageDto) TreeElement(org.eclipse.che.api.project.shared.dto.TreeElement) MoveOptions(org.eclipse.che.api.project.shared.dto.MoveOptions) PUT(com.google.gwt.http.client.RequestBuilder.PUT) ItemReference(org.eclipse.che.api.project.shared.dto.ItemReference) POST(com.google.gwt.http.client.RequestBuilder.POST) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException) List(java.util.List) CopyOptions(org.eclipse.che.api.project.shared.dto.CopyOptions) MimeType(org.eclipse.che.ide.MimeType) ACCEPT(org.eclipse.che.ide.rest.HTTPHeader.ACCEPT) SourceEstimation(org.eclipse.che.api.project.shared.dto.SourceEstimation) Path(org.eclipse.che.ide.resource.Path) UrlBuilder(org.eclipse.che.ide.rest.UrlBuilder) Message(org.eclipse.che.ide.websocket.Message) MessageBuilder(org.eclipse.che.ide.websocket.MessageBuilder) RequestCallback(org.eclipse.che.ide.websocket.rest.RequestCallback) WebSocketException(org.eclipse.che.ide.websocket.WebSocketException)

Aggregations

WebSocketException (org.eclipse.che.ide.websocket.WebSocketException)7 MessageBuilder (org.eclipse.che.ide.websocket.MessageBuilder)3 MessageBus (org.eclipse.che.ide.websocket.MessageBus)3 List (java.util.List)2 ItemReference (org.eclipse.che.api.project.shared.dto.ItemReference)2 Operation (org.eclipse.che.api.promises.client.Operation)2 OperationException (org.eclipse.che.api.promises.client.OperationException)2 Promise (org.eclipse.che.api.promises.client.Promise)2 WsAgentStateEvent (org.eclipse.che.ide.api.machine.events.WsAgentStateEvent)2 WsAgentStateHandler (org.eclipse.che.ide.api.machine.events.WsAgentStateHandler)2 Message (org.eclipse.che.ide.websocket.Message)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 DELETE (com.google.gwt.http.client.RequestBuilder.DELETE)1 POST (com.google.gwt.http.client.RequestBuilder.POST)1 PUT (com.google.gwt.http.client.RequestBuilder.PUT)1 URL (com.google.gwt.http.client.URL)1 Inject (com.google.inject.Inject)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Link (org.eclipse.che.api.core.rest.shared.dto.Link)1