use of org.eclipse.che.ide.websocket.rest.exceptions.ServerException 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.rest.exceptions.ServerException in project che by eclipse.
the class RequestCallback method onReply.
/**
* Perform actions when response message was received.
*
* @param message
* message
*/
public void onReply(Message message) {
if (loader != null) {
loader.hide();
}
final String uuid = message.getStringField(MessageBuilder.UUID_FIELD);
if (message.getResponseCode() == HTTPStatus.UNAUTHORIZED) {
UnauthorizedException exception = new UnauthorizedException(message);
if (statusHandler != null) {
statusHandler.requestError(uuid, exception);
}
onFailure(exception);
return;
}
if (isSuccessful(message)) {
try {
if (unmarshaller != null) {
unmarshaller.unmarshal(message);
payload = unmarshaller.getPayload();
}
if (statusHandler != null) {
statusHandler.requestFinished(uuid);
}
onSuccess(payload);
} catch (UnmarshallerException e) {
if (statusHandler != null) {
statusHandler.requestError(uuid, e);
}
onFailure(e);
}
} else {
ServerException exception = new ServerException(message);
if (statusHandler != null) {
statusHandler.requestError(uuid, exception);
}
onFailure(exception);
}
}
use of org.eclipse.che.ide.websocket.rest.exceptions.ServerException in project che by eclipse.
the class SubscriptionHandler method onMessage.
/**
* Perform actions when {@link Message} was received.
*
* @param message
* received {@link Message}
*/
public void onMessage(Message message) {
if (isSuccessful(message)) {
try {
if (unmarshaller != null) {
unmarshaller.unmarshal(message);
payload = unmarshaller.getPayload();
}
onMessageReceived(payload);
} catch (UnmarshallerException e) {
onErrorReceived(e);
}
} else {
onErrorReceived(new ServerException(message));
}
}
Aggregations