Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- move everything around
- Loading branch information
Showing
120 changed files
with
382 additions
and
8 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 @@ | ||
If having trouble running, open/import by root pom. |
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,5 @@ | ||
Copyright (C) 2020 by IO42630 <ivan@olexyn.com> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
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,2 @@ | ||
### Minimal HTTP Server | ||
Embed by copying code in `MainExample`. |
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,10 @@ | ||
#!/bin/bash | ||
version="0.1" | ||
file="target/min-http-server-${version}.jar" | ||
groupId="com.olexyn.min.http.server" | ||
artifactId="min-http-server" | ||
|
||
|
||
|
||
mvn package | ||
mvn install:install-file -Dfile=${file} -DgroupId=${groupId} -DartifactId=${artifactId} -Dversion=${version} -Dpackaging=jar -DgeneratePom=true |
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,129 @@ | ||
<?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>ch.opendata.hackdaysbe</groupId> | ||
<artifactId>meta-http-server</artifactId> | ||
<version>0.1</version> | ||
<name>min-http-server</name> | ||
<!-- FIXME change it to the project's website --> | ||
<url>http://www.example.com</url> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.7</maven.compiler.source> | ||
<maven.compiler.target>1.7</maven.compiler.target> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-server</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-webapp</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-servlets</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-servlet</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-util</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-http</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-io</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-client</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.websocket</groupId> | ||
<artifactId>websocket-server</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.websocket</groupId> | ||
<artifactId>websocket-client</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.websocket</groupId> | ||
<artifactId>websocket-servlet</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.websocket</groupId> | ||
<artifactId>websocket-api</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.aggregate</groupId> | ||
<artifactId>jetty-all</artifactId> | ||
<version>9.4.28.v20200408</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> | ||
<plugins> | ||
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>3.1.0</version> | ||
</plugin> | ||
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.0.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.5.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.8.2</version> | ||
</plugin> | ||
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> | ||
<plugin> | ||
<artifactId>maven-site-plugin</artifactId> | ||
<version>3.7.1</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-project-info-reports-plugin</artifactId> | ||
<version>3.0.0</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
22 changes: 22 additions & 0 deletions
22
GR_meta/meta-http-server/src/main/java/com/olexyn/min/http/server/MainExample.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,22 @@ | ||
package com.olexyn.min.http.server; | ||
|
||
import com.olexyn.min.http.server.servlets.AsyncServlet; | ||
import com.olexyn.min.http.server.servlets.BlockingServlet; | ||
|
||
|
||
public class MainExample { | ||
public static void main(String... args) { | ||
|
||
MinJettyServer server = new MinJettyServer(); | ||
|
||
server.PORT = 8090; | ||
server.MAX_THREADS = 100; | ||
server.MIN_THREADS = 10; | ||
server.IDLE_TIMEOUT = 120; | ||
|
||
server.addServletWithMapping("/status", BlockingServlet.class); | ||
server.addServletWithMapping("/heavy/async", AsyncServlet.class); | ||
|
||
server.start(); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
GR_meta/meta-http-server/src/main/java/com/olexyn/min/http/server/MinJettyServer.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,59 @@ | ||
package com.olexyn.min.http.server; | ||
|
||
import org.eclipse.jetty.security.SecurityHandler; | ||
import org.eclipse.jetty.server.Connector; | ||
import org.eclipse.jetty.server.HandlerContainer; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.ServerConnector; | ||
import org.eclipse.jetty.server.handler.HandlerWrapper; | ||
import org.eclipse.jetty.server.session.SessionHandler; | ||
import org.eclipse.jetty.servlet.ServletContextHandler; | ||
import org.eclipse.jetty.util.thread.QueuedThreadPool; | ||
|
||
import javax.servlet.Servlet; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class MinJettyServer { | ||
|
||
public int PORT = 8080; | ||
public int MAX_THREADS = 128; | ||
public int MIN_THREADS = 16; | ||
public int IDLE_TIMEOUT = 120; | ||
|
||
final private Map<String, Class<? extends Servlet>> servletURIMapping = new HashMap<>(); | ||
|
||
|
||
public void start() { | ||
|
||
QueuedThreadPool threadPool = new QueuedThreadPool(MAX_THREADS, MIN_THREADS, IDLE_TIMEOUT); | ||
Server server = new Server(threadPool); | ||
ServerConnector connector = new ServerConnector(server); | ||
|
||
|
||
connector.setPort(PORT); | ||
server.setConnectors(new Connector[]{connector}); | ||
|
||
|
||
|
||
|
||
ServletContextHandler servletHandler = new ServletContextHandler(); | ||
|
||
for (Map.Entry<String, Class<? extends Servlet>> entry : servletURIMapping.entrySet()) { | ||
servletHandler.getServletHandler().addServletWithMapping(entry.getValue(), entry.getKey()); | ||
} | ||
|
||
server.setHandler(servletHandler); | ||
try { | ||
server.start(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
|
||
public void addServletWithMapping(String path, Class<? extends Servlet> servlet) { | ||
servletURIMapping.put(path, servlet); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
GR_meta/meta-http-server/src/main/java/com/olexyn/min/http/server/servlets/AsyncServlet.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,42 @@ | ||
package com.olexyn.min.http.server.servlets; | ||
|
||
import javax.servlet.AsyncContext; | ||
import javax.servlet.ServletOutputStream; | ||
import javax.servlet.WriteListener; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class AsyncServlet extends HttpServlet { | ||
private final static String HEAVY_RESOURCE = "This is some heavy resource that will be served in an async way"; | ||
|
||
protected void doGet(HttpServletRequest request, final HttpServletResponse response) throws IOException { | ||
|
||
final ByteBuffer content = ByteBuffer.wrap(HEAVY_RESOURCE.getBytes(StandardCharsets.UTF_8)); | ||
|
||
final AsyncContext async = request.startAsync(); | ||
final ServletOutputStream out = response.getOutputStream(); | ||
out.setWriteListener(new WriteListener() { | ||
@Override | ||
public void onWritePossible() throws IOException { | ||
while (out.isReady()) { | ||
if (!content.hasRemaining()) { | ||
response.setStatus(200); | ||
async.complete(); | ||
return; | ||
} | ||
out.write(content.get()); | ||
} | ||
} | ||
|
||
@Override | ||
public void onError(Throwable t) { | ||
getServletContext().log("Async Error", t); | ||
async.complete(); | ||
} | ||
}); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...a/meta-http-server/src/main/java/com/olexyn/min/http/server/servlets/BlockingServlet.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,16 @@ | ||
package com.olexyn.min.http.server.servlets; | ||
|
||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
|
||
public class BlockingServlet extends HttpServlet { | ||
|
||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
|
||
response.setContentType("application/json"); | ||
response.setStatus(HttpServletResponse.SC_OK); | ||
response.getWriter().println("{ \"status\": \"ok\"}"); | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
..._xml/src/main/java/hack/data/MainApp.java → .../java/ch/opendata/hackdaysbe/MainApp.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
File renamed without changes.
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
2 changes: 1 addition & 1 deletion
2
...ain/java/hack/data/pdf/read/stub/App.java → ...pendata/hackdaysbe/pdf/read/stub/App.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
2 changes: 1 addition & 1 deletion
2
...ack/data/pdf/read/stub/TextExtractor.java → ...ckdaysbe/pdf/read/stub/TextExtractor.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
..._xml/src/test/java/hack/data/AppTest.java → .../java/ch/opendata/hackdaysbe/AppTest.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package hack.data; | ||
package ch.opendata.hackdaysbe; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
|
Oops, something went wrong.