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


Java OAuthProblemException.getProblem方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:groovenauts,项目名称:jmeter_oauth_plugin,代码行数:29,代码来源:TwitterConsumer.java

示例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);
    }
}
 
开发者ID:groovenauts,项目名称:jmeter_oauth_plugin,代码行数:55,代码来源:CookieConsumer.java


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