Skip to content
This repository has been archived by the owner on Dec 14, 2019. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-poitras committed Feb 25, 2015
0 parents commit 1603610
Show file tree
Hide file tree
Showing 36 changed files with 1,614 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.iml
/target
.svn
.metadata
.bin
.idea
uploads/*
71 changes: 71 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.dbrain</groupId>
<artifactId>yaw</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<platform-version>1.0-SNAPSHOT</platform-version>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.dbrain</groupId>
<artifactId>data</artifactId>
<version>0.7</version>
</dependency>
<dependency>
<groupId>org.dbrain</groupId>
<artifactId>templating</artifactId>
<version>0.2</version>
</dependency>
<dependency>
<groupId>org.dbrain.platform</groupId>
<artifactId>guice</artifactId>
<version>${platform-version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.dbrain.platform</groupId>
<artifactId>javax-servlet</artifactId>
<version>${platform-version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.dbrain.platform</groupId>
<artifactId>jetty</artifactId>
<version>${platform-version}</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.dbrain.platform</groupId>
<artifactId>jersey</artifactId>
<version>${platform-version}</version>
<type>pom</type>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
112 changes: 112 additions & 0 deletions src/main/java/org/dbrain/yaw/http/server/HttpConnectorBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package org.dbrain.yaw.http.server;

import org.dbrain.yaw.http.server.config.EndpointConfig;
import org.dbrain.yaw.http.server.config.HttpEndpointConfig;
import org.dbrain.yaw.http.server.config.HttpsEndpointConfig;

import java.net.URI;

/**
* Created with IntelliJ IDEA.
* User: epoitras
* Date: 15/07/13
* Time: 9:01 PM
* To change this template use File | Settings | File Templates.
*/
public class HttpConnectorBuilder {

private boolean secure = false;

private int port = 80;

private int securePort = 443;

private URI keyStore;

private String keyStorePassword;

private String keyManagerPassord;

private String host;

public HttpConnectorBuilder() {
}

public HttpConnectorBuilder( URI serverURI ) {
if ( serverURI != null ) {

if ( serverURI.getScheme() != null ) {
switch ( serverURI.getScheme().toLowerCase() ) {
case "https":
secure = true;
break;
case "http":
secure = false;
break;
default:
throw new IllegalArgumentException( "Unsupported scheme: " + serverURI.getScheme() );
}
}

int port = serverURI.getPort();
if ( port >= 0 ) {
if ( secure ) {
securePort( port );
} else {
port( port );
}
}

host( serverURI.getHost() );
}
}


public HttpConnectorBuilder port( int port ) {
if ( port >= 0 && port < 65536 ) {
this.port = port;
} else {
throw new IllegalArgumentException();
}
return this;
}

public HttpConnectorBuilder securePort( int port ) {
if ( port >= 0 && port < 65536 ) {
this.securePort = port;
} else {
throw new IllegalArgumentException();
}
return this;
}

public HttpConnectorBuilder host( String host ) {
this.host = host;
return this;
}

public HttpConnectorBuilder setupSsl( URI keyStoreUri, String keyStorePassword, String keyManagerPassord ) {
this.keyStore = keyStoreUri;
this.keyStorePassword = keyStorePassword;
this.keyManagerPassord = keyManagerPassord;
return this;
}

public EndpointConfig build() {

if ( secure ) {
HttpsEndpointConfig result = new HttpsEndpointConfig();
result.setPort( port );
result.setSecurePort( securePort );
result.setHost( host );
result.setKeyManagerPassord( keyManagerPassord );
result.setKeyStorePassword( keyStorePassword );
return result;
} else {
HttpEndpointConfig result = new HttpEndpointConfig();
result.setPort( port );
return result;
}
}

}
46 changes: 46 additions & 0 deletions src/main/java/org/dbrain/yaw/http/server/HttpServerBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.dbrain.yaw.http.server;

