• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ODataErrorContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.olingo.odata2.api.processor.ODataErrorContext的典型用法代码示例。如果您正苦于以下问题:Java ODataErrorContext类的具体用法?Java ODataErrorContext怎么用?Java ODataErrorContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ODataErrorContext类属于org.apache.olingo.odata2.api.processor包,在下文中一共展示了ODataErrorContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: handleInnerError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
private void handleInnerError(final XMLStreamReader reader, final ODataErrorContext errorContext)
    throws XMLStreamException {

  StringBuilder sb = new StringBuilder();
  while (notFinished(reader, FormatXml.M_INNER_ERROR)) {
    if (reader.hasName() && !FormatXml.M_INNER_ERROR.equals(reader.getLocalName())) {
      sb.append("<");
      if (reader.isEndElement()) {
        sb.append("/");
      }
      sb.append(reader.getLocalName()).append(">");
    } else if (reader.isCharacters()) {
      sb.append(reader.getText());
    }
    reader.next();
  }

  errorContext.setInnerError(sb.toString());
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:20,代码来源:XmlErrorDocumentConsumer.java


示例2: parseJson

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:21,代码来源:JsonErrorDocumentConsumer.java


示例3: readErrorDocumentXml

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
@Test
public void readErrorDocumentXml() throws EntityProviderException {
  ProviderFacadeImpl providerFacade = new ProviderFacadeImpl();
  String errorDoc =
      "<?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());
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:18,代码来源:ProviderFacadeImplTest.java


示例4: testSerializeJSON

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
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());
  assertEquals("{\"error\":{\"code\":"
      + (errorCode == null ? "null" : "\"" + errorCode + "\"")
      + ","
      + "\"message\":{\"lang\":"
      + (locale == null ? "null" : ("\"" + locale.getLanguage()
          + (locale.getCountry().isEmpty() ? "" : ("-" + locale.getCountry())) + "\""))
      + ",\"value\":" + (message == null ? "null" : "\"" + message + "\"") + "}}}",
      jsonErrorMessage);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:22,代码来源:JsonErrorProducerTest.java


示例5: handleError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
@Override
public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
	Throwable rootCause = context.getException();
	LOGGER.error("Error in the OData. Reason: " + rootCause.getMessage(), rootCause); //$NON-NLS-1$

	Throwable innerCause = rootCause.getCause();
	if (rootCause instanceof ODataJPAException && innerCause != null && innerCause instanceof AppODataException) {
		context.setMessage(innerCause.getMessage());
		Throwable childInnerCause = innerCause.getCause();
		context.setInnerError(childInnerCause != null ? childInnerCause.getMessage() : ""); //$NON-NLS-1$
	} else {
		context.setMessage(HttpStatusCodes.INTERNAL_SERVER_ERROR.getInfo());
		context.setInnerError(rootCause.getMessage());
	}

	context.setHttpStatus(HttpStatusCodes.INTERNAL_SERVER_ERROR);
	return EntityProvider.writeErrorDocument(context);
}
 
开发者ID:SAP,项目名称:cloud-sfsf-benefits-ext,代码行数:19,代码来源:SimpleODataErrorCallback.java


示例6: handleError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
/**
 * Handle an error with adding the error message in the stream thanks to 
 * {@link EntityProvider#writeErrorDocument(ODataErrorContext)} method, but
 * when the response stream is not identified as binary stream (uri contains
 * $value), no ascii message is inserted into the stream.
 */
@Override
public ODataResponse handleError(ODataErrorContext ctx) throws ODataApplicationException
{
   // Compute the error message
   String message = ctx.getMessage();
   if (ctx.getException() != null)
   {
      message = ctx.getException().getClass().getSimpleName();
      if (ctx.getException().getMessage() != null)
      {
         message += " : " + ctx.getException().getMessage();
      }
      else if (ctx.getMessage() != null)
      {
         message += " : " + ctx.getMessage();
      }
   }

   // Suppress in-stream error messages
   // ExpectedException are never thrown while streaming the payload
   if (ctx.getRequestUri().toString().endsWith("$value")
         && !(ctx.getException() instanceof ExpectedException))
   {
      return ODataResponse
            .header("cause-message", message)
            .status(HttpStatusCodes.INTERNAL_SERVER_ERROR)
            .build();
   }
   return ODataResponse
         .fromResponse(EntityProvider.writeErrorDocument(ctx))
         .header("cause-message", message)
         .build();
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:40,代码来源:ServiceLogger.java


示例7: handleError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
@Override
public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
  if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
    LOG.error("Internal Server Error", context.getException());
  }

  return EntityProvider.writeErrorDocument(context);
}
 
