当我将我的API称为:
PUT https://[Project-id].appspot.com/_ah/api/person/v2/[id]/thanks?thanks=true
响应是 400 BadRequest 。
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "java.lang.IllegalArgumentException: Environment variable 'ENDPOINTS_SERVICE_NAME' is not set"
}
],
"code": 400,
"message": "java.lang.IllegalArgumentException: Environment variable 'ENDPOINTS_SERVICE_NAME' is not set"
}
}
响应应 401 Unauthorized ,因为我使用Firebase进行身份验证。
Api定义:
@Api(
name = "person",
version="v2",
authenticators = {EspAuthenticator.class},
issuers = {
@ApiIssuer(
name = "firebase",
issuer = "https://securetoken.google.com/[Project-id] ",
jwksUri = "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com")
},
issuerAudiences = {
@ApiIssuerAudience(name = "firebase", audiences = "[Project-id] ")
}
)
和Api方法:
@ApiMethod(name = "thanks",path = "{personId}/thanks",httpMethod = ApiMethod.HttpMethod.PUT)
public Object thanks(@Named("personId") String personId, @Named("thanks") Boolean thanks, User user) throws IOException, NotFoundException, UnauthorizedException {
if (user == null) {
throw new UnauthorizedException("Invalid credentials");
}
MyBean ty= new MyBean(thanks);
return ty;
}
答案 0 :(得分:3)
看起来您正在使用Endpoints Java Framework。您需要在appengineweb.xml文件中设置ENDPOINTS_SERVICE_NAME: https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/appengine/endpoints-frameworks-v2/backend/src/main/webapp/WEB-INF/appengine-web.xml#L31