Package org.apache.olingo.odata2.api.processor

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


  }

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

    assertEquals("Wrong content type", "application/json", 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


  }

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

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

  }

  @Test
  public void innerErrorComplexObject() throws Exception {
    InputStream in = StringHelper.encapsulate(JSON_ERROR_DOCUMENT_INNER_ERROR_COMPLEX_OBJECT);
    ODataErrorContext error = jedc.readError(in);

    assertEquals("Wrong content type", "application/json", error.getContentType());
    assertEquals("Wrong message", "Message", error.getMessage());
    assertEquals("Wrong error code", "ErrorCode", error.getErrorCode());
    assertEquals("Wrong inner error",
        "{\"moreInner\":\"More Inner Error\",\"secondInner\":\"Second\"}", error.getInnerError());
  }
View Full Code Here

  }

  @Test
  public void innerErrorComplexArray() throws Exception {
    InputStream in = StringHelper.encapsulate(JSON_ERROR_DOCUMENT_INNER_ERROR_COMPLEX_ARRAY);
    ODataErrorContext error = jedc.readError(in);

    assertEquals("Wrong content type", "application/json", error.getContentType());
    assertEquals("Wrong message", "Message", error.getMessage());
    assertEquals("Wrong error code", "ErrorCode", error.getErrorCode());
    assertEquals("Wrong inner error",
        "{\"innerArray\":[\"More Inner Error\"\"Second\"]}", error.getInnerError());
  }
View Full Code Here

    reader.require(XMLStreamConstants.START_ELEMENT, Edm.NAMESPACE_M_2007_08, FormatXml.M_ERROR);

    // read error data
    boolean codeFound = false;
    boolean messageFound = false;
    ODataErrorContext errorContext = new ODataErrorContext();
    while (notFinished(reader)) {
      reader.nextTag();
      if (reader.isStartElement()) {
        String name = reader.getLocalName();
        if (FormatXml.M_CODE.equals(name)) {
          codeFound = true;
          handleCode(reader, errorContext);
        } else if (FormatXml.M_MESSAGE.equals(name)) {
          messageFound = true;
          handleMessage(reader, errorContext);
        } else if (FormatXml.M_INNER_ERROR.equals(name)) {
          handleInnerError(reader, errorContext);
        } else {
          throw new EntityProviderException(
              EntityProviderException.INVALID_CONTENT.addContent(name, FormatXml.M_ERROR));
        }
      }
    }
    validate(codeFound, messageFound);

    errorContext.setContentType(ContentType.APPLICATION_XML.toContentTypeString());
    return errorContext;
  }
View Full Code Here

                    switch (responseContentType.getODataFormat()) {
                    case ATOM:
                    case XML:
                    case JSON:
                        final ODataErrorContext errorContext = EntityProvider.readErrorDocument(
                            response.getEntity().getContent(),
                            responseContentType.toString());
                        throw new ODataApplicationException(errorContext.getMessage(),
                            errorContext.getLocale(), httpStatusCode, errorContext.getErrorCode(),
                            errorContext.getException());
                    default:
                        // fall through to default exception with status line information
                    }
                } catch (EntityProviderException e) {
                    throw new ODataApplicationException(e.getMessage(), response.getLocale(), httpStatusCode, e);
View Full Code Here

    XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
  }

  @Test
  public void viaRuntimeDelegate() throws Exception {
    ODataErrorContext context = new ODataErrorContext();
    context.setContentType(contentType);
    context.setHttpStatus(expectedStatus);
    context.setErrorCode(null);
    context.setMessage(null);
    context.setLocale(null);
    context.setInnerError(null);
    ODataResponse response = EntityProvider.writeErrorDocument(context);
    String errorXml = verifyResponse(response);
    verifyXml(null, null, null, null, errorXml);

    context.setErrorCode("a");
    context.setMessage("a");
    context.setLocale(Locale.GERMAN);
    context.setInnerError("a");
    response = EntityProvider.writeErrorDocument(context);
    errorXml = verifyResponse(response);
    verifyXml("a", "a", Locale.GERMAN, "a", errorXml);

    context.setErrorCode(null);
    context.setInnerError(null);
    response = EntityProvider.writeErrorDocument(context);
    errorXml = verifyResponse(response);
    verifyXml(null, "a", Locale.GERMAN, null, errorXml);
  }
View Full Code Here

    String errorCode = null;
    String message = null;
    Locale locale = null;
    String innerError = null;

    ODataErrorContext ctx = new ODataErrorContext();
    ctx.setContentType(contentType);
    ctx.setErrorCode(errorCode);
    ctx.setHttpStatus(expectedStatus);
    ctx.setLocale(locale);
    ctx.setMessage(message);

    ODataResponse response = new ProviderFacadeImpl().writeErrorDocument(ctx);
    String errorXml = verifyResponse(response);
    verifyXml(errorCode, message, locale, innerError, errorXml);

    errorCode = "a";
    message = "a";
    locale = Locale.GERMAN;
    innerError = "a";

    ctx = new ODataErrorContext();
    ctx.setContentType(contentType);
    ctx.setErrorCode(errorCode);
    ctx.setHttpStatus(expectedStatus);
    ctx.setLocale(locale);
    ctx.setMessage(message);
    ctx.setInnerError(innerError);

    response = new ProviderFacadeImpl().writeErrorDocument(ctx);
    errorXml = verifyResponse(response);
    verifyXml(errorCode, message, locale, innerError, errorXml);

    errorCode = null;
    message = "a";
    locale = Locale.GERMAN;
    innerError = null;

    ctx = new ODataErrorContext();
    ctx.setContentType(contentType);
    ctx.setErrorCode(errorCode);
    ctx.setHttpStatus(expectedStatus);
    ctx.setLocale(locale);
    ctx.setMessage(message);
    ctx.setInnerError(innerError);

    response = new ProviderFacadeImpl().writeErrorDocument(ctx);
    errorXml = verifyResponse(response);
    verifyXml(errorCode, message, locale, innerError, errorXml);
  }
View Full Code Here

    testSerializeJSON(null, null, null);
  }

  // helper method
  private void testSerializeJSON(final String errorCode, final String message, final Locale locale) throws Exception {
    ODataErrorContext ctx = new ODataErrorContext();
    ctx.setContentType(HttpContentType.APPLICATION_JSON);
    ctx.setErrorCode(errorCode);
    ctx.setHttpStatus(HttpStatusCodes.INTERNAL_SERVER_ERROR);
    ctx.setLocale(locale);
    ctx.setMessage(message);

    ODataResponse response = new ProviderFacadeImpl().writeErrorDocument(ctx);
    assertNull("EntitypProvider must not set content header", response.getContentHeader());
    assertEquals(ODataServiceVersion.V10, response.getHeader(ODataHttpHeaders.DATASERVICEVERSION));
    final String jsonErrorMessage = StringHelper.inputStreamToString((InputStream) response.getEntity());
View Full Code Here

    return oDataResponse;
  }

  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

TOP

Related Classes of org.apache.olingo.odata2.api.processor.ODataErrorContext

Copyright © 2018 www.massapicom. 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.