开发者ID:mirchiseth,项目名称:cf-cars-svc,代码行数:9,代码来源:AnnotationSampleServiceFactory.java


示例8: handleError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
/**
 * Handle an error with adding the error message in the stream thanks to 
 * {@link EntityProvider#writeErrorDocument(ODataErrorContext)} method, but
 * when the response stream is not identified as binary stream (uri contains
 * $value), no ascii message is inserted into the stream.
 */
@Override
public ODataResponse handleError(ODataErrorContext ctx) throws ODataApplicationException
{
   // Compute the error message
   String message = ctx.getMessage();
   if (ctx.getException() != null)
   {
      message = ctx.getException().getClass().getSimpleName();
      if (ctx.getException().getMessage() != null)
      {
         message += " : " + ctx.getException().getMessage();
      }
      else if (ctx.getMessage() != null)
      {
         message += " : " + ctx.getMessage();
      }
   }

   // Suppress in-stream error messages
   // ExpectedException are never thrown while streaming the payload
   if (ctx.getRequestUri().toString().endsWith("$value")
         && (ctx.getException() == null || ctx.getException() instanceof ExpectedException))
   {
      return ODataResponse
            .header("cause-message", message)
            .status(HttpStatusCodes.INTERNAL_SERVER_ERROR)
            .build();
   }
   return ODataResponse
         .fromResponse(EntityProvider.writeErrorDocument(ctx))
         .header("cause-message", message)
         .build();
}
 
开发者ID:SentinelDataHub,项目名称:DataHubSystem,代码行数:40,代码来源:ServiceLogger.java


示例9: handleError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
  if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
    LOG.error("Internal Server Error", context.getException());
  }

  return EntityProvider.writeErrorDocument(context);
}
 
开发者ID:mibo,项目名称:janos,代码行数:8,代码来源:SampleDsServiceFactory.java


示例10: handleError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
@Override
public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
  if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
    LOG.error("Internal Server Error", context.getException());
  }
  return EntityProvider.writeErrorDocument(context);
}
 
开发者ID:mibo,项目名称:janos,代码行数:8,代码来源:FitErrorCallback.java


示例11: handleError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
@Override
public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
	Throwable t = context.getException();
	System.out.println("*************** " + t.toString() + " *********************");
	t.printStackTrace();
	return super.handleError(context);
}
 
开发者ID:shunjikonishi,项目名称:odata-producer,代码行数:8,代码来源:MyODataJPAServiceFactory.java


