Search in sources :

Example 1 with OcppJsonError

use of de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError in project steve by RWTH-i5-IDSG.

the class Deserializer method handleError.

/**
 * Do NOT catch and handle exceptions for incoming RESPONSEs. Let the processing fail.
 * There is no mechanism in OCPP to report back such erroneous messages.
 */
private void handleError(CommunicationContext context, String messageId, JsonParser parser) {
    FutureResponseContext responseContext = futureResponseContextStore.get(context.getSession(), messageId);
    if (responseContext == null) {
        throw new SteveException("An error message was received as response to a not-sent call. The message was: %s", context.getIncomingString());
    }
    ErrorCode code;
    String desc;
    String details = null;
    try {
        parser.nextToken();
        code = ErrorCode.fromValue(parser.getText());
        parser.nextToken();
        desc = parser.getText();
        // ErrorDescription - Should be filled in if possible, otherwise a clear empty string "".
        if ("".equals(desc)) {
            desc = null;
        }
        // From spec:
        // ErrorDetails - This JSON object describes error details in an undefined way.
        // If there are no error details you should fill in an empty object {}, missing or null is not allowed
        parser.nextToken();
        TreeNode detailsNode = parser.readValueAsTree();
        if (detailsNode != null && detailsNode.size() != 0) {
            details = mapper.writeValueAsString(detailsNode);
        }
    } catch (IOException e) {
        throw new SteveException("Deserialization of incoming error message failed", e);
    }
    OcppJsonError error = new OcppJsonError();
    error.setMessageId(messageId);
    error.setErrorCode(code);
    error.setErrorDescription(desc);
    error.setErrorDetails(details);
    context.setIncomingMessage(error);
    context.createErrorHandler(responseContext.getTask());
}
Also used : TreeNode(com.fasterxml.jackson.core.TreeNode) OcppJsonError(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError) ErrorCode(de.rwth.idsg.steve.ocpp.ws.data.ErrorCode) IOException(java.io.IOException) FutureResponseContext(de.rwth.idsg.steve.ocpp.ws.data.FutureResponseContext) SteveException(de.rwth.idsg.steve.SteveException)

Example 2 with OcppJsonError

use of de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError in project steve by RWTH-i5-IDSG.

the class ErrorFactory method setFields.

private static OcppJsonError setFields(String messageId, ErrorCode code, String desc, String details) {
    OcppJsonError error = new OcppJsonError();
    error.setMessageId(messageId);
    error.setErrorCode(code);
    error.setErrorDescription(desc);
    error.setErrorDetails(details);
    return error;
}
Also used : OcppJsonError(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError)

Example 3 with OcppJsonError

use of de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError in project steve by RWTH-i5-IDSG.

the class IncomingPipeline method accept.

@Override
public void accept(CommunicationContext context) {
    deserializer.accept(context);
    // When the incoming could not be deserialized
    if (context.isSetOutgoingError()) {
        serializer.accept(context);
        sender.accept(context);
        return;
    }
    OcppJsonMessage msg = context.getIncomingMessage();
    if (msg instanceof OcppJsonCall) {
        handler.accept(context);
        serializer.accept(context);
        sender.accept(context);
    } else if (msg instanceof OcppJsonResult) {
        context.getResultHandler().accept((OcppJsonResult) msg);
    } else if (msg instanceof OcppJsonError) {
        context.getErrorHandler().accept((OcppJsonError) msg);
    }
}
Also used : OcppJsonResult(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResult) OcppJsonError(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError) OcppJsonCall(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall) OcppJsonMessage(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonMessage)

Example 4 with OcppJsonError

use of de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError in project steve by RWTH-i5-IDSG.

the class OcppJsonChargePoint method onMessage.

@OnWebSocketMessage
public void onMessage(Session session, String msg) {
    try {
        OcppJsonResponse response = deserializer.extractResponse(msg);
        ResponseContext ctx = responseContextMap.remove(response.getMessageId());
        if (response instanceof OcppJsonResult) {
            ctx.responseHandler.accept(((OcppJsonResult) response).getPayload());
        } else if (response instanceof OcppJsonError) {
            ctx.errorHandler.accept((OcppJsonError) response);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (receivedResponsesSignal != null) {
            receivedResponsesSignal.countDown();
        }
    }
}
Also used : OcppJsonResponse(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResponse) OcppJsonResult(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResult) OcppJsonError(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError) IOException(java.io.IOException) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Aggregations

OcppJsonError (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError)4 OcppJsonResult (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResult)2 IOException (java.io.IOException)2 TreeNode (com.fasterxml.jackson.core.TreeNode)1 SteveException (de.rwth.idsg.steve.SteveException)1 ErrorCode (de.rwth.idsg.steve.ocpp.ws.data.ErrorCode)1 FutureResponseContext (de.rwth.idsg.steve.ocpp.ws.data.FutureResponseContext)1 OcppJsonCall (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall)1 OcppJsonMessage (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonMessage)1 OcppJsonResponse (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResponse)1 OnWebSocketMessage (org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)1