message: ocppj - prevent WS cache for nonexisting tenants
diff: @@ -385,6 +385,7 @@ export default class JsonOCPPServer extends OCPPServer {
  }
  } catch (error) {
  const logMessage = `${WebSocketAction.MESSAGE} > WS Connection ID '${wsWrapper.guid}' got error while processing WS Message: ${error.message as string}`;
  + if (wsWrapper?.tenantID) {
  await Logging.logError({
  ...LoggingHelper.getWSWrapperProperties(wsWrapper),
  action: ServerAction.WS_SERVER_MESSAGE,
  @@ -392,12 +393,13 @@ export default class JsonOCPPServer extends OCPPServer {
  message: logMessage,
  detailedMessages: { message, isBinary, wsWrapper: this.getWSWrapperData(wsWrapper), error: error.stack }
  });
  + }
  await Logging.logError({
  tenantID: Constants.DEFAULT_TENANT_ID,
  chargingStationID: wsWrapper.chargingStationID,
  action: ServerAction.WS_SERVER_MESSAGE,
  module: MODULE_NAME, method: 'onMessage',
  - message: logMessage,
  + message: logMessage + ` - tenant: ${wsWrapper?.tenantID}`,
  detailedMessages: { message, isBinary, wsWrapper: this.getWSWrapperData(wsWrapper), error: error.stack }
  });
  }
  @@ -406,6 +408,11 @@ export default class JsonOCPPServer extends OCPPServer {
  private async checkWSConnectionFromOnMessage(wsWrapper: WSWrapper) {
  // Get WS Connection
  const wsConnection = wsWrapper.wsConnection;
  + if (wsWrapper.closed) {
  + // Current message is from a charger which should not reach us!
  + // e.g.: Websocket has been closed during the onOpen because the tenant does not exists
  + throw new Error('Websocket is already closed');
  + }
  // Get WS Connection from cache
  const wsExistingConnection =
  this.getWSConnectionFromProtocolAndID(wsWrapper.protocol, wsWrapper.key);
  @@ -420,7 +427,6 @@ export default class JsonOCPPServer extends OCPPServer {
  });
  // Add WS connection from OnMessage in cache
  await this.setWSConnection(WebSocketAction.MESSAGE, ServerAction.WS_SERVER_MESSAGE, wsConnection, wsWrapper);
  - return;
  }
  // Should have the same GUID
  const wsExistingWrapper = wsExistingConnection.getWS();
  @@ -441,7 +447,7 @@ export default class JsonOCPPServer extends OCPPServer {
  chargingStationID: wsWrapper.chargingStationID,
  action: ServerAction.WS_SERVER_MESSAGE,
  module: MODULE_NAME, method: 'checkWSConnectionFromOnMessage',
  - message: `${WebSocketAction.MESSAGE} > Existing WS Connection ID '${wsExistingWrapper.guid}' ping succeded meaning multiple WS connections are opened by the same charging station, existing one will be closed and replaced by new one with ID '${wsWrapper.guid}'`,
  + message: `${WebSocketAction.MESSAGE} > Existing WS Connection ID '${wsExistingWrapper.guid}' ping succeeded meaning multiple WS connections are opened by the same charging station, existing one will be closed and replaced by new one with ID '${wsWrapper.guid}'`,
  detailedMessages: { wsExistingWrapper: this.getWSWrapperData(wsExistingWrapper), wsWrapper: this.getWSWrapperData(wsWrapper) }
  });
  // Close WS
  