如何在Google Cloud Endpoint方法中获取servlet上下文?

时间:2021-12-29 22:55:52

I have a simple Google cloud endpoint. How can I access the context? I'm looking for something similar to getServletContext() from HttpServlet.

我有一个简单的Google云端点。我如何访问上下文?我正在寻找类似于来自HttpServlet的getServletContext()。

@Api
public FooEndpoint {
    @ApiMehod
    public String[] getFiles() {
        // TODO: return files in WEB-INF/data
    }
}

1 个解决方案

#1


1  

The servlet context is an injected type. Just include it as a method argument to an endpoint method and the server will fill it in for you. E.g.

servlet上下文是注入类型。只需将其作为方法参数包含在端点方法中,服务器就会为您填写。例如。

@Api
public FooEndpoint {
  @ApiMethod
  public String[] getFiles(ServletContext context) {
    // TODO: return files in WEB-INF/data
  }
}

You don't need to annotate the argument, and it won't appear in the method stub in the generated client library.

您不需要注释参数,它也不会出现在生成的客户端库中的方法存根中。

#1


1  

The servlet context is an injected type. Just include it as a method argument to an endpoint method and the server will fill it in for you. E.g.

servlet上下文是注入类型。只需将其作为方法参数包含在端点方法中,服务器就会为您填写。例如。

@Api
public FooEndpoint {
  @ApiMethod
  public String[] getFiles(ServletContext context) {
    // TODO: return files in WEB-INF/data
  }
}

You don't need to annotate the argument, and it won't appear in the method stub in the generated client library.

您不需要注释参数,它也不会出现在生成的客户端库中的方法存根中。