This repository has been archived by the owner on Dec 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1603610
Showing
36 changed files
with
1,614 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.iml | ||
/target | ||
.svn | ||
.metadata | ||
.bin | ||
.idea | ||
uploads/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
112
src/main/java/org/dbrain/yaw/http/server/HttpConnectorBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
46
src/main/java/org/dbrain/yaw/http/server/HttpServerBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
src/main/java/org/dbrain/yaw/http/server/HttpServerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
src/main/java/org/dbrain/yaw/http/server/ServletContextBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/org/dbrain/yaw/http/server/config/CredentialsDef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/org/dbrain/yaw/http/server/config/EndpointConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.dbrain.yaw.http.server.config; | ||
|
||
public interface EndpointConfig { | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/dbrain/yaw/http/server/config/FormLocationDef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.