Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
refactor(http): remove Guava dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jaguililla committed Jul 8, 2015
1 parent 79323de commit ac83929
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper.properties
@@ -1,4 +1,4 @@
#Mon Jun 08 02:30:15 CEST 2015
#Wed Jul 08 00:39:37 CEST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
6 changes: 2 additions & 4 deletions http/build.gradle
Expand Up @@ -15,9 +15,7 @@
description = 'A Sinatra inspired java web framework (http)'

dependencies {
compile 'com.google.guava:guava:18.0'

// SERVER DEPENDENCIES
compile 'org.eclipse.jetty:jetty-webapp:9.2.10.v20150310'
compile 'io.undertow:undertow-servlet:1.1.3.Final'
compile 'org.eclipse.jetty:jetty-webapp:9.3.0.v20150612'
compile 'io.undertow:undertow-servlet:1.2.8.Final'
}
11 changes: 11 additions & 0 deletions http/src/main/java/sabina/Client.java
@@ -0,0 +1,11 @@
package sabina;

/**
* Created by jam on 7/7/15.
*/
public final class Client {
private String keystoreFile;
private String keystorePassword;
private String truststoreFile;
private String truststorePassword;
}
20 changes: 15 additions & 5 deletions http/src/main/java/sabina/Server.java
Expand Up @@ -17,8 +17,12 @@
import static java.lang.Integer.parseInt;
import static java.lang.String.format;
import static java.lang.System.getProperty;
import static java.util.Arrays.asList;
import static java.util.logging.Logger.getLogger;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.logging.Logger;

import sabina.route.RouteMatcher;
Expand Down Expand Up @@ -50,14 +54,14 @@ public final class Server implements Router {
private static final Logger LOG = getLogger (Server.class.getName ());

private static final int DEFAULT_PORT = 4567;
private static final String DEFAULT_HOST = "0.0.0.0";
private static final String DEFAULT_BIND = "0.0.0.0";

public static Server server (final int port) {
return new Server (port);
}

private int port = DEFAULT_PORT;
private String ipAddress = DEFAULT_HOST;
private String bind = DEFAULT_BIND;

private String keystoreFile;
private String keystorePassword;
Expand All @@ -66,6 +70,7 @@ public static Server server (final int port) {

private String staticFileFolder;
private String externalStaticFileFolder;
private List<Consumer<Server>> configurationCallbacks = new ArrayList<> ();

private String backend = getProperty ("sabina.backend", "undertow");

Expand All @@ -85,14 +90,18 @@ public Server (String backend, int port) {
backend (backend);
}

public void configure (Consumer<Server>... callbacks) {
this.configurationCallbacks = asList (callbacks);
}

/**
* Set the IP address that Sabina should listen on. If not called the default
* address is '0.0.0.0'. This has to be called before any route mapping is done.
*
* @param ipAddress The ip.
*/
public void host (String ipAddress) {
this.ipAddress = ipAddress;
this.bind = ipAddress;
}

/**
Expand Down Expand Up @@ -185,10 +194,11 @@ public void filesLocation (String folder, String externalFolder) {
}

public void start () {
configurationCallbacks.stream ().forEach (c -> c.accept (this));
new Thread (() -> {
server = BackendFactory.create (backend, routeMatcher, hasMultipleHandlers ());
server.startUp (
ipAddress,
bind,
port,
keystoreFile,
keystorePassword,
Expand All @@ -197,7 +207,7 @@ public void start () {
staticFileFolder,
externalStaticFileFolder);
}).start ();
LOG.info (format ("Server started at: %s:%s with %s backend", ipAddress, port, backend));
LOG.info (format ("Server started at: %s:%s with %s backend", bind, port, backend));
}

private boolean hasMultipleHandlers () {
Expand Down
12 changes: 5 additions & 7 deletions http/src/main/java/sabina/util/Checks.java
Expand Up @@ -14,7 +14,7 @@

package sabina.util;

import com.google.common.base.Preconditions;
import static java.lang.String.format;

/**
* TODO .
Expand All @@ -23,15 +23,13 @@
*/
public final class Checks {
public static void checkArgument (boolean condition) {
Preconditions.checkArgument (condition);
}

public static void checkArgument (boolean condition, String message) {
Preconditions.checkArgument (condition, message);
if (!condition)
throw new IllegalArgumentException ();
}

public static void checkArgument (boolean condition, String message, Object... arguments) {
Preconditions.checkArgument (condition, message, arguments);
if (!condition)
throw new IllegalArgumentException (format (message, arguments));
}

private Checks () {
Expand Down
2 changes: 1 addition & 1 deletion http/src/main/java/sabina/util/Strings.java
Expand Up @@ -26,7 +26,7 @@
*/
public final class Strings {
public static boolean isNullOrEmpty (String str) {
return com.google.common.base.Strings.isNullOrEmpty (str);
return str == null || str.isEmpty ();
}

public static String encode (final byte[] body, final String encoding) {
Expand Down

0 comments on commit ac83929

Please sign in to comment.