Search in sources :

Example 1 with OcppJsonCall

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

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

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

the class OcppJsonChargePoint method prepare.

public <T extends ResponseType> void prepare(RequestType request, Class<T> responseClass, Consumer<T> responseHandler, Consumer<OcppJsonError> errorHandler) {
    String messageId = UUID.randomUUID().toString();
    OcppJsonCall call = new OcppJsonCall();
    call.setMessageId(messageId);
    call.setPayload(request);
    call.setAction(getOperationName(request));
    // session is null, because we do not need org.springframework.web.socket.WebSocketSession
    CommunicationContext ctx = new CommunicationContext(null, chargeBoxId);
    ctx.setOutgoingMessage(call);
    Serializer.INSTANCE.accept(ctx);
    ResponseContext resCtx = new ResponseContext(ctx.getOutgoingString(), responseClass, responseHandler, errorHandler);
    responseContextMap.put(messageId, resCtx);
}
Also used : CommunicationContext(de.rwth.idsg.steve.ocpp.ws.data.CommunicationContext) OcppJsonCall(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall)

Example 4 with OcppJsonCall

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

the class Deserializer method handleCall.

// -------------------------------------------------------------------------
// Private Helpers
// -------------------------------------------------------------------------
/**
 * Catch exceptions and wrap them in outgoing ERRORs for incoming CALLs.
 */
private void handleCall(CommunicationContext context, String messageId, JsonParser parser) {
    // parse action
    String action;
    try {
        parser.nextToken();
        action = parser.getText();
    } catch (IOException e) {
        log.error("Exception occurred", e);
        context.setOutgoingMessage(ErrorFactory.genericDeserializeError(messageId, e.getMessage()));
        return;
    }
    // find action class
    Class<? extends RequestType> clazz = typeStore.findRequestClass(action);
    if (clazz == null) {
        context.setOutgoingMessage(ErrorFactory.actionNotFound(messageId, action));
        return;
    }
    // parse request payload
    RequestType req;
    try {
        parser.nextToken();
        JsonNode requestPayload = parser.readValueAsTree();
        req = mapper.treeToValue(requestPayload, clazz);
    } catch (IOException e) {
        log.error("Exception occurred", e);
        context.setOutgoingMessage(ErrorFactory.payloadDeserializeError(messageId, e.getMessage()));
        return;
    }
    OcppJsonCall call = new OcppJsonCall();
    call.setMessageId(messageId);
    call.setAction(action);
    call.setPayload(req);
    context.setIncomingMessage(call);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) OcppJsonCall(de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall) IOException(java.io.IOException) RequestType(de.rwth.idsg.steve.ocpp.RequestType)

Example 5 with OcppJsonCall

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

Aggregations

OcppJsonCall (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonCall)5 RequestType (de.rwth.idsg.steve.ocpp.RequestType)2 CommunicationContext (de.rwth.idsg.steve.ocpp.ws.data.CommunicationContext)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 ResponseType (de.rwth.idsg.steve.ocpp.ResponseType)1 ActionResponsePair (de.rwth.idsg.steve.ocpp.ws.data.ActionResponsePair)1 FutureResponseContext (de.rwth.idsg.steve.ocpp.ws.data.FutureResponseContext)1 OcppJsonError (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError)1 OcppJsonMessage (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonMessage)1 IOException (java.io.IOException)1