Incoming requests payload validation with JSON schemas (#135)
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16ResponseService.ts
index 38a29976a115160c558bed39b03196cf16ddd5fe..7eef0270865e752ed836f45051b97b3a8999f423 100644 (file)
@@ -34,6 +34,7 @@ import logger from '../../../utils/Logger';
 import Utils from '../../../utils/Utils';
 import type ChargingStation from '../../ChargingStation';
 import { ChargingStationConfigurationUtils } from '../../ChargingStationConfigurationUtils';
+import { ChargingStationUtils } from '../../ChargingStationUtils';
 import OCPPResponseService from '../OCPPResponseService';
 import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
 
@@ -65,7 +66,10 @@ export default class OCPP16ResponseService extends OCPPResponseService {
     requestPayload: JsonType
   ): Promise<void> {
     if (chargingStation.isRegistered() || commandName === OCPP16RequestCommand.BOOT_NOTIFICATION) {
-      if (this.responseHandlers.has(commandName)) {
+      if (
+        this.responseHandlers.has(commandName) &&
+        ChargingStationUtils.isRequestCommandSupported(commandName, chargingStation)
+      ) {
         try {
           await this.responseHandlers.get(commandName)(chargingStation, payload, requestPayload);
         } catch (error) {
@@ -76,7 +80,7 @@ export default class OCPP16ResponseService extends OCPPResponseService {
         // Throw exception
         throw new OCPPError(
           ErrorType.NOT_IMPLEMENTED,
-          `${commandName} is not implemented to handle request response payload ${JSON.stringify(
+          `${commandName} is not implemented to handle request response PDU ${JSON.stringify(
             payload,
             null,
             2
@@ -88,7 +92,7 @@ export default class OCPP16ResponseService extends OCPPResponseService {
     } else {
       throw new OCPPError(
         ErrorType.SECURITY_ERROR,
-        `${commandName} cannot be issued to handle request response payload ${JSON.stringify(
+        `${commandName} cannot be issued to handle request response PDU ${JSON.stringify(
           payload,
           null,
           2