示例12: handleError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
@Override
public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {

  final String SEPARATOR = " : ";

  Throwable t = context.getException();
  if (t instanceof ODataJPAException && t.getCause() != null) {
    StringBuilder errorBuilder = new StringBuilder();
    errorBuilder.append(t.getCause().getClass().toString());
    errorBuilder.append(SEPARATOR);
    errorBuilder.append(t.getCause().getMessage());
    context.setInnerError(errorBuilder.toString());
  }
  return EntityProvider.writeErrorDocument(context);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:16,代码来源:ODataJPAErrorCallback.java


示例13: parserError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
private ODataErrorContext parserError(final XMLStreamReader reader)
    throws XMLStreamException, EntityProviderException {
  // read xml tag
  reader.require(XMLStreamConstants.START_DOCUMENT, null, null);
  reader.nextTag();

  // read error tag
  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;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:37,代码来源:XmlErrorDocumentConsumer.java


示例14: handleMessage

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
private void handleMessage(final XMLStreamReader reader, final ODataErrorContext errorContext)
    throws XMLStreamException {
  String lang = reader.getAttributeValue(Edm.NAMESPACE_XML_1998, FormatXml.XML_LANG);
  errorContext.setLocale(getLocale(lang));
  String message = reader.getElementText();
  errorContext.setMessage(message);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:8,代码来源:XmlErrorDocumentConsumer.java


示例15: readError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
/**
 * Deserialize / read OData error document in ODataErrorContext.
 * 
 * @param errorDocument OData error document in JSON format
 * @return created ODataErrorContext based on input stream content.
 * @throws EntityProviderException if an exception during read / deserialization occurs.
 */
public ODataErrorContext readError(final InputStream errorDocument) throws EntityProviderException {
  JsonReader reader = createJsonReader(errorDocument);
  try {
    return parseJson(reader);
  } catch (IOException e) {
    throw new EntityProviderException(
        EntityProviderException.EXCEPTION_OCCURRED.addContent(e.getMessage()), e);
  }
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:17,代码来源:JsonErrorDocumentConsumer.java


示例16: parseError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
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);
    } else {
      throw new EntityProviderException(EntityProviderException.INVALID_STATE.addContent(
          "Invalid name '" + currentName + "' found."));
    }
  }

  if (!codeFound) {
    throw new EntityProviderException(
        EntityProviderException.MISSING_PROPERTY.addContent("Mandatory 'code' property not found.'"));
  }
  if (!messageFound) {
    throw new EntityProviderException(
        EntityProviderException.MISSING_PROPERTY.addContent("Mandatory 'message' property not found.'"));
  }

  reader.endObject();
  return errorContext;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:36,代码来源:JsonErrorDocumentConsumer.java


示例17: parseInnerError

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
private void parseInnerError(final JsonReader reader, final ODataErrorContext errorContext) throws IOException {
  JsonToken token = reader.peek();
  if (token == JsonToken.STRING) {
    // implementation for parse content as provided by JsonErrorDocumentProducer
    String innerError = reader.nextString();
    errorContext.setInnerError(innerError);
  } else if (token == JsonToken.BEGIN_OBJECT) {
    // implementation for OData v2 Section 2.2.8.1.2 JSON Error Response
    // (RFC4627 Section 2.2 -> https://www.ietf.org/rfc/rfc4627.txt))
    // currently partial provided
    errorContext.setInnerError(readJson(reader));
  }
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:14,代码来源:JsonErrorDocumentConsumer.java


示例18: parseMessage

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
private void parseMessage(final JsonReader reader, final ODataErrorContext errorContext)
    throws IOException, EntityProviderException {

  reader.beginObject();
  boolean valueFound = false;
  boolean langFound = false;
  String currentName;

  while (reader.hasNext()) {
    currentName = reader.nextName();
    if (FormatJson.LANG.equals(currentName)) {
      langFound = true;
      String langValue = getValue(reader);
      if (langValue != null) {
        errorContext.setLocale(getLocale(langValue));
      }
    } else if (FormatJson.VALUE.equals(currentName)) {
      valueFound = true;
      errorContext.setMessage(getValue(reader));
    } else {
      throw new EntityProviderException(EntityProviderException.INVALID_STATE.addContent("Invalid name '" +
          currentName + "' found."));
    }
  }

  if (!langFound) {
    throw new EntityProviderException(
        EntityProviderException.MISSING_PROPERTY.addContent("Mandatory 'lang' property not found.'"));
  }
  if (!valueFound) {
    throw new EntityProviderException(
        EntityProviderException.MISSING_PROPERTY.addContent("Mandatory 'value' property not found.'"));
  }
  reader.endObject();
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:36,代码来源:JsonErrorDocumentConsumer.java


示例19: writeErrorDocument

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
@Override
public ODataResponse writeErrorDocument(final ODataErrorContext context) {
  try {
    return create(context.getContentType()).writeErrorDocument(context.getHttpStatus(), context.getErrorCode(),
        context.getMessage(), context.getLocale(), context.getInnerError());
  } catch (EntityProviderException e) {
    throw new ODataRuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:10,代码来源:ProviderFacadeImpl.java


示例20: handleWebApplicationException

import org.apache.olingo.odata2.api.processor.ODataErrorContext; //导入依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:8,代码来源:ODataExceptionMapperImpl.java



注:本文中的org.apache.olingo.odata2.api.processor.ODataErrorContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NonElement类代码示例发布时间:2022-05-22
下一篇:
Java OpModeRegistrar类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap