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
|
|
@ -1,19 +1,9 @@
|
|||
package de.kosit.validationtool.daemon;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
|
||||
import lombok.Getter;
|
||||
|
|
@ -22,8 +12,9 @@ import lombok.Setter;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import de.kosit.validationtool.api.Configuration;
|
||||
import de.kosit.validationtool.impl.ConversionService;
|
||||
import de.kosit.validationtool.impl.DefaultCheck;
|
||||
import de.kosit.validationtool.impl.ObjectFactory;
|
||||
import de.kosit.validationtool.model.daemon.HealthType;
|
||||
|
||||
/**
|
||||
* HTTP-Daemon für die Bereitstellung der Prüf-Funktionalität via http.
|
||||
|
|
@ -42,56 +33,6 @@ public class Daemon {
|
|||
|
||||
private final int threadCount;
|
||||
|
||||
/**
|
||||
* Methode, die die Antwort als String-Text schreibt
|
||||
*
|
||||
* @param httpExchange um den Antwort Body zu erhalten
|
||||
* @param rCode der Code-Status
|
||||
* @param response die String antwort, die ich anzeigen möchte
|
||||
*/
|
||||
static void writeError(final HttpExchange httpExchange, final int rCode, final String response) throws IOException {
|
||||
httpExchange.sendResponseHeaders(rCode, response.length());
|
||||
final OutputStream os = httpExchange.getResponseBody();
|
||||
os.write(response.getBytes());
|
||||
os.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode, die die Antwort als String-Text schreibt
|
||||
*
|
||||
* @param httpExchange um den Antwort Body zu erhalten
|
||||
* @param doc der Report
|
||||
*/
|
||||
static void writeOutputstreamArray(final HttpExchange httpExchange, final Document doc)
|
||||
throws IOException, TransformerException {
|
||||
final byte[] bytes = serialize(doc);
|
||||
final OutputStream os = httpExchange.getResponseBody();
|
||||
httpExchange.getResponseHeaders().add("Content-Type", "application/xml");
|
||||
httpExchange.sendResponseHeaders(200, bytes.length);
|
||||
os.write(bytes);
|
||||
os.close();
|
||||
log.debug("Xml File erzeugen ist Fertig ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode zum Serialisieren des Dokuments.
|
||||
*
|
||||
* @param report Vom Typ Dokument, aka Report .
|
||||
*/
|
||||
static byte[] serialize(final Document report) throws TransformerException {
|
||||
|
||||
try ( final ByteArrayOutputStream bArrayOS = new ByteArrayOutputStream() ) {
|
||||
final DOMSource source = new DOMSource(report);
|
||||
final StreamResult streamResult = new StreamResult(bArrayOS);
|
||||
final Transformer transformer = ObjectFactory.createTransformer(true);
|
||||
transformer.transform(source, streamResult);
|
||||
return bArrayOS.toByteArray();
|
||||
} catch (final IOException e) {
|
||||
log.error("Report {}", e.getMessage(), e);
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode zum Starten des Servers
|
||||
*
|
||||
|
|
@ -100,10 +41,14 @@ public class Daemon {
|
|||
public void startServer(final Configuration config) {
|
||||
HttpServer server = null;
|
||||
try {
|
||||
final ConversionService converter = new ConversionService();
|
||||
converter.initialize(HealthType.class.getPackage());
|
||||
|
||||
server = HttpServer.create(new InetSocketAddress(this.hostName, this.port), 0);
|
||||
final DefaultCheck check = new DefaultCheck(config);
|
||||
server.createContext("/", new HttpServerHandler(check));
|
||||
server.createContext("/health", new HealthHandler(config));
|
||||
server.createContext("/", new CheckHandler(check, config.getContentRepository().getProcessor()));
|
||||
server.createContext("/server/health", new HealthHandler(config, converter));
|
||||
server.createContext("/server/config", new ConfigHandler(config, new ConversionService()));
|
||||
server.setExecutor(Executors.newFixedThreadPool(this.threadCount));
|
||||
server.start();
|
||||
log.info("Server unter Port {} ist erfolgreich gestartet", this.port);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue