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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations