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);
}
}
}
}
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());
});
});
}
Aggregations