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

Commit 9ac655b

Browse files
authored
Added SimpleHttpsServer
Added SimpleHttpsServer and SimpleHttpsServerImpl
2 parents b7d4d99 + e65961b commit 9ac655b

File tree

9 files changed

+443
-52
lines changed

9 files changed

+443
-52
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.kttdevelopment</groupId>
88
<artifactId>simplehttpserver</artifactId>
9-
<version>03.03.00</version>
9+
<version>03.04.00</version>
1010
<packaging>jar</packaging>
1111

1212
<url>https://github.com/Ktt-Development/simplehttpserver</url>

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.sun.net.httpserver.HttpExchange;
55

66
import java.util.*;
7-
import java.util.function.Predicate;
87

98
/**
109
* This class assigns {@link HttpSession} to every client.
@@ -132,12 +131,12 @@ public synchronized final void updateLastAccessTime(){
132131

133132
@SuppressWarnings("StringBufferReplaceableByString")
134133
@Override
135-
public final String toString(){
134+
public String toString(){
136135
final StringBuilder OUT = new StringBuilder();
137-
OUT.append("HttpSession").append('{');
138-
OUT.append("sessionID").append('=').append(sessionID).append(", ");
139-
OUT.append("creationTime").append('=').append(creationTime).append(", ");
140-
OUT.append("lastAccessTime").append('=').append(lastAccessTime);
136+
OUT.append("HttpSession") .append('{');
137+
OUT.append("sessionID") .append('=') .append(sessionID) .append(", ");
138+
OUT.append("creationTime") .append('=') .append(creationTime) .append(", ");
139+
OUT.append("lastAccessTime") .append('=') .append(lastAccessTime);
141140
OUT.append('}');
142141
return OUT.toString();
143142
}

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

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ public class SimpleHttpCookie {
3030
/**
3131
* Creates an HTTP cookie. All fields except for <code>name</code>, <code>secure</code>, <code>httpOnly</code>, and <code>value</code> can be set to null if unused.
3232
*
33-
* @deprecated Use {@link Builder} class instead. This method will be removed in the future
34-
*
3533
* @param name name of the cookie
3634
* @param value value of the cookie
3735
* @param domain what domain to send the cookie to
@@ -45,8 +43,7 @@ public class SimpleHttpCookie {
4543
* @since 02.00.00
4644
* @author Ktt Development
4745
*/
48-
@Deprecated
49-
public SimpleHttpCookie(final String name, final String value, final String domain, final String path, final String sameSite, final Date expires, final Integer maxAge, final Boolean secure, final Boolean httpOnly){
46+
private SimpleHttpCookie(final String name, final String value, final String domain, final String path, final String sameSite, final Date expires, final Integer maxAge, final Boolean secure, final Boolean httpOnly){
5047
if(name == null)
5148
throw new NullPointerException("Cookie name can not be null");
5249
else
@@ -64,41 +61,7 @@ public SimpleHttpCookie(final String name, final String value, final String doma
6461
this.httpOnly = httpOnly;
6562
}
6663

67-
/**
68-
* Converts the cookie to a readable string for the cookie header.
69-
*
70-
* @deprecated Use {@link #toCookieHeaderString()} instead
71-
*
72-
* @return cookie header
73-
*
74-
* @see SimpleHttpExchange#setCookie(SimpleHttpCookie)
75-
* @since 02.00.00
76-
* @author Ktt Development
77-
*/
78-
@SuppressWarnings({"ConstantConditions", "SpellCheckingInspection"})
79-
@Override @Deprecated
80-
public final String toString(){
81-
final StringBuilder OUT = new StringBuilder();
82-
83-
OUT.append(name).append("=").append(value);
84-
if(expires != null)
85-
OUT.append("; Expires=").append(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(expires)).append(" GMT");
86-
if(maxAge != null)
87-
OUT.append("; Max-Age=").append(maxAge);
88-
if(domain != null)
89-
OUT.append("; Domain=").append(domain);
90-
if(path != null)
91-
OUT.append("; Path=").append(path);
92-
if(secure != null && secure)
93-
OUT.append("; Secure=").append(secure);
94-
if(httpOnly != null && httpOnly)
95-
OUT.append("; HttpOnly=").append(httpOnly);
96-
if(sameSite != null)
97-
OUT.append("; SameSite=").append(sameSite);
98-
99-
return OUT.toString();
100-
}
101-
64+
@SuppressWarnings("SpellCheckingInspection")
10265
private final SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
10366

10467
/**
@@ -130,6 +93,25 @@ public final String toCookieHeaderString(){
13093
return OUT.toString();
13194
}
13295

96+
@SuppressWarnings("StringBufferReplaceableByString")
97+
public String toString(){
98+
final StringBuilder OUT = new StringBuilder();
99+
100+
OUT.append("SimpleHttpCookie") .append('{');
101+
OUT.append("name") .append('=') .append(name) .append(", ");
102+
OUT.append("value") .append('=') .append(value) .append(", ");
103+
OUT.append("expires") .append('=') .append(expires) .append(", ");
104+
OUT.append("maxAge") .append('=') .append(maxAge) .append(", ");
105+
OUT.append("domain") .append('=') .append(domain) .append(", ");
106+
OUT.append("path") .append('=') .append(path) .append(", ");
107+
OUT.append("secure") .append('=') .append(secure) .append(", ");
108+
OUT.append("httpOnly") .append('=') .append(httpOnly) .append(", ");
109+
OUT.append("sameSite") .append('=') .append(sameSite);
110+
OUT.append('}');
111+
112+
return OUT.toString();
113+
}
114+
133115
/**
134116
* Builder class for {@link SimpleHttpCookie}.
135117
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ public synchronized final void setAttribute(final String name, final Object valu
417417

418418
@SuppressWarnings("StringBufferReplaceableByString")
419419
@Override
420-
public final String toString(){
420+
public String toString(){
421421
final StringBuilder OUT = new StringBuilder();
422422
OUT.append("SimpleHttpExchange").append('{');
423423
OUT.append("httpServer") .append('=') .append(httpServer) .append(", ");

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*
1515
* @see HttpServer
1616
* @see HttpHandler
17+
* @see SimpleHttpsServer
1718
* @see SimpleHttpHandler
1819
* @since 02.00.00
1920
* @version 03.04.00
@@ -25,7 +26,7 @@ public abstract class SimpleHttpServer {
2526
/**
2627
* Create an empty {@link SimpleHttpServer}. Applications don't use this method.
2728
*
28-
* @see SimpleHttpServerImpl#create(Integer, Integer)
29+
* @see SimpleHttpServerImpl#createHttpServer(Integer, Integer)
2930
* @since 02.00.00
3031
* @author Ktt Development
3132
*/
@@ -43,7 +44,7 @@ public abstract class SimpleHttpServer {
4344
* @author Ktt Development
4445
*/
4546
public static SimpleHttpServer create() throws IOException {
46-
return SimpleHttpServerImpl.create(null,null);
47+
return SimpleHttpServerImpl.createHttpServer(null, null);
4748
}
4849

4950
/**
@@ -60,7 +61,7 @@ public static SimpleHttpServer create() throws IOException {
6061
* @author Ktt Development
6162
*/
6263
public static SimpleHttpServer create(final int port) throws IOException {
63-
return SimpleHttpServerImpl.create(port,null);
64+
return SimpleHttpServerImpl.createHttpServer(port, null);
6465
}
6566

6667
/**
@@ -78,7 +79,7 @@ public static SimpleHttpServer create(final int port) throws IOException {
7879
* @author Ktt Development
7980
*/
8081
public static SimpleHttpServer create(final int port, final int backlog) throws IOException {
81-
return SimpleHttpServerImpl.create(port,backlog);
82+
return SimpleHttpServerImpl.createHttpServer(port,backlog);
8283
}
8384

8485
//

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ final class SimpleHttpServerImpl extends SimpleHttpServer {
4040
* @since 03.04.00
4141
* @author Ktt Development
4242
*/
43-
static SimpleHttpServer create(final Integer port, final Integer backlog) throws IOException{
43+
static SimpleHttpServer createHttpServer(final Integer port, final Integer backlog) throws IOException{
4444
return new SimpleHttpServerImpl(port,backlog);
4545
}
4646

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package com.kttdevelopment.simplehttpserver;
2+
3+
import com.sun.net.httpserver.*;
4+
5+
import java.io.IOException;
6+
7+
/**
8+
* <i>This class is a simplified implementation of {@link HttpsServer}.</i><br>
9+
* At least one {@link HttpHandler} must be created in order to process requests. When handling requests the server will use the most specific context. If no handler can be found it is rejected with a 404 response. <br>
10+
* <b>Contexts are case-sensitive.</b>
11+
*
12+
* @see HttpsServer
13+
* @see HttpHandler
14+
* @see SimpleHttpServer
15+
* @see SimpleHttpHandler
16+
* @since 02.00.00
17+
* @version 03.04.00
18+
* @author Ktt Development
19+
*/
20+
public abstract class SimpleHttpsServer extends SimpleHttpServer {
21+
22+
/**
23+
* Create an empty {@link SimpleHttpsServer}. Applications don't use this method.
24+
*
25+
* @see SimpleHttpsServerImpl#createSimpleHttpsServer(Integer, Integer)
26+
* @since 02.00.00
27+
* @author Ktt Development
28+
*/
29+
SimpleHttpsServer(){ }
30+
31+
//
32+
33+
/**
34+
* Creates a {@link SimpleHttpsServer}.
35+
*
36+
* @return a {@link SimpleHttpsServer}
37+
* @throws IOException uncaught exception
38+
*
39+
* @since 03.04.00
40+
* @author Ktt Development
41+
*/
42+
public static SimpleHttpsServer create() throws IOException {
43+
return SimpleHttpsServerImpl.createSimpleHttpsServer(null, null);
44+
}
45+
46+
/**
47+
* Creates a {@link SimpleHttpsServer} bounded to a port.
48+
*
49+
* @param port port to bind to
50+
* @return a {@link SimpleHttpsServer}
51+
* @throws java.net.BindException if server can not bind to port
52+
* @throws NullPointerException if address is <code>null</code>
53+
* @throws IllegalArgumentException if port is out of range
54+
* @throws IOException uncaught exception
55+
*
56+
* @since 03.04.00
57+
* @author Ktt Development
58+
*/
59+
public static SimpleHttpsServer create(final int port) throws IOException {
60+
return SimpleHttpsServerImpl.createSimpleHttpsServer(port, null);
61+
}
62+
63+
/**
64+
* Creates a {@link SimpleHttpsServer} bounded to a port.
65+
*
66+
* @param port port to bind to
67+
* @param backlog request backlog
68+
* @return a {@link SimpleHttpsServer}
69+
* @throws java.net.BindException if server can not bind to port
70+
* @throws NullPointerException if address is <code>null</code>
71+
* @throws IllegalArgumentException if port is out of range
72+
* @throws IOException uncaught exception
73+
*
74+
* @since 03.04.00
75+
* @author Ktt Development
76+
*/
77+
public static SimpleHttpsServer create(final int port, final int backlog) throws IOException {
78+
return SimpleHttpsServerImpl.createSimpleHttpsServer(port,backlog);
79+
}
80+
81+
//
82+
83+
/**
84+
* Returns the native https server.
85+
*
86+
* @return https server
87+
*
88+
* @see HttpsServer
89+
* @since 03.04.00
90+
* @author Ktt Development
91+
*/
92+
@Override
93+
public abstract HttpsServer getHttpServer();
94+
95+
96+
//
97+
98+
/**
99+
* Sets a https configurator for the server
100+
*
101+
* @param config the https configurator
102+
* @throws NullPointerException if config is null
103+
*
104+
* @since 03.04.00
105+
* @author Ktt Development
106+
*/
107+
public abstract void setHttpsConfigurator(HttpsConfigurator config);
108+
109+
/**
110+
* Returns the https configurator of the server
111+
*
112+
* @return the https configurator
113+
*
114+
* @since 03.04.00
115+
* @author Ktt Development
116+
*/
117+
public abstract HttpsConfigurator getHttpsConfigurator();
118+
119+
}

0 commit comments

Comments
 (0)