当前位置: 首页>>代码示例>>Java>>正文


Java ServiceException.getHttpErrorCodeOverride方法代码示例

本文整理汇总了Java中com.google.gdata.util.ServiceException.getHttpErrorCodeOverride方法的典型用法代码示例。如果您正苦于以下问题:Java ServiceException.getHttpErrorCodeOverride方法的具体用法?Java ServiceException.getHttpErrorCodeOverride怎么用?Java ServiceException.getHttpErrorCodeOverride使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gdata.util.ServiceException的用法示例。


在下文中一共展示了ServiceException.getHttpErrorCodeOverride方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printServiceException

import com.google.gdata.util.ServiceException; //导入方法依赖的package包/类
/**
 * Prints an error message returned by the server, if any.
 * 
 * @param e an exception that may contain an error message from the server
 */
protected static void printServiceException(ServiceException e) {

  System.err.print("Error");
  if (e.getHttpErrorCodeOverride() > 0) {
    System.err.print(e.getHttpErrorCodeOverride());
  }
  System.err.print(": ");
  System.err.println(e.getMessage());

  ServiceErrors errors = new ServiceErrors(e);
  for (ServiceError error: errors.getAllErrors()) {
    String field = error.getField();
    System.err.print("  ");
    if (field != null) {
      System.err.print("in field '");
      System.err.print(field);
      System.err.print("' ");
    }
    System.err.println(error.getReason());
  }
}
 
开发者ID:google,项目名称:gdata-java-client,代码行数:27,代码来源:Example.java

示例2: main

import com.google.gdata.util.ServiceException; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
  Command command = CommandFactory.createCommand(args);
  try {
    command.execute();
  } catch (ServiceException e) {
    /* Display the error message sent by the server, if it 
     * is available. A real application would need to parse
     * the body (as HTML or XML, depending on e.getContentType())
     * and display it nicely.
     */
    StringBuffer message = new StringBuffer("Response code:");
    ServiceErrors errors = new ServiceErrors(e);

    if (e.getHttpErrorCodeOverride() > 0) {
      message.append(" ");
      message.append(e.getHttpErrorCodeOverride());
    }
    message.append(" ");
    message.append(e.getMessage());
    System.err.println(message);

    List<? extends ServiceError> allErrors = errors.getAllErrors();
    for (ServiceError error: allErrors) {
      String field = error.getField();
      StringBuffer buffer = new StringBuffer();
      buffer.append("  ");
      if (field != null) {
        buffer.append("in field '");
        buffer.append(field);
        buffer.append("'");
        buffer.append(": ");
      }
      buffer.append(error.getReason());
      System.err.println(buffer);
    }
    System.exit(10);
  }
}
 
开发者ID:google,项目名称:gdata-java-client,代码行数:39,代码来源:CustomerTool.java

示例3: BatchStatus

import com.google.gdata.util.ServiceException; //导入方法依赖的package包/类
/**
 * Creates a BatchStatus and initializes it
 * based on an exception.
 *
 * @param e
 */
public BatchStatus(ServiceException e) {
  code = e.getHttpErrorCodeOverride();
  if (code == -1) {
    code = HttpURLConnection.HTTP_INTERNAL_ERROR;
  }
  reason = e.getMessage();
  contentType = e.getResponseContentType();
  content = e.getResponseBody();
}
 
开发者ID:google,项目名称:gdata-java-client,代码行数:16,代码来源:BatchStatus.java

示例4: BatchStatus

import com.google.gdata.util.ServiceException; //导入方法依赖的package包/类
/**
 * Creates a BatchStatus and initializes it
 * based on an exception.
 *
 * @param e exception to initialize the status from
 */
public BatchStatus(ServiceException e) {
  this();
  int code = e.getHttpErrorCodeOverride();
  if (code == -1) {
    code = HttpURLConnection.HTTP_INTERNAL_ERROR;
  }
  setCode(code);
  setReason(e.getMessage());
  setContentType(e.getResponseContentType());
  setContent(e.getResponseBody());
}
 
开发者ID:google,项目名称:gdata-java-client,代码行数:18,代码来源:BatchStatus.java


注:本文中的com.google.gdata.util.ServiceException.getHttpErrorCodeOverride方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。