import org.dbrain.yaw.http.server.config.HttpEndpointConfig;
import org.dbrain.yaw.http.server.config.EndpointConfig;
import org.dbrain.yaw.http.server.config.HttpServerConfig;
import org.dbrain.yaw.http.server.config.ServletContextConfig;

public class HttpServerBuilder {

private HttpServerConfig building = new HttpServerConfig();

public HttpServerBuilder() {
}

public HttpServerBuilder add( EndpointConfig config ) {
if ( config != null ) {
building.getEndPoints().add( config );
}
return this;
}

public HttpServerBuilder add( ServletContextConfig servletContext ) {
if ( servletContext != null ) {
building.getServletContexts().add( servletContext );
}
return this;
}

public HttpServerConfig buildConfig() {
if ( building.getEndPoints().size() == 0 ) {
building.getEndPoints().add( new HttpEndpointConfig() );
}


return building;
}

public <T> T build( HttpServerFactory<T> factory ) {
return factory.build( buildConfig() );
}





}
12 changes: 12 additions & 0 deletions src/main/java/org/dbrain/yaw/http/server/HttpServerFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.dbrain.yaw.http.server;

import org.dbrain.yaw.http.server.config.HttpServerConfig;

/**
* Created by epoitras on 17/09/14.
*/
public interface HttpServerFactory<T> {

public T build( HttpServerConfig def );

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.dbrain.yaw.http.server;

import org.dbrain.yaw.http.server.config.ServletAppSecurityDef;
import org.dbrain.yaw.http.server.config.ServletContextConfig;
import org.dbrain.yaw.http.server.config.ServletConfig;
import org.dbrain.yaw.http.server.config.WebSocketConfig;
import org.dbrain.yaw.http.server.config.ServletFilterConfig;

import javax.servlet.Filter;
import java.util.ArrayList;
import java.util.List;

/**
* Created with IntelliJ IDEA.
* User: epoitras
* Date: 15/07/13
* Time: 9:27 PM
* To change this template use File | Settings | File Templates.
*/
public class ServletContextBuilder {

protected String contextPath;

protected List<ServletConfig> servlets = new ArrayList<>();

protected List<WebSocketConfig> webSockets = new ArrayList<>();

protected List<ServletFilterConfig> filters = new ArrayList<>();

protected ServletAppSecurityDef security;

public ServletContextBuilder( String contextPath ) {
contextPath( contextPath );
}

/**
* Set the serve context path.
*
* @return
*/
public ServletContextBuilder contextPath( String contextPath ) {
this.contextPath = contextPath;
return this;
}

public ServletContextBuilder serve( ServletConfig servletDef ) {
if ( servletDef != null ) {
servlets.add( servletDef );
}
return this;
}

public ServletContextBuilder serve( WebSocketConfig wsd ) {
if ( wsd != null ) {
webSockets.add( wsd );
}
return this;
}

public ServletContextBuilder filter( Filter filter, String pathSpec ) {
filters.add( new ServletFilterConfig( filter, pathSpec ) );
return this;
}

public void security( ServletAppSecurityDef security ) {
this.security = security;
}

public ServletContextConfig build() {
return new ServletContextConfig( contextPath, servlets, filters, webSockets, security );
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.dbrain.yaw.http.server.config;

/**
* @author kilantzis
*/
public class CredentialsDef {

private final String realm;
private final String singleRole;
private final String file;

public CredentialsDef( String realm, String singleRole, String file ) {
this.realm = realm;
this.singleRole = singleRole;
this.file = file;
}

public String getRealm() {
return realm;
}

public String getSingleRole() {
return singleRole;
}

public String getFile() {
return file;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.dbrain.yaw.http.server.config;

public interface EndpointConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.dbrain.yaw.http.server.config;

/**
* @author kilantzis
*/
public class FormLocationDef {

private final String url;
private final String errorURL;

public FormLocationDef( String url, String errorURL ) {
this.url = url;
this.errorURL = errorURL;
}

public String getUrl() {
return url;
}

public String getErrorURL() {
return errorURL;
}
}
Loading

0 comments on commit 1603610

Please sign in to comment.