Пример #1
0
 public void handleException(
     final ODataRequest request,
     final ODataResponse response,
     final ODataServerError serverError,
     final Exception exception) {
   lastThrownException = exception;
   ErrorProcessor exceptionProcessor;
   try {
     exceptionProcessor = selectProcessor(ErrorProcessor.class);
   } catch (ODataHandlerException e) {
     // This cannot happen since there is always an ExceptionProcessor registered.
     exceptionProcessor = new DefaultProcessor();
   }
   ContentType requestedContentType;
   try {
     requestedContentType =
         ContentNegotiator.doContentNegotiation(
             uriInfo == null ? null : uriInfo.getFormatOption(),
             request,
             getCustomContentTypeSupport(),
             RepresentationType.ERROR);
   } catch (final ContentNegotiatorException e) {
     requestedContentType = ContentType.JSON;
   }
   final int measurementHandle =
       debugger.startRuntimeMeasurement("ErrorProcessor", "processError");
   exceptionProcessor.processError(request, response, serverError, requestedContentType);
   debugger.stopRuntimeMeasurement(measurementHandle);
 }
Пример #2
0
 public ODataResponse process(final ODataRequest request) {
   ODataResponse response = new ODataResponse();
   final int responseHandle = debugger.startRuntimeMeasurement("ODataHandler", "process");
   try {
     processInternal(request, response);
   } catch (final UriValidationException e) {
     ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
     handleException(request, response, serverError, e);
   } catch (final UriParserSemanticException e) {
     ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
     handleException(request, response, serverError, e);
   } catch (final UriParserSyntaxException e) {
     ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
     handleException(request, response, serverError, e);
   } catch (final UriParserException e) {
     ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
     handleException(request, response, serverError, e);
   } catch (ContentNegotiatorException e) {
     ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
     handleException(request, response, serverError, e);
   } catch (SerializerException e) {
     ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
     handleException(request, response, serverError, e);
   } catch (DeserializerException e) {
     ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
     handleException(request, response, serverError, e);
   } catch (PreconditionException e) {
     ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
     handleException(request, response, serverError, e);
   } catch (ODataHandlerException e) {
     ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
     handleException(request, response, serverError, e);
   } catch (ODataApplicationException e) {
     ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
     handleException(request, response, serverError, e);
   } catch (Exception e) {
     ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
     handleException(request, response, serverError, e);
   }
   debugger.stopRuntimeMeasurement(responseHandle);
   return response;
 }
Пример #3
0
  private void processInternal(final ODataRequest request, final ODataResponse response)
      throws ODataApplicationException, ODataLibraryException {
    final int measurementHandle =
        debugger.startRuntimeMeasurement("ODataHandler", "processInternal");

    response.setHeader(HttpHeader.ODATA_VERSION, ODataServiceVersion.V40.toString());
    try {
      validateODataVersion(request);
    } catch (final ODataHandlerException e) {
      debugger.stopRuntimeMeasurement(measurementHandle);
      throw e;
    }

    final int measurementUriParser = debugger.startRuntimeMeasurement("UriParser", "parseUri");
    try {
      uriInfo =
          new Parser()
              .parseUri(
                  request.getRawODataPath(),
                  request.getRawQueryPath(),
                  null,
                  serviceMetadata.getEdm());
    } catch (final ODataLibraryException e) {
      debugger.stopRuntimeMeasurement(measurementUriParser);
      debugger.stopRuntimeMeasurement(measurementHandle);
      throw e;
    }
    debugger.stopRuntimeMeasurement(measurementUriParser);

    final int measurementUriValidator =
        debugger.startRuntimeMeasurement("UriValidator", "validate");
    final HttpMethod method = request.getMethod();
    try {
      new UriValidator().validate(uriInfo, method);
    } catch (final UriValidationException e) {
      debugger.stopRuntimeMeasurement(measurementUriValidator);
      debugger.stopRuntimeMeasurement(measurementHandle);
      throw e;
    }
    debugger.stopRuntimeMeasurement(measurementUriValidator);

    final int measurementDispatcher =
        debugger.startRuntimeMeasurement("ODataDispatcher", "dispatch");
    try {
      new ODataDispatcher(uriInfo, this).dispatch(request, response);
    } finally {
      debugger.stopRuntimeMeasurement(measurementDispatcher);
      debugger.stopRuntimeMeasurement(measurementHandle);
    }
  }