Examples of ODataErrorContext


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

        "<?xml version='1.0' encoding='UTF-8'?>\n" +
            "<error xmlns=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\">\n" +
            "\t<code>ErrorCode</code>\n" +
            "\t<message xml:lang=\"en-US\">Message</message>\n" +
            "</error>";
    ODataErrorContext errorContext = providerFacade.readErrorDocument(StringHelper.encapsulate(errorDoc),
        ContentType.APPLICATION_XML.toContentTypeString());
    //
    assertEquals("Wrong content type", "application/xml", 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

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

          EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getMessage()), e);
    }
  }

  private ODataErrorContext parseJson(final JsonReader reader) throws IOException, EntityProviderException {
    ODataErrorContext errorContext;

    if (reader.hasNext()) {
      reader.beginObject();
      String currentName = reader.nextName();
      if (FormatJson.ERROR.equals(currentName)) {
        errorContext = parseError(reader);
      } else {
        throw new EntityProviderException(EntityProviderException.INVALID_STATE.addContent(
            "Invalid object with name '" + currentName + "' found."));
      }
    } else {
      throw new EntityProviderException(EntityProviderException.INVALID_STATE.addContent(
          "No content to parse found."));
    }

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

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

    errorContext.setContentType(ContentType.APPLICATION_JSON.toContentTypeString());
    return errorContext;
  }

  private ODataErrorContext parseError(final JsonReader reader) throws IOException, EntityProviderException {
    ODataErrorContext errorContext = new ODataErrorContext();
    String currentName;
    reader.beginObject();
    boolean messageFound = false;
    boolean codeFound = false;

    while (reader.hasNext()) {
      currentName = reader.nextName();
      if (FormatJson.CODE.equals(currentName)) {
        codeFound = true;
        errorContext.setErrorCode(getValue(reader));
      } else if (FormatJson.MESSAGE.equals(currentName)) {
        messageFound = true;
        parseMessage(reader, errorContext);
      } else if (FormatJson.INNER_ERROR.equals(currentName)) {
        parseInnerError(reader, errorContext);
View Full Code Here

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

  private JsonErrorDocumentConsumer jedc = new JsonErrorDocumentConsumer();

  @Test
  public void simpleErrorDocument() throws Exception {
    InputStream in = StringHelper.encapsulate(JSON_ERROR_DOCUMENT_SIMPLE);
    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 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(JSON_ERROR_DOCUMENT_NULL_LOCALE);
    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());
    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(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

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

  }

  @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

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

  }

  @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

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

  }

  @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

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

    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
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.