Examples of ODataErrorContext


Examples of org.apache.olingo.odata2.api.processor.ODataErrorContext

  private XmlErrorDocumentConsumer xedc = new XmlErrorDocumentConsumer();

  @Test
  public void simpleErrorDocument() throws Exception {
    InputStream in = StringHelper.encapsulate(XML_ERROR_DOCUMENT_SIMPLE);
    ODataErrorContext error = xedc.readError(in);

    assertEquals("Wrong content type", "application/xml", error.getContentType());
    assertEquals("Wrong message", "Message", error.getMessage());
    assertEquals("Wrong error code", "ErrorCode", error.getErrorCode());
    assertEquals("Wrong locale for lang", Locale.US, error.getLocale());
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataErrorContext

  @Test
  public void emptyMessage() throws EntityProviderException {
    InputStream in = StringHelper.encapsulate(XML_ERROR_DOCUMENT_EMPTY_MESSAGE);

    ODataErrorContext error = xedc.readError(in);

    assertEquals("Wrong content type", "application/xml", error.getContentType());
    assertEquals("Wrong message", "", error.getMessage());
    assertEquals("Wrong error code", "ErrorCode", error.getErrorCode());
    assertEquals("Wrong locale for lang", Locale.US, error.getLocale());
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataErrorContext

  }

  @Test
  public void localeNull() throws Exception {
    InputStream in = StringHelper.encapsulate(XML_ERROR_DOCUMENT_NULL_LOCALE);
    ODataErrorContext error = xedc.readError(in);

    assertEquals("Wrong content type", "application/xml", error.getContentType());
    assertEquals("Wrong message", "Message", error.getMessage());
    assertEquals("Wrong error code", "ErrorCode", error.getErrorCode());
    assertNull("Expected NULL for locale", error.getLocale());
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataErrorContext

  }

  @Test
  public void innerError() throws Exception {
    InputStream in = StringHelper.encapsulate(XML_ERROR_DOCUMENT_INNER_ERROR);
    ODataErrorContext error = xedc.readError(in);

    assertEquals("Wrong content type", "application/xml", error.getContentType());
    assertEquals("Wrong message", "Message", error.getMessage());
    assertEquals("Wrong error code", "ErrorCode", error.getErrorCode());
    assertEquals("Wrong inner error", "Some InnerError", error.getInnerError());
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataErrorContext

  }

  @Test
  public void innerErrorComplex() throws Exception {
    InputStream in = StringHelper.encapsulate(XML_ERROR_DOCUMENT_INNER_ERROR_COMPLEX);
    ODataErrorContext error = xedc.readError(in);

    assertEquals("Wrong content type", "application/xml", error.getContentType());
    assertEquals("Wrong message", "Message", error.getMessage());
    assertEquals("Wrong error code", "ErrorCode", error.getErrorCode());
    assertEquals("Wrong inner error", "<moreInner>More Inner Error</moreInner>", error.getInnerError());
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataErrorContext

    String innerErrorText = "<firstTag>tagText</firstTag><secondTag>secondText</secondTag>";
    String innerError = "<innererror>" + innerErrorText + "</innererror>";
    String errorDocument = XML_ERROR_DOCUMENT_INNER_ERROR_COMPLEX.replaceAll(
        "<innererror.*error>", innerError);
    InputStream in = StringHelper.encapsulate(errorDocument);
    ODataErrorContext error = xedc.readError(in);

    assertEquals("Wrong content type", "application/xml", error.getContentType());
    assertEquals("Wrong message", "Message", error.getMessage());
    assertEquals("Wrong error code", "ErrorCode", error.getErrorCode());
    assertEquals("Wrong inner error", innerErrorText, error.getInnerError());
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataErrorContext

    String innerErrorText = "\n\t<firstTag>tagText</firstTag>\n<secondTag>secondText</secondTag>\n";
    String innerError = "<innererror>" + innerErrorText + "</innererror>";
    String errorDocument = XML_ERROR_DOCUMENT_INNER_ERROR_COMPLEX.replaceAll(
        "<innererror.*error>", innerError);
    InputStream in = StringHelper.encapsulate(errorDocument);
    ODataErrorContext error = xedc.readError(in);

    assertEquals("Wrong content type", "application/xml", error.getContentType());
    assertEquals("Wrong message", "Message", error.getMessage());
    assertEquals("Wrong error code", "ErrorCode", error.getErrorCode());
    assertEquals("Wrong inner error", innerErrorText, error.getInnerError());
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataErrorContext

    return exceptionWrapper.wrapInExceptionResponse(exception);
  }

  private ODataResponse handleWebApplicationException(final Exception exception) throws ClassNotFoundException,
      InstantiationException, IllegalAccessException, EntityProviderException {
    ODataErrorContext errorContext = createErrorContext((WebApplicationException) exception);
    ODataErrorCallback callback = getErrorHandlerCallback();
    return callback == null ?
        new ProviderFacadeImpl().writeErrorDocument(errorContext) : executeErrorCallback(errorContext, callback);
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataErrorContext

    }
    return oDataResponse;
  }

  private ODataErrorContext createErrorContext(final WebApplicationException exception) {
    ODataErrorContext context = new ODataErrorContext();
    if (uriInfo != null) {
      context.setRequestUri(uriInfo.getRequestUri());
    }
    if (httpHeaders != null && httpHeaders.getRequestHeaders() != null) {
      MultivaluedMap<String, String> requestHeaders = httpHeaders.getRequestHeaders();
      Set<Entry<String, List<String>>> entries = requestHeaders.entrySet();
      for (Entry<String, List<String>> entry : entries) {
        context.putRequestHeader(entry.getKey(), entry.getValue());
      }
    }
    context.setContentType(getContentType().toContentTypeString());
    context.setException(exception);
    context.setErrorCode(null);
    context.setMessage(exception.getMessage());
    context.setLocale(DEFAULT_RESPONSE_LOCALE);
    HttpStatusCodes statusCode = HttpStatusCodes.fromStatusCode(exception.getResponse().getStatus());
    context.setHttpStatus(statusCode);
    if (statusCode == HttpStatusCodes.METHOD_NOT_ALLOWED) {
      // RFC 2616, 5.1.1: " An origin server SHOULD return the status code
      // 405 (Method Not Allowed) if the method is known by the origin server
      // but not allowed for the requested resource, and 501 (Not Implemented)
      // if the method is unrecognized or not implemented by the origin server."
      // Since all recognized methods are handled elsewhere, we unconditionally
      // switch to 501 here for not-allowed exceptions thrown directly from
      // JAX-RS implementations.
      context.setHttpStatus(HttpStatusCodes.NOT_IMPLEMENTED);
      context.setMessage("The request dispatcher does not allow the HTTP method used for the request.");
      context.setLocale(Locale.ENGLISH);
    }
    return context;
  }
View Full Code Here

Examples of org.apache.olingo.odata2.api.processor.ODataErrorContext

  @Test
  public void readErrorDocumentJson() throws EntityProviderException {
    ProviderFacadeImpl providerFacade = new ProviderFacadeImpl();
    String errorDoc = "{\"error\":{\"code\":\"ErrorCode\",\"message\":{\"lang\":\"en-US\",\"value\":\"Message\"}}}";
    ODataErrorContext errorContext = providerFacade.readErrorDocument(StringHelper.encapsulate(errorDoc),
        ContentType.APPLICATION_JSON.toContentTypeString());
    //
    assertEquals("Wrong content type", "application/json", errorContext.getContentType());
    assertEquals("Wrong message", "Message", errorContext.getMessage());
    assertEquals("Wrong error code", "ErrorCode", errorContext.getErrorCode());
    assertEquals("Wrong locale for lang", Locale.US, errorContext.getLocale());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.