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

Commit e1c7405

Browse files
authored
Merge branch 'http-handler/encapsulation' into http-handler/encapsulation-patch
2 parents bf10a0b + bfc96d9 commit e1c7405

File tree

4 files changed

+16
-86
lines changed

4 files changed

+16
-86
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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,22 @@
1313
* @version 03.03.00
1414
* @author Ktt Development
1515
*/
16-
public interface SimpleHttpHandler {
16+
17+
public interface SimpleHttpHandler extends HttpHandler {
18+
19+
/**
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.
21+
*
22+
* @param exchange client information
23+
* @throws IOException internal failure
24+
*
25+
* @since 02.00.00
26+
* @author Ktt Development
27+
*/
28+
@Override
29+
default void handle(final HttpExchange exchange) throws IOException{
30+
handle(SimpleHttpExchange.create(exchange));
31+
}
1732

1833
/**
1934
* Handlers the given request and generates a response <b>if no exceptions occur</b>.

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

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
229229
*
230230
* @see HttpContext
231231
* @see #createContext(String, HttpHandler)
232-
* @see #createContext(String, SimpleHttpHandler)
233232
* @see #removeContext(String)
234233
* @see #removeContext(HttpContext)
235234
* @since 02.00.00
@@ -249,34 +248,13 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
249248
* @see HttpContext
250249
* @see HttpHandler
251250
* @see #createContext(String)
252-
* @see #createContext(String, SimpleHttpHandler)
253251
* @see #removeContext(String)
254252
* @see #removeContext(HttpContext)
255253
* @since 02.00.00
256254
* @author Ktt Development
257255
*/
258256
public abstract HttpContext createContext(final String context, final HttpHandler handler);
259257

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

282260
/**
@@ -291,7 +269,6 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
291269
* @see HttpContext
292270
* @see Authenticator
293271
* @see #createContext(String, HttpHandler, Authenticator)
294-
* @see #createContext(String, SimpleHttpHandler, Authenticator)
295272
* @see #removeContext(String)
296273
* @see #removeContext(HttpContext)
297274
* @since 03.03.00
@@ -313,36 +290,13 @@ public static SimpleHttpServer create(final int port, final int backlog) throws
313290
* @see HttpHandler
314291
* @see Authenticator
315292
* @see #createContext(String, Authenticator)
316-
* @see #createContext(String, SimpleHttpHandler, Authenticator)
317293
* @see #removeContext(String)
318294
* @see #removeContext(HttpContext)
319295
* @since 03.03.00
320296
* @author Ktt Development
321297
*/
322298
public abstract HttpContext createContext(final String context, final HttpHandler handler, final Authenticator authenticator);
323299

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

348302
/**

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

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

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

164148
@Override
@@ -175,14 +159,6 @@ public synchronized final HttpContext createContext(final String path, final Htt
175159
return context;
176160
}
177161

178-
@Override
179-
public synchronized final HttpContext createContext(final String path, final SimpleHttpHandler handler, final Authenticator authenticator){
180-
final HttpContext context = createContext(path,handler);
181-
context.setAuthenticator(authenticator);
182-
return context;
183-
}
184-
185-
186162
//
187163

188164
private String generateRandomContext(){

0 commit comments

Comments
 (0)