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

Commit 474bae9

Browse files
committed
depreciated old
1 parent 364a093 commit 474bae9

File tree

3 files changed

+94
-9
lines changed

3 files changed

+94
-9
lines changed

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,14 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
299299

300300
//
301301

302+
// region depreciated - temporary context
303+
302304
/**
303305
* 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>
304306
* To get the context use {@link HttpContext#getPath()}.
305307
*
308+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
309+
*
306310
* @return the http context associated with the context
307311
*
308312
* @see HttpContext
@@ -318,12 +322,15 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
318322
* @since 02.00.00
319323
* @author Ktt Development
320324
*/
325+
@Deprecated
321326
public abstract HttpContext createTemporaryContext();
322327

323328
/**
324329
* 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>
325330
* To get the context use {@link HttpContext#getPath()}.
326331
*
332+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
333+
*
327334
* @param maxTime the maximum time the context may exist for (in milliseconds)
328335
* @return the http context associated with the context
329336
*
@@ -340,13 +347,16 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
340347
* @since 02.00.00
341348
* @author Ktt Development
342349
*/
350+
@Deprecated
343351
public abstract HttpContext createTemporaryContext(final long maxTime);
344352

345353
/**
346354
* 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>
347355
* To get the context use {@link HttpContext#getPath()}. <br>
348356
* 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.
349357
*
358+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
359+
*
350360
* @param handler handler to use
351361
* @return the http context associated with the context
352362
*
@@ -364,13 +374,16 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
364374
* @since 02.00.00
365375
* @author Ktt Development
366376
*/
377+
@Deprecated
367378
public abstract HttpContext createTemporaryContext(final HttpHandler handler);
368379

369380
/**
370381
* 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>
371382
* To get the context use {@link HttpContext#getPath()}. <br>
372383
* 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.
373384
*
385+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
386+
*
374387
* @param handler handler to use
375388
* @param maxTime the maximum time the context may exist for (in milliseconds)
376389
* @return the http context associated with the context
@@ -389,11 +402,14 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
389402
* @since 02.00.00
390403
* @author Ktt Development
391404
*/
405+
@Deprecated
392406
public abstract HttpContext createTemporaryContext(final HttpHandler handler, final long maxTime);
393407

394408
/**
395409
* 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>
396410
*
411+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
412+
*
397413
* @param context the context
398414
* @return the http context associated with the context
399415
* @throws IllegalArgumentException if the context is invalid or taken
@@ -412,11 +428,14 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
412428
* @since 02.00.00
413429
* @author Ktt Development
414430
*/
431+
@Deprecated
415432
public abstract HttpContext createTemporaryContext(final String context);
416433

417434
/**
418435
* 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>
419436
*
437+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
438+
*
420439
* @param context the context
421440
* @param maxTime the maximum time the context may exist for (in milliseconds)
422441
* @return the http context associated with the context
@@ -437,12 +456,15 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
437456
* @since 02.00.00
438457
* @author Ktt Development
439458
*/
459+
@Deprecated
440460
public abstract HttpContext createTemporaryContext(final String context, final long maxTime);
441461

442462
/**
443463
* 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>
444464
* 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.
445465
*
466+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
467+
*
446468
* @param context the context
447469
* @param handler handler to use
448470
* @return the http context associated with the context
@@ -463,6 +485,7 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
463485
* @since 02.00.00
464486
* @author Ktt Development
465487
*/
488+
@Deprecated
466489
public abstract HttpContext createTemporaryContext(final String context, final HttpHandler handler);
467490

468491

