Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

Commit 124d9fd

Browse files
authored
Replace #createTemporaryContext with TemporaryHandler
Replace #createTemporaryContext with TemporaryHandler
2 parents 063ecce + 39ad3d8 commit 124d9fd

File tree

9 files changed

+247
-133
lines changed

9 files changed

+247
-133
lines changed

src/main/java/com/kttdevelopment/simplehttpserver/HttpSessionHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,11 @@ public synchronized final void updateLastAccessTime(){
120120
@Override
121121
public final String toString(){
122122
final StringBuilder OUT = new StringBuilder();
123-
OUT.append("HttpSession") .append("{");
124-
OUT.append("sessionID") .append("=") .append(sessionID) .append(", ");
125-
OUT.append("creationTime") .append("=") .append(creationTime) .append(", ");
126-
OUT.append("lastAccessTime").append("=") .append(lastAccessTime);
127-
OUT.append("}");
123+
OUT.append("HttpSession") .append('{');
124+
OUT.append("sessionID") .append('=') .append(sessionID) .append(", ");
125+
OUT.append("creationTime") .append('=') .append(creationTime) .append(", ");
126+
OUT.append("lastAccessTime").append('=') .append(lastAccessTime);
127+
OUT.append('}');
128128
return OUT.toString();
129129
}
130130

src/main/java/com/kttdevelopment/simplehttpserver/HttpSessionImpl.java

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpExchangeImpl.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -423,27 +423,27 @@ public synchronized final void setAttribute(final String name, final Object valu
423423
@Override
424424
public final String toString(){
425425
final StringBuilder OUT = new StringBuilder();
426-
OUT.append("SimpleHttpExchange").append("{");
427-
OUT.append("httpServer") .append("=") .append(httpServer) .append(", ");
428-
OUT.append("httpExchange") .append("=") .append(httpExchange) .append(", ");
429-
OUT.append("URI") .append("=") .append(URI) .append(", ");
430-
OUT.append("publicAddress") .append("=") .append(publicAddr) .append(", ");
431-
OUT.append("localAddress") .append("=") .append(localAddr) .append(", ");
432-
OUT.append("httpContext") .append("=") .append(httpContext) .append(", ");
433-
OUT.append("httpPrincipal") .append("=") .append(httpPrincipal) .append(", ");
434-
OUT.append("protocol") .append("=") .append(protocol) .append(", ");
435-
OUT.append("requestHeaders") .append("=") .append(requestHeaders) .append(", ");
436-
OUT.append("requestMethod") .append("=") .append(requestMethod) .append(", ");
437-
OUT.append("responseHeaders") .append("=") .append(getResponseHeaders()) .append(", ");
438-
OUT.append("responseCode") .append("=") .append(getResponseCode()) .append(", ");
439-
OUT.append("rawGet") .append("=") .append(rawGet) .append(", ");
440-
OUT.append("getMap") .append("=") .append(getMap) .append(", ");
441-
OUT.append("hasGet") .append("=") .append(hasGet) .append(", ");
442-
OUT.append("rawPost") .append("=") .append(rawPost) .append(", ");
443-
OUT.append("postMap") .append("=") .append(postMap) .append(", ");
444-
OUT.append("hasPost") .append("=") .append(hasPost) .append(", ");
445-
OUT.append("cookies") .append("=") .append(cookies);
446-
OUT.append("}");
426+
OUT.append("SimpleHttpExchange").append('{');
427+
OUT.append("httpServer") .append('=') .append(httpServer) .append(", ");
428+
OUT.append("httpExchange") .append('=') .append(httpExchange) .append(", ");
429+
OUT.append("URI") .append('=') .append(URI) .append(", ");
430+
OUT.append("publicAddress") .append('=') .append(publicAddr) .append(", ");
431+
OUT.append("localAddress") .append('=') .append(localAddr) .append(", ");
432+
OUT.append("httpContext") .append('=') .append(httpContext) .append(", ");
433+
OUT.append("httpPrincipal") .append('=') .append(httpPrincipal) .append(", ");
434+
OUT.append("protocol") .append('=') .append(protocol) .append(", ");
435+
OUT.append("requestHeaders") .append('=') .append(requestHeaders) .append(", ");
436+
OUT.append("requestMethod") .append('=') .append(requestMethod) .append(", ");
437+
OUT.append("responseHeaders") .append('=') .append(getResponseHeaders()) .append(", ");
438+
OUT.append("responseCode") .append('=') .append(getResponseCode()) .append(", ");
439+
OUT.append("rawGet") .append('=') .append(rawGet) .append(", ");
440+
OUT.append("getMap") .append('=') .append(getMap) .append(", ");
441+
OUT.append("hasGet") .append('=') .append(hasGet) .append(", ");
442+
OUT.append("rawPost") .append('=') .append(rawPost) .append(", ");
443+
OUT.append("postMap") .append('=') .append(postMap) .append(", ");
444+
OUT.append("hasPost") .append('=') .append(hasPost) .append(", ");
445+
OUT.append("cookies") .append('=') .append(cookies);
446+
OUT.append('}');
447447
return OUT.toString();
448448
}
449449

src/main/java/com/kttdevelopment/simplehttpserver/SimpleHttpServer.java

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,40 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
211211

212212
//
213213

214+
/**
215+
* Sets a session handler for the server.
216+
*
217+
* @param sessionHandler session handler
218+
*
219+
* @see HttpSessionHandler
220+
* @see #getHttpSessionHandler()
221+
* @since 03.03.00
222+
* @author Ktt Development
223+
*/
214224
public abstract void setHttpSessionHandler(final HttpSessionHandler sessionHandler);
215225

226+
/**
227+
* Returns the session handler for the server or null if none exists.
228+
*
229+
* @return server session handler
230+
*
231+
* @see HttpSessionHandler
232+
* @see #setHttpSessionHandler(HttpSessionHandler)
233+
* @since 03.03.00
234+
* @author Ktt Development
235+
*/
216236
public abstract HttpSessionHandler getHttpSessionHandler();
217237

238+
/**
239+
* Returns the session associated with an exchange or null if no session handler exists.
240+
*
241+
* @param exchange http exchange
242+
* @return http session
243+
*
244+
* @see HttpSession
245+
* @since 03.03.00
246+
* @author Ktt Development
247+
*/
218248
public abstract HttpSession getHttpSession(final HttpExchange exchange);
219249

220250
//
@@ -299,10 +329,14 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
299329

300330
//
301331

332+
// region depreciated - temporary context
333+
302334
/**
303335
* Creates a temporary context at a random address that will remove itself after the first connection. This type of context is typically used for single use downloads or media file hosting. <br>
304336
* To get the context use {@link HttpContext#getPath()}.
305337
*
338+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
339+
*
306340
* @return the http context associated with the context
307341
*
308342
* @see HttpContext
@@ -318,12 +352,15 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
318352
* @since 02.00.00
319353
* @author Ktt Development
320354
*/
355+
@Deprecated
321356
public abstract HttpContext createTemporaryContext();
322357

323358
/**
324359
* Creates a temporary context at a random address that will remove itself after the first connection or after the max time is passed. This type of context is typically used for single use downloads or media file hosting. <br>
325360
* To get the context use {@link HttpContext#getPath()}.
326361
*
362+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
363+
*
327364
* @param maxTime the maximum time the context may exist for (in milliseconds)
328365
* @return the http context associated with the context
329366
*
@@ -340,13 +377,16 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
340377
* @since 02.00.00
341378
* @author Ktt Development
342379
*/
380+
@Deprecated
343381
public abstract HttpContext createTemporaryContext(final long maxTime);
344382

345383
/**
346384
* Creates a temporary context at a random address that will remove itself after the first connection. This type of context is typically used for single use downloads or media file hosting. <br>
347385
* To get the context use {@link HttpContext#getPath()}. <br>
348386
* This method encapsulates the handler with a temporary one, so {@link HttpContext#getHandler()} will not return the one passed in the parameter, instead it will return the encapsulating handler.
349387
*
388+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
389+
*
350390
* @param handler handler to use
351391
* @return the http context associated with the context
352392
*
@@ -364,13 +404,16 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
364404
* @since 02.00.00
365405
* @author Ktt Development
366406
*/
407+
@Deprecated
367408
public abstract HttpContext createTemporaryContext(final HttpHandler handler);
368409

369410
/**
370411
* Creates a temporary context at a random address that will remove itself after the first connection or after the max time is passed. This type of context is typically used for single use downloads or media file hosting. <br>
371412
* To get the context use {@link HttpContext#getPath()}. <br>
372413
* This method encapsulates the handler with a temporary one, so {@link HttpContext#getHandler()} will not return the one passed in the parameter, instead it will return the encapsulating handler.
373414
*
415+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
416+
*
374417
* @param handler handler to use
375418
* @param maxTime the maximum time the context may exist for (in milliseconds)
376419
* @return the http context associated with the context
@@ -389,11 +432,14 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
389432
* @since 02.00.00
390433
* @author Ktt Development
391434
*/
435+
@Deprecated
392436
public abstract HttpContext createTemporaryContext(final HttpHandler handler, final long maxTime);
393437

394438
/**
395439
* Creates a temporary context at a specified address that will remove itself after the first connection. This type of context is typically used for single use downloads or media file hosting. <br>
396440
*
441+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
442+
*
397443
* @param context the context
398444
* @return the http context associated with the context
399445
* @throws IllegalArgumentException if the context is invalid or taken
@@ -412,11 +458,14 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
412458
* @since 02.00.00
413459
* @author Ktt Development
414460
*/
461+
@Deprecated
415462
public abstract HttpContext createTemporaryContext(final String context);
416463

417464
/**
418465
* Creates a temporary context at a specified address that will remove itself after the first connection or after the max time is passed. This type of context is typically used for single use downloads or media file hosting. <br>
419466
*
467+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
468+
*
420469
* @param context the context
421470
* @param maxTime the maximum time the context may exist for (in milliseconds)
422471
* @return the http context associated with the context
@@ -437,12 +486,15 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
437486
* @since 02.00.00
438487
* @author Ktt Development
439488
*/
489+
@Deprecated
440490
public abstract HttpContext createTemporaryContext(final String context, final long maxTime);
441491

442492
/**
443493
* Creates a temporary context at a specified address that will remove itself after the first connection. This type of context is typically used for single use downloads or media file hosting. <br>
444494
* This method encapsulates the handler with a temporary one, so {@link HttpContext#getHandler()} will not return the one passed in the parameter, instead it will return the encapsulating handler.
445495
*
496+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
497+
*
446498
* @param context the context
447499
* @param handler handler to use
448500
* @return the http context associated with the context
@@ -463,6 +515,7 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
463515
* @since 02.00.00
464516
* @author Ktt Development
465517
*/
518+
@Deprecated
466519
public abstract HttpContext createTemporaryContext(final String context, final HttpHandler handler);
467520

468521

@@ -471,6 +524,8 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
471524
* To get the context use {@link HttpContext#getPath()}. <br>
472525
* This method encapsulates the handler with a temporary one, so {@link HttpContext#getHandler()} will not return the one passed in the parameter, instead it will return the encapsulating handler.
473526
*
527+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
528+
*
474529
* @param context the context
475530
* @param handler handler to use
476531
* @param maxTime the maximum time the context may exist for (in milliseconds)
@@ -492,8 +547,11 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
492547
* @since 02.00.00
493548
* @author Ktt Development
494549
*/
550+
@Deprecated
495551
public abstract HttpContext createTemporaryContext(final String context, final HttpHandler handler, final long maxTime);
496552

553+
// endregion
554+
497555
//
498556

499557
/**
@@ -549,11 +607,39 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
549607
* Returns a copy of the server's contexts and their respective handlers.
550608
*
551609
* @return server's contexts
610+
*
552611
* @since 02.00.00
553612
* @author Ktt Development
554613
*/
555614
public abstract Map<HttpContext,HttpHandler> getContexts();
556615

616+
//
617+
618+
/**
619+
* Generates a random context at the root that can be used on the server.
620+
*
621+
* @return random safe context
622+
*
623+
* @see #getRandomContext(String)
624+
* @see com.kttdevelopment.simplehttpserver.handler.TemporaryHandler
625+
* @since 03.03.00
626+
* @author Ktt Development
627+
*/
628+
public abstract String getRandomContext();
629+
630+
/**
631+
* Generates a randome context that can be used on the server.
632+
*
633+
* @param context where to generate the random context
634+
* @return randome safe context
635+
*
636+
* @see #getRandomContext()
637+
* @see com.kttdevelopment.simplehttpserver.handler.TemporaryHandler
638+
* @since 03.03.00
639+
* @author Ktt Development
640+
*/
641+
public abstract String getRandomContext(final String context);
642+
557643
//
558644

559645
/**

0 commit comments

Comments
 (0)