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

Added SimpleHttpsServer #43

Merged
merged 5 commits into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.kttdevelopment</groupId>
<artifactId>simplehttpserver</artifactId>
<version>03.03.00</version>
<version>03.04.00</version>
<packaging>jar</packaging>

<url>https://github.com/Ktt-Development/simplehttpserver</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.sun.net.httpserver.HttpExchange;

import java.util.*;
import java.util.function.Predicate;

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

@SuppressWarnings("StringBufferReplaceableByString")
@Override
public final String toString(){
public String toString(){
final StringBuilder OUT = new StringBuilder();
OUT.append("HttpSession").append('{');
OUT.append("sessionID").append('=').append(sessionID).append(", ");
OUT.append("creationTime").append('=').append(creationTime).append(", ");
OUT.append("lastAccessTime").append('=').append(lastAccessTime);
OUT.append("HttpSession") .append('{');
OUT.append("sessionID") .append('=') .append(sessionID) .append(", ");
OUT.append("creationTime") .append('=') .append(creationTime) .append(", ");
OUT.append("lastAccessTime") .append('=') .append(lastAccessTime);
OUT.append('}');
return OUT.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public class SimpleHttpCookie {
/**
* 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.
*
* @deprecated Use {@link Builder} class instead. This method will be removed in the future
*
* @param name name of the cookie
* @param value value of the cookie
* @param domain what domain to send the cookie to
Expand All @@ -45,8 +43,7 @@ public class SimpleHttpCookie {
* @since 02.00.00
* @author Ktt Development
*/
@Deprecated
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){
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){
if(name == null)
throw new NullPointerException("Cookie name can not be null");
else
Expand All @@ -64,41 +61,7 @@ public SimpleHttpCookie(final String name, final String value, final String doma
this.httpOnly = httpOnly;
}

/**
* Converts the cookie to a readable string for the cookie header.
*
* @deprecated Use {@link #toCookieHeaderString()} instead
*
* @return cookie header
*
* @see SimpleHttpExchange#setCookie(SimpleHttpCookie)
* @since 02.00.00
* @author Ktt Development
*/
@SuppressWarnings({"ConstantConditions", "SpellCheckingInspection"})
@Override @Deprecated
public final String toString(){
final StringBuilder OUT = new StringBuilder();

OUT.append(name).append("=").append(value);
if(expires != null)
OUT.append("; Expires=").append(new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(expires)).append(" GMT");
if(maxAge != null)
OUT.append("; Max-Age=").append(maxAge);
if(domain != null)
OUT.append("; Domain=").append(domain);
if(path != null)
OUT.append("; Path=").append(path);
if(secure != null && secure)
OUT.append("; Secure=").append(secure);
if(httpOnly != null && httpOnly)
OUT.append("; HttpOnly=").append(httpOnly);
if(sameSite != null)
OUT.append("; SameSite=").append(sameSite);

return OUT.toString();
}

@SuppressWarnings("SpellCheckingInspection")
private final SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");

/**
Expand Down Expand Up @@ -130,6 +93,25 @@ public final String toCookieHeaderString(){
return OUT.toString();
}

@SuppressWarnings("StringBufferReplaceableByString")
public String toString(){
final StringBuilder OUT = new StringBuilder();

OUT.append("SimpleHttpCookie") .append('{');
OUT.append("name") .append('=') .append(name) .append(", ");
OUT.append("value") .append('=') .append(value) .append(", ");
OUT.append("expires") .append('=') .append(expires) .append(", ");
OUT.append("maxAge") .append('=') .append(maxAge) .append(", ");
OUT.append("domain") .append('=') .append(domain) .append(", ");
OUT.append("path") .append('=') .append(path) .append(", ");
OUT.append("secure") .append('=') .append(secure) .append(", ");
OUT.append("httpOnly") .append('=') .append(httpOnly) .append(", ");
OUT.append("sameSite") .append('=') .append(sameSite);
OUT.append('}');

return OUT.toString();
}

/**
* Builder class for {@link SimpleHttpCookie}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public synchronized final void setAttribute(final String name, final Object valu

@SuppressWarnings("StringBufferReplaceableByString")
@Override
public final String toString(){
public String toString(){
final StringBuilder OUT = new StringBuilder();
OUT.append("SimpleHttpExchange").append('{');
OUT.append("httpServer") .append('=') .append(httpServer) .append(", ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
* @see HttpServer
* @see HttpHandler
* @see SimpleHttpsServer
* @see SimpleHttpHandler
* @since 02.00.00
* @version 03.04.00
Expand All @@ -25,7 +26,7 @@ public abstract class SimpleHttpServer {
/**
* Create an empty {@link SimpleHttpServer}. Applications don't use this method.
*
* @see SimpleHttpServerImpl#create(Integer, Integer)
* @see SimpleHttpServerImpl#createHttpServer(Integer, Integer)
* @since 02.00.00
* @author Ktt Development
*/
Expand All @@ -43,7 +44,7 @@ public abstract class SimpleHttpServer {
* @author Ktt Development
*/
public static SimpleHttpServer create() throws IOException {
return SimpleHttpServerImpl.create(null,null);
return SimpleHttpServerImpl.createHttpServer(null, null);
}

/**
Expand All @@ -60,7 +61,7 @@ public static SimpleHttpServer create() throws IOException {
* @author Ktt Development
*/
public static SimpleHttpServer create(final int port) throws IOException {
return SimpleHttpServerImpl.create(port,null);
return SimpleHttpServerImpl.createHttpServer(port, null);
}

/**
Expand All @@ -78,7 +79,7 @@ public static SimpleHttpServer create(final int port) throws IOException {
* @author Ktt Development
*/
public static SimpleHttpServer create(final int port, final int backlog) throws IOException {
return SimpleHttpServerImpl.create(port,backlog);
return SimpleHttpServerImpl.createHttpServer(port,backlog);
}

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class SimpleHttpServerImpl extends SimpleHttpServer {
* @since 03.04.00
* @author Ktt Development
*/
static SimpleHttpServer create(final Integer port, final Integer backlog) throws IOException{
static SimpleHttpServer createHttpServer(final Integer port, final Integer backlog) throws IOException{
return new SimpleHttpServerImpl(port,backlog);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package com.kttdevelopment.simplehttpserver;

import com.sun.net.httpserver.*;

import java.io.IOException;

/**
* <i>This class is a simplified implementation of {@link HttpsServer}.</i><br>
* 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>
* <b>Contexts are case-sensitive.</b>
*
* @see HttpsServer
* @see HttpHandler
* @see SimpleHttpServer
* @see SimpleHttpHandler
* @since 02.00.00
* @version 03.04.00
* @author Ktt Development
*/
public abstract class SimpleHttpsServer extends SimpleHttpServer {

/**
* Create an empty {@link SimpleHttpsServer}. Applications don't use this method.
*
* @see SimpleHttpsServerImpl#createSimpleHttpsServer(Integer, Integer)
* @since 02.00.00
* @author Ktt Development
*/
SimpleHttpsServer(){ }

//

/**
* Creates a {@link SimpleHttpsServer}.
*
* @return a {@link SimpleHttpsServer}
* @throws IOException uncaught exception
*
* @since 03.04.00
* @author Ktt Development
*/
public static SimpleHttpsServer create() throws IOException {
return SimpleHttpsServerImpl.createSimpleHttpsServer(null, null);
}

/**
* Creates a {@link SimpleHttpsServer} bounded to a port.
*
* @param port port to bind to
* @return a {@link SimpleHttpsServer}
* @throws java.net.BindException if server can not bind to port
* @throws NullPointerException if address is <code>null</code>
* @throws IllegalArgumentException if port is out of range
* @throws IOException uncaught exception
*
* @since 03.04.00
* @author Ktt Development
*/
public static SimpleHttpsServer create(final int port) throws IOException {
return SimpleHttpsServerImpl.createSimpleHttpsServer(port, null);
}

/**
* Creates a {@link SimpleHttpsServer} bounded to a port.
*
* @param port port to bind to
* @param backlog request backlog
* @return a {@link SimpleHttpsServer}
* @throws java.net.BindException if server can not bind to port
* @throws NullPointerException if address is <code>null</code>
* @throws IllegalArgumentException if port is out of range
* @throws IOException uncaught exception
*
* @since 03.04.00
* @author Ktt Development
*/
public static SimpleHttpsServer create(final int port, final int backlog) throws IOException {
return SimpleHttpsServerImpl.createSimpleHttpsServer(port,backlog);
}

//

/**
* Returns the native https server.
*
* @return https server
*
* @see HttpsServer
* @since 03.04.00
* @author Ktt Development
*/
@Override
public abstract HttpsServer getHttpServer();


//

/**
* Sets a https configurator for the server
*
* @param config the https configurator
* @throws NullPointerException if config is null
*
* @since 03.04.00
* @author Ktt Development
*/
public abstract void setHttpsConfigurator(HttpsConfigurator config);

/**
* Returns the https configurator of the server
*
* @return the https configurator
*
* @since 03.04.00
* @author Ktt Development
*/
public abstract HttpsConfigurator getHttpsConfigurator();

}
Loading