@@ -471,6 +494,8 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
471494
* To get the context use {@link HttpContext#getPath()}. <br>
472495
* 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.
473496
*
497+
* @deprecated Use {@link com.kttdevelopment.simplehttpserver.handler.TemporaryHandler} instead
498+
*
474499
* @param context the context
475500
* @param handler handler to use
476501
* @param maxTime the maximum time the context may exist for (in milliseconds)
@@ -492,8 +517,11 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
492517
* @since 02.00.00
493518
* @author Ktt Development
494519
*/
520+
@Deprecated
495521
public abstract HttpContext createTemporaryContext(final String context, final HttpHandler handler, final long maxTime);
496522

523+
// endregion
524+
497525
//
498526

499527
/**
@@ -549,11 +577,39 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
549577
* Returns a copy of the server's contexts and their respective handlers.
550578
*
551579
* @return server's contexts
580+
*
552581
* @since 02.00.00
553582
* @author Ktt Development
554583
*/
555584
public abstract Map<HttpContext,HttpHandler> getContexts();
556585

586+
//
587+
588+
/**
589+
* Generates a random context at the root that can be used on the server.
590+
*
591+
* @return random safe context
592+
*
593+
* @see #getRandomContext(String)
594+
* @see com.kttdevelopment.simplehttpserver.handler.TemporaryHandler
595+
* @since 03.03.00
596+
* @author Ktt Development
597+
*/
598+
public abstract String getRandomContext();
599+
600+
/**
601+
* Generates a randome context that can be used on the server.
602+
*
603+
* @param context where to generate the random context
604+
* @return randome safe context
605+
*
606+
* @see #getRandomContext()
607+
* @see com.kttdevelopment.simplehttpserver.handler.TemporaryHandler
608+
* @since 03.03.00
609+
* @author Ktt Development
610+
*/
611+
public abstract String getRandomContext(final String context);
612+
557613
//
558614

559615
/**

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

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public synchronized final HttpContext createContext(final String path, final Htt
161161

162162
//
163163

164+
@Deprecated
164165
private String generateRandomContext(){
165166
String targetContext;
166167

@@ -172,32 +173,34 @@ private String generateRandomContext(){
172173

173174
//
174175

175-
@Override
176+
// region depreciated - temporary context
177+
178+
@Override @Deprecated
176179
public synchronized final HttpContext createTemporaryContext(){
177180
return createTemporaryContext(generateRandomContext());
178181
}
179182

180-
@Override
183+
@Override @Deprecated
181184
public synchronized final HttpContext createTemporaryContext(final long maxTime){
182185
return createTemporaryContext(generateRandomContext(),maxTime);
183186
}
184187

185-
@Override
188+
@Override @Deprecated
186189
public synchronized final HttpContext createTemporaryContext(final HttpHandler handler){
187190
return createTemporaryContext(generateRandomContext(),handler);
188191
}
189192

190-
@Override
193+
@Override @Deprecated
191194
public synchronized final HttpContext createTemporaryContext(final HttpHandler handler, final long maxTime){
192195
return createTemporaryContext(generateRandomContext(),handler,maxTime);
193196
}
194197

195-
@Override
198+
@Override @Deprecated
196199
public synchronized final HttpContext createTemporaryContext(final String context){
197200
return createContext(context, (HttpExchange exchange) -> removeContext(context));
198201
}
199202

200-
@Override
203+
@Override @Deprecated
201204
public synchronized final HttpContext createTemporaryContext(final String context, final long maxTime){
202205
final HttpContext httpContext = createContext(context, (HttpExchange exchange) -> removeContext(context));
203206

@@ -211,15 +214,15 @@ public synchronized final HttpContext createTemporaryContext(final String contex
211214
return httpContext;
212215
}
213216

214-
@Override
217+
@Override @Deprecated
215218
public synchronized final HttpContext createTemporaryContext(final String context, final HttpHandler handler){
216219
return createContext(context, (HttpExchange exchange) -> {
217220
handler.handle(exchange);
218221
removeContext(context);
219222
});
220223
}
221224

222-
@Override
225+
@Override @Deprecated
223226
public synchronized final HttpContext createTemporaryContext(final String context, final HttpHandler handler, final long maxTime){
224227
final HttpContext httpContext = createContext(context, (HttpExchange exchange) -> {
225228
handler.handle(exchange);
@@ -236,6 +239,8 @@ public synchronized final HttpContext createTemporaryContext(final String contex
236239
return httpContext;
237240
}
238241

242+
// endregion
243+
239244
//
240245

241246
@Override
@@ -275,7 +280,27 @@ public final Map<HttpContext, HttpHandler> getContexts(){
275280
return new HashMap<>(contexts);
276281
}
277282

278-
//
283+
//
284+
285+
@Override
286+
public synchronized final String getRandomContext(){
287+
return getRandomContext("/");
288+
}
289+
290+
@Override
291+
public synchronized final String getRandomContext(final String context){
292+
String targetContext;
293+
294+
final String head = getContext(context);
295+
296+
do targetContext = head + '/' + UUID.randomUUID().toString();
297+
while(getContextHandler(targetContext) != null);
298+
299+
return targetContext;
300+
}
301+
302+
303+
//
279304

280305
@Override
281306
public synchronized final void start(){
@@ -316,6 +341,7 @@ public final String toString(){
316341
};
317342
}
318343

344+
// start slash; no end slash
319345
private static String getContext(final String path){
320346
final String linSlash = path.replace("\\","/");
321347
if(linSlash.equals("/")) return "/";

src/main/java/com/kttdevelopment/simplehttpserver/handler/TemporaryHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.kttdevelopment.simplehttpserver.handler;
22

3+
import com.kttdevelopment.simplehttpserver.SimpleHttpServer;
34
import com.sun.net.httpserver.HttpExchange;
45
import com.sun.net.httpserver.HttpHandler;
56

@@ -9,6 +10,8 @@
910
* A temporary handler handles a single request and then removes itself from the server. This can be used for single use downloads, or media file hosting.
1011
*
1112
* @see HttpHandler
13+
* @see SimpleHttpServer#getRandomContext()
14+
* @see SimpleHttpServer#getRandomContext(String)
1215
* @since 03.03.00
1316
* @version 03.03.00
1417
* @author Ktt Development

0 commit comments

Comments
 (0)