本文整理汇总了Java中net.oauth.OAuthProblemException.getProblem方法的典型用法代码示例。如果您正苦于以下问题:Java OAuthProblemException.getProblem方法的具体用法?Java OAuthProblemException.getProblem怎么用?Java OAuthProblemException.getProblem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.oauth.OAuthProblemException
的用法示例。
在下文中一共展示了OAuthProblemException.getProblem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import net.oauth.OAuthProblemException; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
OAuthConsumer consumer = null;
try {
consumer = CookieConsumer.getConsumer("twitter", getServletContext());
OAuthAccessor accessor = CookieConsumer.getAccessor(request, response, consumer);
OAuthResponseMessage result = CookieConsumer.CLIENT.access(accessor.newRequestMessage(OAuthMessage.GET,
"http://twitter.com/statuses/friends_timeline.atom", null), ParameterStyle.AUTHORIZATION_HEADER);
int status = result.getHttpResponse().getStatusCode();
if (status != HttpResponseMessage.STATUS_OK) {
OAuthProblemException problem = result.toOAuthProblemException();
if (problem.getProblem() != null) {
throw problem;
}
Map<String, Object> dump = problem.getParameters();
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.println(dump.get(HttpMessage.REQUEST));
out.println("----------------------");
out.println(dump.get(HttpMessage.RESPONSE));
} else {
// Simply pass the data through to the browser:
CookieConsumer.copyResponse(result, response);
}
} catch (Exception e) {
CookieConsumer.handleException(e, request, response, consumer);
}
}
示例2: handleException
import net.oauth.OAuthProblemException; //导入方法依赖的package包/类
/**
* Handle an exception that occurred while processing an HTTP request.
* Depending on the exception, either send a response, redirect the client
* or propagate an exception.
*/
public static void handleException(Exception e, HttpServletRequest request,
HttpServletResponse response, OAuthConsumer consumer)
throws IOException, ServletException {
if (e instanceof RedirectException) {
RedirectException redirect = (RedirectException) e;
String targetURL = redirect.getTargetURL();
if (targetURL != null) {
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
response.setHeader("Location", targetURL);
}
} else if (e instanceof OAuthProblemException) {
OAuthProblemException p = (OAuthProblemException) e;
String problem = p.getProblem();
if (consumer != null && RECOVERABLE_PROBLEMS.contains(problem)) {
try {
CookieMap cookies = new CookieMap(request, response);
OAuthAccessor accessor = newAccessor(consumer, cookies);
getAccessToken(request, cookies, accessor);
// getAccessToken(request, consumer,
// new CookieMap(request, response));
} catch (Exception e2) {
handleException(e2, request, response, null);
}
} else {
try {
StringWriter s = new StringWriter();
PrintWriter pw = new PrintWriter(s);
e.printStackTrace(pw);
pw.flush();
p.setParameter("stack trace", s.toString());
} catch (Exception rats) {
}
response.setStatus(p.getHttpStatusCode());
response.resetBuffer();
request.setAttribute("OAuthProblemException", p);
request.getRequestDispatcher //
("/OAuthProblemException.jsp").forward(request,
response);
}
} else if (e instanceof IOException) {
throw (IOException) e;
} else if (e instanceof ServletException) {
throw (ServletException) e;
} else if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new ServletException(e);
}
}