Search in sources :

Example 1 with UnmarshallerException

use of org.eclipse.che.ide.commons.exception.UnmarshallerException 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);
    }
}
Also used : ServerException(org.eclipse.che.ide.websocket.rest.exceptions.ServerException) UnauthorizedException(org.eclipse.che.ide.websocket.rest.exceptions.UnauthorizedException) UnmarshallerException(org.eclipse.che.ide.commons.exception.UnmarshallerException)

Example 2 with UnmarshallerException

use of org.eclipse.che.ide.commons.exception.UnmarshallerException 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));
    }
}
Also used : ServerException(org.eclipse.che.ide.websocket.rest.exceptions.ServerException) UnmarshallerException(org.eclipse.che.ide.commons.exception.UnmarshallerException)

Example 3 with UnmarshallerException

use of org.eclipse.che.ide.commons.exception.UnmarshallerException in project che by eclipse.

the class DebuggerEventUnmarshaller method unmarshal.

@Override
public void unmarshal(Message response) throws UnmarshallerException {
    JSONObject jsonObject = JSONParser.parseStrict(response.getBody()).isObject();
    if (jsonObject == null) {
        return;
    }
    if (jsonObject.containsKey("type")) {
        String type = jsonObject.get("type").isString().stringValue();
        TYPE eventType = TYPE.valueOf(type);
        switch(eventType) {
            case SUSPEND:
                event = dtoFactory.createDtoFromJson(jsonObject.toString(), SuspendEventDto.class);
                break;
            case DISCONNECT:
                event = dtoFactory.createDtoFromJson(jsonObject.toString(), DisconnectEventDto.class);
                break;
            case BREAKPOINT_ACTIVATED:
                event = dtoFactory.createDtoFromJson(jsonObject.toString(), BreakpointActivatedEventDto.class);
                break;
            default:
                throw new UnmarshallerException("Can't parse response.", new IllegalArgumentException("Unknown debug event type: " + eventType));
        }
    }
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) SuspendEventDto(org.eclipse.che.api.debug.shared.dto.event.SuspendEventDto) DisconnectEventDto(org.eclipse.che.api.debug.shared.dto.event.DisconnectEventDto) BreakpointActivatedEventDto(org.eclipse.che.api.debug.shared.dto.event.BreakpointActivatedEventDto) UnmarshallerException(org.eclipse.che.ide.commons.exception.UnmarshallerException) TYPE(org.eclipse.che.api.debug.shared.model.event.DebuggerEvent.TYPE)

Aggregations

UnmarshallerException (org.eclipse.che.ide.commons.exception.UnmarshallerException)3 ServerException (org.eclipse.che.ide.websocket.rest.exceptions.ServerException)2 JSONObject (com.google.gwt.json.client.JSONObject)1 BreakpointActivatedEventDto (org.eclipse.che.api.debug.shared.dto.event.BreakpointActivatedEventDto)1 DisconnectEventDto (org.eclipse.che.api.debug.shared.dto.event.DisconnectEventDto)1 SuspendEventDto (org.eclipse.che.api.debug.shared.dto.event.SuspendEventDto)1 TYPE (org.eclipse.che.api.debug.shared.model.event.DebuggerEvent.TYPE)1 UnauthorizedException (org.eclipse.che.ide.websocket.rest.exceptions.UnauthorizedException)1