mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
get rid of ObjectFactory.java
This commit is contained in:
parent
5b1d0cd467
commit
d0000fc698
20 changed files with 494 additions and 445 deletions
|
|
@ -0,0 +1,34 @@
|
|||
package de.kosit.validationtool.daemon;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpHandler;
|
||||
|
||||
/**
|
||||
* Simple base implemenation for http handlers. Doing I/O stuff.
|
||||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public abstract class BaseHandler implements HttpHandler {
|
||||
|
||||
protected static final String APPLICATION_XML = "application/xml";
|
||||
|
||||
protected static void write(final HttpExchange exchange, final byte[] content, final String contentType) throws IOException {
|
||||
final OutputStream os = exchange.getResponseBody();
|
||||
exchange.getResponseHeaders().add("Content-Type", contentType);
|
||||
exchange.sendResponseHeaders(200, content.length);
|
||||
os.write(content);
|
||||
os.close();
|
||||
}
|
||||
|
||||
protected static void error(final HttpExchange httpExchange, final int statusCode, final String message) throws IOException {
|
||||
final byte[] bytes = message.getBytes();
|
||||
httpExchange.sendResponseHeaders(statusCode, bytes.length);
|
||||
final OutputStream os = httpExchange.getResponseBody();
|
||||
os.write(bytes);
|
||||
os.close();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue