use of org.n52.web.exception.BadRequestException in project series-rest-api by 52North.
the class ParameterController method getRawData.
@Override
public void getRawData(HttpServletResponse response, String id, String locale, MultiValueMap<String, String> query) {
RequestUtils.overrideQueryLocaleWhenSet(locale, query);
if (!getParameterService().supportsRawData()) {
throw new BadRequestException("Querying raw procedure data is not supported!");
}
IoParameters queryMap = QueryParameters.createFromQuery(query);
LOGGER.debug("getRawData() with id '{}' and query '{}'", id, queryMap);
try (InputStream inputStream = getParameterService().getRawDataService().getRawData(id, queryMap)) {
if (inputStream == null) {
throw new ResourceNotFoundException("No raw data found for id '" + id + "'.");
}
IOUtils.copyLarge(inputStream, response.getOutputStream());
} catch (IOException e) {
throw new InternalServerException("Error while querying raw data", e);
}
}
use of org.n52.web.exception.BadRequestException in project series-rest-api by 52North.
the class BaseController method handleException.
@ExceptionHandler(value = { RuntimeException.class, Exception.class, Throwable.class })
public void handleException(Exception e, HttpServletRequest request, HttpServletResponse response) {
if (e instanceof HttpMessageNotReadableException) {
WebException wrappedException = new BadRequestException("The request could not been read.", e);
wrappedException.addHint("Check the message which has been sent to the server. Probably it is not valid.");
writeExceptionResponse(wrappedException, response, HttpStatus.BAD_REQUEST);
} else {
WebException wrappedException = new InternalServerException("Unexpected Exception occured.", e);
writeExceptionResponse(wrappedException, response, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
use of org.n52.web.exception.BadRequestException in project series-rest-api by 52North.
the class DataController method writeRawData.
private void writeRawData(RequestSimpleParameterSet parameters, HttpServletResponse response) throws InternalServerException, ResourceNotFoundException, BadRequestException {
if (!dataService.supportsRawData()) {
throw new BadRequestException("Querying of raw timeseries data is not supported " + "by the underlying service!");
}
final RawDataService rawDataService = dataService.getRawDataService();
try (InputStream inputStream = rawDataService.getRawData(parameters)) {
if (inputStream == null) {
throw new ResourceNotFoundException("No raw data found.");
}
response.setContentType(parameters.getRawFormat());
IOUtils.copyLarge(inputStream, response.getOutputStream());
} catch (IOException e) {
throw new InternalServerException("Error while querying raw data", e);
}
}
Aggregations