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

Commit bfc96d9

Browse files
authored
Convert handler to extended interface
Convert handler to extended interface
2 parents c4b31ae + 9ee34d1 commit bfc96d9

File tree

4 files changed

+7
-96
lines changed

4 files changed

+7
-96
lines changed

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,11 @@ public abstract class HttpSession {
1616
/**
1717
* Creates an empty {@link HttpSession}. Applications don't use this method.
1818
*
19-
* @see HttpSessionImpl#createHttpSession()
2019
* @since 02.00.00
2120
* @author Ktt Development
2221
*/
2322
HttpSession(){ }
2423

25-
//
26-
27-
/**
28-
* Creates a {@link HttpSession}.
29-
*
30-
* @return a {@link HttpSession}
31-
*
32-
* @since 02.00.00
33-
* @author Ktt Development
34-
*/
35-
synchronized static HttpSession create(){
36-
return HttpSessionImpl.createHttpSession();
37-
}
38-
3924
//
4025

4126
/**

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,22 @@
1414
* @version 03.03.00
1515
* @author Ktt Development
1616
*/
17-
public interface SimpleHttpHandler {
18-
/*
17+
public interface SimpleHttpHandler extends HttpHandler {
18+
1919
/**
20-
* Encapsulates the {@link #handle(SimpleHttpExchange)} for the authenticator. Applications do not use this.
20+
* Encapsulates the {@link #handle(SimpleHttpExchange)} for the authenticator. This method is reserved by the server; <b>do not override this</b>, it will break the {@link #handle(SimpleHttpExchange)} method.
2121
*
2222
* @param exchange client information
2323
* @throws IOException internal failure
2424
*
2525
* @since 02.00.00
2626
* @author Ktt Development
27-
/
27+
*/
2828
@Override
29-
default final void handle(final HttpExchange exchange) throws IOException{
30-
final SimpleHttpExchange sxe = SimpleHttpExchange.create(exchange);
31-
if(authenticate(sxe))
32-
handle(sxe);
33-
else
34-
sxe.close();
29+
default void handle(final HttpExchange exchange) throws IOException{
30+
handle(SimpleHttpExchange.create(exchange));
3531
}
36-
*/
32+
3733
/**
3834
* Handlers the given request and generates a response <b>if no exceptions occur</b>.
3935
*

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

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
227227
*
228228
* @see HttpContext
229229
* @see #createContext(String, HttpHandler)
230-
* @see #createContext(String, SimpleHttpHandler)
231230
* @see #removeContext(String)
232231
* @see #removeContext(HttpContext)
233232
* @since 02.00.00
@@ -247,34 +246,13 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
247246
* @see HttpContext
248247
* @see HttpHandler
249248
* @see #createContext(String)
250-
* @see #createContext(String, SimpleHttpHandler)
251249
* @see #removeContext(String)
252250
* @see #removeContext(HttpContext)
253251
* @since 02.00.00
254252
* @author Ktt Development
255253
*/
256254
public abstract HttpContext createContext(final String context, final HttpHandler handler);
257255

258-
/**
259-
* Creates a context mapped to a specific {@link HttpHandler}.
260-
*
261-
* @param context the context
262-
* @param handler the handler
263-
* @return the http context associated with the context
264-
* @throws IllegalArgumentException if the context is invalid or taken
265-
* @throws NullPointerException if the context is null
266-
*
267-
* @see HttpContext
268-
* @see SimpleHttpHandler
269-
* @see #createContext(String)
270-
* @see #createContext(String, HttpHandler)
271-
* @see #removeContext(String)
272-
* @see #removeContext(HttpContext)
273-
* @since 03.03.00
274-
* @author Ktt Development
275-
*/
276-
public abstract HttpContext createContext(final String context, final SimpleHttpHandler handler);
277-
278256
//
279257

280258
/**
@@ -289,7 +267,6 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
289267
* @see HttpContext
290268
* @see Authenticator
291269
* @see #createContext(String, HttpHandler, Authenticator)
292-
* @see #createContext(String, SimpleHttpHandler, Authenticator)
293270
* @see #removeContext(String)
294271
* @see #removeContext(HttpContext)
295272
* @since 03.03.00
@@ -311,36 +288,13 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
311288
* @see HttpHandler
312289
* @see Authenticator
313290
* @see #createContext(String, Authenticator)
314-
* @see #createContext(String, SimpleHttpHandler, Authenticator)
315291
* @see #removeContext(String)
316292
* @see #removeContext(HttpContext)
317293
* @since 03.03.00
318294
* @author Ktt Development
319295
*/
320296
public abstract HttpContext createContext(final String context, final HttpHandler handler, final Authenticator authenticator);
321297

322-
/**
323-
* Creates a context mapped to a specific {@link HttpContext} with an {@link Authenticator}.
324-
*
325-
* @param context the context
326-
* @param handler the handler
327-
* @param authenticator authenticator
328-
* @return the http context associated with the context
329-
* @throws IllegalArgumentException if the context is invalid or taken
330-
* @throws NullPointerException if the context is null
331-
*
332-
* @see HttpContext
333-
* @see SimpleHttpHandler
334-
* @see Authenticator
335-
* @see #createContext(String, Authenticator)
336-
* @see #createContext(String, HttpHandler, Authenticator)
337-
* @see #removeContext(String)
338-
* @see #removeContext(HttpContext)
339-
* @since 03.03.00
340-
* @author Ktt Development
341-
*/
342-
public abstract HttpContext createContext(final String context, final SimpleHttpHandler handler, final Authenticator authenticator);
343-
344298
//
345299

346300
/**

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

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,6 @@ public synchronized final HttpContext createContext(final String path, final Htt
140140
return context;
141141
}
142142

143-
@Override
144-
public synchronized final HttpContext createContext(final String path, final SimpleHttpHandler handler){
145-
if(!getContext(path).equals("/") && handler instanceof RootHandler)
146-
throw new IllegalArgumentException("RootHandler can only be used at the root '/' context");
147-
148-
final HttpHandler wrapper = exchange -> {
149-
handle(exchange);
150-
handler.handle(SimpleHttpExchange.create(exchange));
151-
};
152-
final HttpContext context = server.createContext(getContext(path),wrapper);
153-
154-
contexts.put(context,context.getHandler());
155-
156-
return context;
157-
}
158-
159143
//
160144

161145
@Override
@@ -172,14 +156,6 @@ public synchronized final HttpContext createContext(final String path, final Htt
172156
return context;
173157
}
174158

175-
@Override
176-
public synchronized final HttpContext createContext(final String path, final SimpleHttpHandler handler, final Authenticator authenticator){
177-
final HttpContext context = createContext(path,handler);
178-
context.setAuthenticator(authenticator);
179-
return context;
180-
}
181-
182-
183159
//
184160

185161
private String generateRandomContext(){

0 commit comments

Comments
 (0)