@@ -39,7 +39,7 @@ interface
3939 { $IFDEF FPC}
4040 LazUTF8,
4141 { $ENDIF}
42- Generics.Collections;
42+ Classes, Generics.Collections;
4343
4444const
4545 DEFAULT_BINDING_PORT = 8080 ;
@@ -90,7 +90,7 @@ TdjServer = class(TdjServerBase)
9090 ConnectorMap: TObjectDictionary<string, IConnector>;
9191 ConnectorList: TdjStrings;
9292 ContextHandlers: IHandlerContainer;
93-
93+ ContextNames: TStrings;
9494 procedure Trace (const S: string);
9595 procedure StartConnectors ;
9696 procedure StopConnectors ;
@@ -147,6 +147,7 @@ TdjServer = class(TdjServerBase)
147147 * Add a new context.
148148 *
149149 * @param Context the context handler.
150+ * @throws EWebComponentException if an error occurs that interferes with the component's normal operation.
150151 *}
151152 procedure Add (Context: TdjWebComponentContextHandler);
152153
@@ -162,7 +163,7 @@ TdjServer = class(TdjServerBase)
162163implementation // / \cond
163164
164165uses
165- Generics.Defaults, SysUtils, Classes ;
166+ Generics.Defaults, SysUtils;
166167
167168{ TdjServer }
168169
@@ -183,12 +184,9 @@ constructor TdjServer.Create;
183184 ConnectorList := TdjStrings.Create;
184185
185186 ContextHandlers := TdjContextHandlerCollection.Create;
187+ ContextNames := TStringList.Create;
186188
187189 AddHandler(ContextHandlers);
188-
189- { $IFDEF LOG_CREATE}
190- Trace(' Created' );
191- { $ENDIF}
192190end ;
193191
194192constructor TdjServer.Create(const AHost: string;
@@ -209,10 +207,6 @@ constructor TdjServer.Create(const APort: Integer);
209207
210208destructor TdjServer.Destroy;
211209begin
212- { $IFDEF LOG_DESTROY}
213- Trace(' Destroy' );
214- { $ENDIF}
215-
216210 if IsStarted then
217211 begin
218212 Stop;
@@ -221,6 +215,8 @@ destructor TdjServer.Destroy;
221215 ConnectorMap.Free;
222216 ConnectorList.Free;
223217
218+ ContextNames.Free;
219+
224220 inherited ;
225221end ;
226222
@@ -263,6 +259,16 @@ procedure TdjServer.Add(Context: TdjWebComponentContextHandler);
263259begin
264260 Trace(' Add context ' + Context.ContextPath);
265261
262+ if ContextNames.IndexOf(Context.ContextPath) < 0 then
263+ begin
264+ ContextNames.Add(Context.ContextPath);
265+ end else begin
266+ raise EWebComponentException.CreateFmt(' Context path "%s" is already registered.' ,
267+ [Context.ContextPath]);
268+
269+ Context.Free; // avoid leak
270+ end ;
271+
266272 ContextHandlers.AddHandler(Context);
267273end ;
268274
@@ -320,7 +326,6 @@ procedure TdjServer.Trace(const S: string);
320326 { $ENDIF DARAJA_LOGGING}
321327end ;
322328
323-
324329procedure TdjServer.DoStart ;
325330begin
326331 CheckStarted;
0 commit comments