Search in sources :

Example 1 with FutureResponseContext

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

the class AbstractChargePointServiceInvoker method run.

/**
 * Actual processing
 */
private void run(String chargeBoxId, CommunicationTask task) {
    RequestType request = task.getRequest();
    String messageId = UUID.randomUUID().toString();
    ActionResponsePair pair = typeStore.findActionResponse(request);
    if (pair == null) {
        throw new SteveException("Action name is not found");
    }
    OcppJsonCall call = new OcppJsonCall();
    call.setMessageId(messageId);
    call.setPayload(request);
    call.setAction(pair.getAction());
    FutureResponseContext frc = new FutureResponseContext(task, pair.getResponseClass());
    CommunicationContext context = new CommunicationContext(endpoint.getSession(chargeBoxId), chargeBoxId);
    context.setOutgoingMessage(call);
    context.setFutureResponseContext(frc);
    outgoingCallPipeline.accept(context);
}
Also used : CommunicationContext(de.rwth.idsg.steve.ocpp.ws.data.CommunicationContext) ActionResponsePair(de.rwth.idsg.steve.ocpp.ws.data.ActionResponsePair) OcppJsonCall(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall) FutureResponseContext(de.rwth.idsg.steve.ocpp.ws.data.FutureResponseContext) RequestType(de.rwth.idsg.steve.ocpp.RequestType) SteveException(de.rwth.idsg.steve.SteveException)

Example 2 with FutureResponseContext

use of de.rwth.idsg.steve.ocpp.ws.data.FutureResponseContext 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 3 with FutureResponseContext

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

the class Deserializer method handleResult.

/**
 * 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 handleResult(CommunicationContext context, String messageId, JsonParser parser) {
    FutureResponseContext responseContext = futureResponseContextStore.get(context.getSession(), messageId);
    if (responseContext == null) {
        throw new SteveException("A result message was received as response to a not-sent call. The message was: %s", context.getIncomingString());
    }
    ResponseType res;
    try {
        parser.nextToken();
        JsonNode responsePayload = parser.readValueAsTree();
        res = mapper.treeToValue(responsePayload, responseContext.getResponseClass());
    } catch (IOException e) {
        throw new SteveException("Deserialization of incoming response payload failed", e);
    }
    OcppJsonResult result = new OcppJsonResult();
    result.setMessageId(messageId);
    result.setPayload(res);
    context.setIncomingMessage(result);
    context.createResultHandler(responseContext.getTask());
}
Also used : OcppJsonResult(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResult) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) FutureResponseContext(de.rwth.idsg.steve.ocpp.ws.data.FutureResponseContext) SteveException(de.rwth.idsg.steve.SteveException) ResponseType(de.rwth.idsg.steve.ocpp.ResponseType)

Example 4 with FutureResponseContext

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

the class FutureResponseContextStoreImpl method get.

@Override
public FutureResponseContext get(WebSocketSession session, String messageId) {
    Map<String, FutureResponseContext> map = lookupTable.get(session);
    if (map == null) {
        throw new SteveException("sessionId '%s' is not in store", session.getId());
    } else {
        FutureResponseContext context = map.remove(messageId);
        log.debug("Store size for sessionId '{}': {}", session.getId(), map.size());
        return context;
    }
}
Also used : FutureResponseContext(de.rwth.idsg.steve.ocpp.ws.data.FutureResponseContext) SteveException(de.rwth.idsg.steve.SteveException)

Aggregations

SteveException (de.rwth.idsg.steve.SteveException)4 FutureResponseContext (de.rwth.idsg.steve.ocpp.ws.data.FutureResponseContext)4 IOException (java.io.IOException)2 TreeNode (com.fasterxml.jackson.core.TreeNode)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 RequestType (de.rwth.idsg.steve.ocpp.RequestType)1 ResponseType (de.rwth.idsg.steve.ocpp.ResponseType)1 ActionResponsePair (de.rwth.idsg.steve.ocpp.ws.data.ActionResponsePair)1 CommunicationContext (de.rwth.idsg.steve.ocpp.ws.data.CommunicationContext)1 ErrorCode (de.rwth.idsg.steve.ocpp.ws.data.ErrorCode)1 OcppJsonCall (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall)1 OcppJsonError (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError)1 OcppJsonResult (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResult)1