-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
communicate the content type and the base URI to the process via the
contentInStream instead of communicating that via config file. fix the log4j stuff. inherit the logging correctly create a health check for kubernetes purposes
- Loading branch information
1 parent
169f518
commit c3c188f
Showing
9 changed files
with
212 additions
and
97 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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
# version | ||
version=1.0b03 | ||
|
||
# deps | ||
tikaVersion=1.20 | ||
slf4jVersion=1.7.26 | ||
commonsPoolVersion=2.6.2 | ||
junitVersion=4.12 | ||
junitVersion=4.12 | ||
jacksonDatabindVersion=2.4.4 | ||
args4jVersion=2.33 |
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
80 changes: 80 additions & 0 deletions
80
tika-fork-main/src/main/java/org/apache/tika/main/HealthCheckServer.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,80 @@ | ||
package org.apache.tika.main; | ||
|
||
import java.io.BufferedOutputStream; | ||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.io.OutputStream; | ||
import java.io.PrintStream; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
import java.util.Date; | ||
|
||
/** | ||
* Useful for kubernetes. Gives you something for the keepalive check. | ||
* Will return the number of milliseconds since it has seen a parse request. | ||
*/ | ||
public class HealthCheckServer implements Runnable { | ||
public static long LAST_UPDATE = System.currentTimeMillis(); | ||
|
||
private static final String newLine = "\r\n"; | ||
|
||
int port; | ||
|
||
public HealthCheckServer(int port) { | ||
this.port = port; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
ServerSocket socket = new ServerSocket(port); | ||
|
||
while (true) { | ||
Socket connection = socket.accept(); | ||
|
||
try { | ||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
OutputStream out = new BufferedOutputStream(connection.getOutputStream()); | ||
PrintStream pout = new PrintStream(out); | ||
|
||
// read first line of request | ||
String request = in.readLine(); | ||
if (request == null) { | ||
continue; | ||
} | ||
|
||
// we ignore the rest | ||
while (true) { | ||
String ignore = in.readLine(); | ||
if (ignore == null || ignore.length() == 0) { | ||
break; | ||
} | ||
} | ||
|
||
if (!request.startsWith("GET ") || | ||
!(request.endsWith(" HTTP/1.0") || request.endsWith(" HTTP/1.1"))) { | ||
// bad request | ||
pout.print("HTTP/1.0 400 Bad Request" + newLine + newLine); | ||
} else { | ||
String response = String.valueOf(System.currentTimeMillis() - LAST_UPDATE); | ||
|
||
pout.print( | ||
"HTTP/1.0 200 OK" + newLine + | ||
"Content-Type: text/plain" + newLine + | ||
"Date: " + new Date() + newLine + | ||
"Content-length: " + response.length() + newLine + newLine + | ||
response | ||
); | ||
} | ||
|
||
pout.close(); | ||
} catch (Throwable tri) { | ||
System.err.println("Error handling request: " + tri); | ||
} | ||
} | ||
} catch (Throwable tr) { | ||
System.err.println("Could not start server: " + tr); | ||
} | ||
|
||
} | ||
} |
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
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
Oops, something went wrong.