Search in sources :

Example 1 with ResponseType

use of de.rwth.idsg.steve.ocpp.ResponseType in project steve by RWTH-i5-IDSG.

the class AbstractCallHandler method accept.

@Override
public void accept(CommunicationContext context) {
    OcppJsonCall call = (OcppJsonCall) context.getIncomingMessage();
    String messageId = call.getMessageId();
    ResponseType response;
    try {
        response = dispatch(call.getPayload(), context.getChargeBoxId());
    } catch (Exception e) {
        log.error("Exception occurred", e);
        context.setOutgoingMessage(ErrorFactory.payloadProcessingError(messageId, e.getMessage()));
        return;
    }
    OcppJsonResult result = new OcppJsonResult();
    result.setPayload(response);
    result.setMessageId(messageId);
    context.setOutgoingMessage(result);
}
Also used : OcppJsonResult(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResult) OcppJsonCall(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall) ResponseType(de.rwth.idsg.steve.ocpp.ResponseType)

Example 2 with ResponseType

use of de.rwth.idsg.steve.ocpp.ResponseType 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)

Aggregations

ResponseType (de.rwth.idsg.steve.ocpp.ResponseType)2 OcppJsonResult (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResult)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 SteveException (de.rwth.idsg.steve.SteveException)1 FutureResponseContext (de.rwth.idsg.steve.ocpp.ws.data.FutureResponseContext)1 OcppJsonCall (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall)1 IOException (java.io.IOException)1