本文整理汇总了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());
}
}
示例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);
}
}
示例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();
}
示例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());
}