Search in sources :

Example 1 with InternalServerException

use of org.n52.web.exception.InternalServerException 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);
    }
}
Also used : InputStream(java.io.InputStream) InternalServerException(org.n52.web.exception.InternalServerException) BadRequestException(org.n52.web.exception.BadRequestException) IoParameters(org.n52.io.request.IoParameters) IOException(java.io.IOException) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException)

Example 2 with InternalServerException

use of org.n52.web.exception.InternalServerException in project series-rest-api by 52North.

the class TimeseriesDataController method processRawDataRequest.

private void processRawDataRequest(HttpServletResponse response, RequestSimpleParameterSet query) {
    if (!timeseriesDataService.supportsRawData()) {
        throwNewRawDataQueryNotSupportedException();
    }
    final RawDataService rawDataService = timeseriesDataService.getRawDataService();
    try (InputStream inputStream = rawDataService.getRawData(query)) {
        if (inputStream == null) {
            throw new ResourceNotFoundException("No raw data found.");
        }
        response.setContentType(query.getFormat());
        IOUtils.copyLarge(inputStream, response.getOutputStream());
    } catch (IOException e) {
        throw new InternalServerException("Error while querying raw data", e);
    }
}
Also used : RawDataService(org.n52.series.spi.srv.RawDataService) InputStream(java.io.InputStream) InternalServerException(org.n52.web.exception.InternalServerException) IOException(java.io.IOException) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException)

Example 3 with InternalServerException

use of org.n52.web.exception.InternalServerException 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);
    }
}
Also used : HttpMessageNotReadableException(org.springframework.http.converter.HttpMessageNotReadableException) WebException(org.n52.web.exception.WebException) InternalServerException(org.n52.web.exception.InternalServerException) BadRequestException(org.n52.web.exception.BadRequestException) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 4 with InternalServerException

use of org.n52.web.exception.InternalServerException 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);
    }
}
Also used : RawDataService(org.n52.series.spi.srv.RawDataService) InputStream(java.io.InputStream) InternalServerException(org.n52.web.exception.InternalServerException) BadRequestException(org.n52.web.exception.BadRequestException) IOException(java.io.IOException) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException)

Aggregations

InternalServerException (org.n52.web.exception.InternalServerException)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 BadRequestException (org.n52.web.exception.BadRequestException)3 ResourceNotFoundException (org.n52.web.exception.ResourceNotFoundException)3 RawDataService (org.n52.series.spi.srv.RawDataService)2 IoParameters (org.n52.io.request.IoParameters)1 WebException (org.n52.web.exception.WebException)1 HttpMessageNotReadableException (org.springframework.http.converter.HttpMessageNotReadableException)1 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)1