Search in sources :

Example 1 with RequestCallback

use of org.eclipse.che.ide.websocket.rest.RequestCallback in project che by eclipse.

the class AbstractMessageBus method onMessageReceived.

/** {@inheritDoc} */
@Override
public void onMessageReceived(MessageReceivedEvent event) {
    Message message = parseMessage(event.getMessage());
    // as it might be disallowed when processing actually takes place.
    if (message.getResponseCode() == 202) {
        return;
    }
    //TODO Should be revised to remove
    List<Pair> headers = message.getHeaders().toList();
    if (headers != null) {
        for (Pair header : headers) {
            if (HTTPHeader.LOCATION.equals(header.getName()) && header.getValue().contains("async/")) {
                return;
            }
        }
    }
    if (getChannel(message) != null) {
        // this is a message received by subscription
        processSubscriptionMessage(message);
    } else {
        String uuid = message.getStringField(MessageBuilder.UUID_FIELD);
        ReplyHandler replyCallback = replyCallbackMap.remove(uuid);
        if (replyCallback != null) {
            replyCallback.onReply(message.getBody());
        } else {
            RequestCallback requestCallback = requestCallbackMap.remove(uuid);
            if (requestCallback != null) {
                requestCallback.onReply(message);
            }
        }
    }
}
Also used : ReplyHandler(org.eclipse.che.ide.websocket.events.ReplyHandler) RequestCallback(org.eclipse.che.ide.websocket.rest.RequestCallback) Pair(org.eclipse.che.ide.websocket.rest.Pair)

Example 2 with RequestCallback

use of org.eclipse.che.ide.websocket.rest.RequestCallback 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

RequestCallback (org.eclipse.che.ide.websocket.rest.RequestCallback)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 List (java.util.List)1 Map (java.util.Map)1 CopyOptions (org.eclipse.che.api.project.shared.dto.CopyOptions)1 ItemReference (org.eclipse.che.api.project.shared.dto.ItemReference)1 MoveOptions (org.eclipse.che.api.project.shared.dto.MoveOptions)1 SourceEstimation (org.eclipse.che.api.project.shared.dto.SourceEstimation)1 TreeElement (org.eclipse.che.api.project.shared.dto.TreeElement)1 Promise (org.eclipse.che.api.promises.client.Promise)1 AsyncPromiseHelper.createFromAsyncRequest (org.eclipse.che.api.promises.client.callback.AsyncPromiseHelper.createFromAsyncRequest)1 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)1 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)1 SourceStorageDto (org.eclipse.che.api.workspace.shared.dto.SourceStorageDto)1 MimeType (org.eclipse.che.ide.MimeType)1