我正在使用Google oAuth作为我的网络应用程序。登录时返回状态和代码,并从同一页面重定向到index.jsp。
我的index.jsp
<body style="background-color: #FFA;">
<div class="container" style="width: 100%;">
<div class="row">
<div class="col-md-6">
<h3>
IntegrationEZ<br />
<span style="color:#808080;"><i>We make "integrations" easy</i></span>
</h3>
</div>
<div align="right" class="col-md-6"><br>
<%
/*
* The GoogleAuthHelper handles all the heavy lifting, and contains all "secrets"
* required for constructing a google login url.
*/
final GoogleAuthHelper helper = new GoogleAuthHelper();
if (request.getParameter("code") == null
|| request.getParameter("state") == null) {
/*
* initial visit to the page
*/
out.println(" <a class='btn btn-lg btn-social btn-google' style='width:36%;padding: 12px 0px;float:right;' href='" + helper.buildLoginUrl()
+ "'><span class='fa fa-google'></span> Login with Google</a>");
/*
* set the secure state token in session to be able to track what we sent to google
*/
session.setAttribute("state", helper.getStateToken());
System.out.println("code-->"+request.getParameter("code"));
} else if (request.getParameter("code") != null && request.getParameter("state") != null
&& request.getParameter("state").equals(session.getAttribute("state"))) {
// System.out.println("state-->"+request.getParameter("state")+" code-->"+request.getParameter("code"));
session.removeAttribute("state");
// out.println("<pre>");
/*
* Executes after google redirects to the callback url.
* Please note that the state request parameter is for convenience to differentiate
* between authentication methods (ex. facebook oauth, google oauth, twitter, in-house).
*
* GoogleAuthHelper()#getUserInfoJson(String) method returns a String containing
* the json representation of the authenticated user's information.
* At this point you should parse and persist the info.
*/
String userInfo=helper.getUserInfoJson(request.getParameter("code"));
System.out.println("name-->"+userInfo);
ServletContext context= getServletContext();
RequestDispatcher rd= context.getRequestDispatcher("/DashboardAuditDetails");
context.setAttribute("msg",userInfo);
rd.forward(request, response);
return;
}
%>
</div>
</div>
在google开发者控制台中,我将重定向网址设置为相同的索引页面。当它返回时,它转到else语句,我已经获取了用户信息,我需要将此用户信息传递给另一个servlet。我的流程将是index.jsp - &gt; google Auth - &gt; index.jsp - &gt; dashboard.jsp(带有用户信息)但使用上面的转发技巧,它正在抛出
Apr 07, 2017 12:36:57 PM org.apache.catalina.core.ApplicationDispatcher
invoke
SEVERE: Servlet.service() for servlet DashboardAuditDetails threw exception
java.lang.NoSuchMethodError:
com.google.api.client.http.HttpResponseException.<init>
(Lcom/google/api/client/http/HttpResponse;Ljava/lang/String;)V
at com.google.api.client.auth.oauth2.TokenResponseException.<init>
(TokenResponseException.java:57)
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:103)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:303)
at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.execute(GoogleAuthorizationCodeTokenRequest.java:147)
at com.tspl.lwp.as.GoogleAuthHelper.getUserInfoJson(GoogleAuthHelper.java:101)
at com.tspl.lwp.servlet.DashboardAuditDetails.doGet(DashboardAuditDetails.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:747)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:485)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:410)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:337)
at org.apache.jsp.jsp.index_jsp._jspService(index_jsp.java:254)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Apr 07, 2017 12:36:57 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/SoaPoc] threw exception [An exception occurred processing JSP page /jsp/index.jsp at line 170
167: ServletContext context= getServletContext();
168: RequestDispatcher rd= context.getRequestDispatcher("/DashboardAuditDetails");
169: context.setAttribute("msg",userInfo);
170: rd.forward(request, response);
171: return;
172:
173:
Stacktrace:] with root cause
java.lang.NoSuchMethodError: com.google.api.client.http.HttpResponseException.<init>(Lcom/google/api/client/http/HttpResponse;Ljava/lang/String;)V
at com.google.api.client.auth.oauth2.TokenResponseException.<init>(TokenResponseException.java:57)
at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:103)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:303)
at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest.execute(GoogleAuthorizationCodeTokenRequest.java:147)
at com.tspl.lwp.as.GoogleAuthHelper.getUserInfoJson(GoogleAuthHelper.java:101)
at com.tspl.lwp.servlet.DashboardAuditDetails.doGet(DashboardAuditDetails.java:45)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:747)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:485)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:410)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:337)
at org.apache.jsp.jsp.index_jsp._jspService(index_jsp.java:254)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
请指教。感谢