use of de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.model.HttpRequest in project FAAAST-Service by FraunhoferIOSB.
the class RequestHandler method handle.
@Override
public void handle(String string, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8")) {
@Override
public void close() throws IOException {
request.getInputStream().close();
}
};
HttpRequest httpRequest = HttpRequest.builder().path(request.getRequestURI()).query(request.getQueryString()).body(reader.lines().collect(Collectors.joining(System.lineSeparator()))).method(HttpMethod.valueOf(request.getMethod())).headers(Collections.list(request.getHeaderNames()).stream().collect(Collectors.toMap(x -> x, x -> request.getHeader(x)))).build();
de.fraunhofer.iosb.ilt.faaast.service.model.api.Request apiRequest = null;
try {
apiRequest = mappingManager.map(httpRequest);
} catch (InvalidRequestException | IllegalArgumentException ex) {
// ex.printStackTrace();
sendResultResponse(response, HttpStatus.BAD_REQUEST_400, MessageType.Error, ex.getMessage());
baseRequest.setHandled(true);
return;
}
// TODO more differentiated error codes (must be generated in mappingManager)
try {
executeAndSend(response, apiRequest);
} catch (SerializationException e) {
e.printStackTrace();
}
baseRequest.setHandled(true);
}
Aggregations