Search in sources :

Example 1 with Stopwatch

use of org.n52.web.common.Stopwatch in project series-rest-api by 52North.

the class StationsParameterController method getItem.

@RequestMapping(value = "/{item}", method = RequestMethod.GET)
public ModelAndView getItem(@PathVariable("item") String procedureId, @RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestParam(required = false) MultiValueMap<String, String> query) {
    RequestUtils.overrideQueryLocaleWhenSet(locale, query);
    IoParameters map = QueryParameters.createFromQuery(query);
    map = IoParameters.ensureBackwardsCompatibility(map);
    // TODO check parameters and throw BAD_REQUEST if invalid
    Stopwatch stopwatch = Stopwatch.startStopwatch();
    Object result = parameterService.getParameter(procedureId, map);
    logRequestTime(stopwatch);
    if (result == null) {
        throw new ResourceNotFoundException("Found no station with given id.");
    }
    return new ModelAndView().addObject(result);
}
Also used : Stopwatch(org.n52.web.common.Stopwatch) ModelAndView(org.springframework.web.servlet.ModelAndView) IoParameters(org.n52.io.request.IoParameters) ResourceNotFoundException(org.n52.web.exception.ResourceNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Stopwatch

use of org.n52.web.common.Stopwatch in project series-rest-api by 52North.

the class StationsParameterController method getCollection.

@RequestMapping(method = RequestMethod.GET)
public ModelAndView getCollection(@RequestHeader(value = Parameters.HttpHeader.ACCEPT_LANGUAGE) String locale, @RequestParam(required = false) MultiValueMap<String, String> query) {
    RequestUtils.overrideQueryLocaleWhenSet(locale, query);
    IoParameters map = QueryParameters.createFromQuery(query);
    map = IoParameters.ensureBackwardsCompatibility(map);
    if (map.isExpanded()) {
        Stopwatch stopwatch = Stopwatch.startStopwatch();
        OutputCollection<?> result = parameterService.getExpandedParameters(map);
        logRequestTime(stopwatch);
        // TODO add paging
        return new ModelAndView().addObject(result.getItems());
    } else {
        Stopwatch stopwatch = Stopwatch.startStopwatch();
        OutputCollection<?> result = parameterService.getCondensedParameters(map);
        logRequestTime(stopwatch);
        // TODO add paging
        return new ModelAndView().addObject(result.getItems());
    }
}
Also used : Stopwatch(org.n52.web.common.Stopwatch) ModelAndView(org.springframework.web.servlet.ModelAndView) IoParameters(org.n52.io.request.IoParameters) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Stopwatch

use of org.n52.web.common.Stopwatch in project series-rest-api by 52North.

the class TimeseriesDataController method getTimeseriesData.

private DataCollection<QuantityData> getTimeseriesData(RequestSimpleParameterSet parameters) {
    Stopwatch stopwatch = Stopwatch.startStopwatch();
    DataCollection<QuantityData> timeseriesData = parameters.isGeneralize() ? new GeneralizingQuantityService(timeseriesDataService).getData(parameters) : timeseriesDataService.getData(parameters);
    LOGGER.debug("Processing request took {} seconds.", stopwatch.stopInSeconds());
    return timeseriesData;
}
Also used : Stopwatch(org.n52.web.common.Stopwatch) GeneralizingQuantityService(org.n52.io.quantity.generalize.GeneralizingQuantityService) QuantityData(org.n52.io.response.dataset.quantity.QuantityData)

Example 4 with Stopwatch

use of org.n52.web.common.Stopwatch in project arctic-sea by 52North.

the class Service method logResponse.

private void logResponse(HttpServletRequest request, HttpServletResponse response, long count, Stopwatch stopwatch) {
    long elapsed = stopwatch.stop().elapsed(TimeUnit.MILLISECONDS);
    this.serviceEventBus.submit(new OutgoingResponseEvent(request, response, count, elapsed));
    LOGGER.debug("Outgoing response for request No. {} is committed = {} (took {} ms)", count, response.isCommitted(), elapsed);
}
Also used : OutgoingResponseEvent(org.n52.iceland.event.events.OutgoingResponseEvent)

Example 5 with Stopwatch

use of org.n52.web.common.Stopwatch in project arctic-sea by 52North.

the class Service method put.

@RequestMapping(method = RequestMethod.PUT)
public void put(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    long currentCount = logRequest(request);
    try {
        getBinding(request).doPutOperation(request, response);
    } catch (HTTPException exception) {
        onHttpException(request, response, exception);
    } finally {
        logResponse(request, response, currentCount, stopwatch);
    }
}
Also used : HTTPException(org.n52.iceland.exception.HTTPException) Stopwatch(com.google.common.base.Stopwatch) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Stopwatch (org.n52.web.common.Stopwatch)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 IoParameters (org.n52.io.request.IoParameters)8 Stopwatch (com.google.common.base.Stopwatch)5 HTTPException (org.n52.iceland.exception.HTTPException)5 ModelAndView (org.springframework.web.servlet.ModelAndView)4 HashMap (java.util.HashMap)2 ResourceNotFoundException (org.n52.web.exception.ResourceNotFoundException)2 JobDataMap (org.quartz.JobDataMap)2 JobDetail (org.quartz.JobDetail)2 Binding (org.n52.iceland.binding.Binding)1 OutgoingResponseEvent (org.n52.iceland.event.events.OutgoingResponseEvent)1 RenderingConfig (org.n52.io.PrerenderingJobConfig.RenderingConfig)1 GeneralizingQuantityService (org.n52.io.quantity.generalize.GeneralizingQuantityService)1 Data (org.n52.io.response.dataset.Data)1 QuantityData (org.n52.io.response.dataset.quantity.QuantityData)1 RenderingConfig (org.n52.io.task.PreRenderingConfig.RenderingConfig)1 GeneralizingQuantityService (org.n52.io.type.quantity.generalize.GeneralizingQuantityService)1 OffsetBasedPagination (org.n52.web.common.OffsetBasedPagination)1 Paginated (org.n52.web.common.Paginated)1