我正在尝试使用 JSP Servlets 开发一个简单的 BigQuery 应用程序。我正在遵循https://developers.google.com/bigquery/docs/authorization上给出的示例
在早期阶段,doGet 方法没有被调用,所以我重写了 Service 方法。代码看起来像这样
public class BigQueryWebServerAuthDemo extends AbstractAuthorizationCodeServlet {
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
System.out.println(" Start service ");
doGet(req, resp);
}
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
System.out.println(" Start doGet ");
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException {
System.out.println(" Start doPost ");
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
System.out.println(" Begin loadbigquery() ");
Bigquery bigquery = CredentialUtils.loadbigquery();
System.out.println(" end loadbigquery() ");
Bigquery.Projects.List projectListRequest = bigquery.projects().list();
ProjectList projectList = projectListRequest.execute();
if (projectList.getProjects() != null) {
java.util.List<Projects> projects = projectList.getProjects();
writer.println("<h3>BigQuery project list:</h3>");
for (ProjectList.Projects project : projects) {
writer.printf("%s<br />", project.getProjectReference().getProjectId());
}
}
System.out.println(" End doPost ");
}
@Override
protected AuthorizationCodeFlow initializeFlow() throws ServletException, IOException {
System.out.println(" inside BigQueryWebServerAuthDemo --- initializeFlow() ");
return CredentialUtils.newFlow();
}
@Override
protected String getRedirectUri(HttpServletRequest request) throws ServletException, IOException {
System.out.println(" inside BigQueryWebServerAuthDemo --- getRedirectUri() ");
return CredentialUtils.getRedirectUri(request);
}
@Override
protected String getUserId(HttpServletRequest request) throws ServletException, IOException {
System.out.println(" inside BigQueryWebServerAuthDemo --- getUserId ");
return request.getParameter("userId");
}
}
我有一个 JSP 页面,从中获取参数“userId”。现在我在 execute() 方法 [projectListRequest.execute()] 上得到一个 NoSuchMethodError,尽管 Eclipse 编译器没有显示任何错误。
下面是我的 web.xml 配置信息
<servlet>
<servlet-name>oauth2callback</servlet-name>
<servlet-class>main.BigQueryWebServerAuthCallBack</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>oauth2callback</servlet-name>
<url-pattern>/oauth2callback</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ServletBigQuery</servlet-name>
<servlet-class>main.BigQueryWebServerAuthDemo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletBigQuery</servlet-name>
<url-pattern>/ServletBigQuery</url-pattern>
</servlet-mapping>
如上面提到的教程中给出的,我还有 2 个类 CredentialUtils 和 BigQueryWebServerAuthCallBack。
我实际上是 Java 新手。我想摆脱 NoSuchMethodError 错误。任何帮助将不胜感激。