Search in sources :

Example 1 with RequestType

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

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

Aggregations

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