BroadcastChannelProcedureName.CLOSE_CONNECTION,
() => this.chargingStation.closeWSConnection(),
],
+ [
+ BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
+ (requestPayload?: BroadcastChannelRequestPayload) =>
+ this.chargingStation.startAutomaticTransactionGenerator(requestPayload.connectorIds),
+ ],
+ [
+ BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
+ (requestPayload?: BroadcastChannelRequestPayload) =>
+ this.chargingStation.stopAutomaticTransactionGenerator(requestPayload.connectorIds),
+ ],
[
BroadcastChannelProcedureName.START_TRANSACTION,
async (requestPayload?: BroadcastChannelRequestPayload) =>
),
}),
],
- [
- BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
- (requestPayload?: BroadcastChannelRequestPayload) =>
- this.chargingStation.startAutomaticTransactionGenerator(requestPayload.connectorIds),
- ],
- [
- BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
- (requestPayload?: BroadcastChannelRequestPayload) =>
- this.chargingStation.stopAutomaticTransactionGenerator(requestPayload.connectorIds),
- ],
[
BroadcastChannelProcedureName.AUTHORIZE,
async (requestPayload?: BroadcastChannelRequestPayload) =>
errorStack: (error as Error).stack,
errorDetails: (error as OCPPError).details,
};
+ } finally {
+ this.sendResponse([uuid, responsePayload]);
}
- this.sendResponse([uuid, responsePayload]);
}
private messageErrorHandler(messageEvent: MessageEvent): void {
);
}
+ protected authenticate(req: IncomingMessage, next: (err?: Error) => void): void {
+ if (this.isBasicAuthEnabled() === true) {
+ if (this.isValidBasicAuth(req) === false) {
+ next(new Error('Unauthorized'));
+ }
+ next();
+ }
+ next();
+ }
+
public abstract start(): void;
public abstract sendRequest(request: ProtocolRequest): void;
public abstract sendResponse(response: ProtocolResponse): void;
}
private requestListener(req: IncomingMessage, res: ServerResponse): void {
- if (this.authenticate(req) === false) {
- res.setHeader('Content-Type', 'text/plain');
- res.setHeader('WWW-Authenticate', 'Basic realm=users');
- res.writeHead(StatusCodes.UNAUTHORIZED);
- res.end(`${StatusCodes.UNAUTHORIZED} Unauthorized`);
- return;
- }
+ this.authenticate(req, (err) => {
+ if (err) {
+ res.setHeader('Content-Type', 'text/plain');
+ res.setHeader('WWW-Authenticate', 'Basic realm=users');
+ res.writeHead(StatusCodes.UNAUTHORIZED);
+ res.end(`${StatusCodes.UNAUTHORIZED} Unauthorized`);
+ req.destroy();
+ res.destroy();
+ }
+ });
// Expected request URL pathname: /ui/:version/:procedureName
const [protocol, version, procedureName] = req.url?.split('/').slice(1) as [
Protocol,
}
}
- private authenticate(req: IncomingMessage): boolean {
- if (this.isBasicAuthEnabled() === true) {
- if (this.isValidBasicAuth(req) === true) {
- return true;
- }
- return false;
- }
- return true;
- }
-
private responseStatusToStatusCode(status: ResponseStatus): StatusCodes {
switch (status) {
case ResponseStatus.SUCCESS:
}
}
- private authenticate(req: IncomingMessage, next: (err?: Error) => void): void {
- if (this.isBasicAuthEnabled() === true) {
- if (this.isValidBasicAuth(req) === false) {
- next(new Error('Unauthorized'));
- } else {
- next();
- }
- } else {
- next();
- }
- }
-
private validateRawDataRequest(rawData: RawData): ProtocolRequest | false {
// logger.debug(
// `${this.logPrefix(
errorStack: (error as Error).stack,
errorDetails: (error as OCPPError).details,
};
- }
- // Send response for payload not forwarded to broadcast channel
- if (responsePayload !== undefined) {
- this.sendResponse(messageId ?? 'error', responsePayload);
+ } finally {
+ // Send response for payload not forwarded to broadcast channel
+ if (responsePayload !== undefined) {
+ this.sendResponse(messageId ?? 'error', responsePayload);
+ }
}
}
this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
);
this.requestHandlers.set(
- ProcedureName.START_TRANSACTION,
+ ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
);
this.requestHandlers.set(
- ProcedureName.STOP_TRANSACTION,
+ ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
);
this.requestHandlers.set(
- ProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR,
+ ProcedureName.START_TRANSACTION,
this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
);
this.requestHandlers.set(
- ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR,
+ ProcedureName.STOP_TRANSACTION,
this.handleProtocolRequest.bind(this) as ProtocolRequestHandler
);
this.requestHandlers.set(