Я работаю над веб-приложением, которое работает в Google Appengine и к которому можно получить доступ из приложения Android, которое синхронизирует некоторые данные с сервера. У меня это работало гладко до недавнего времени, когда я воссоздал проект на GCP и настроил IAP, который отлично работает.
Однако я не могу настроить конечную точку, где я продолжаю получать 500 Ошибка сервера . Я выполнил каждый шаг в этой онлайн-инструкции от Google https://cloud.google.com/endpoints/docs/openapi/get-started-app-engine-standard и не могу понять, что я делаю не так !!
Вот содержимое моих файлов:
Эхо. java
package com.example.endpoints;
import ...
@Api(
name = "echo",
version = "v1",
clientIds = { IAP_CREATED_WEBCLIENTID_FROM_CREDENTIALS, Constant.API_EXPLORER_CLIENT_ID},
audiences = {IAP_CREATED_WEBCLIENTID_FROM_CREDENTIALS},
namespace = @ApiNamespace(
ownerDomain = "com.example.endpoints",
ownerName = "com.example.endpoints",
packagePath = "")
)
public class Echo {
@ApiMethod(name = "echoonly", path = "/echo/v1/echoonly")
public Entity echoonly() {
Entity testingResponse = new Entity("TestingResponse", 1000000L);
testingResponse.setProperty("name", "Only");
return testingResponse;
}
@ApiMethod(name = "echoname", path = "/echo/v1/echoname/{name}")
public Entity echoname(
@Named("name") @Nullable String name) {
Entity testingResponse = new Entity("TestingResponse", 1000000L);
testingResponse.setProperty("name", name);
return testingResponse;
}
@ApiMethod(name = "echoage", path = "/echo/v1/echoage/{name}/{age}")
public Entity echoage(
@Named("name") String name,
@Named("age") String age) {
Entity testingResponse = new Entity("TestingResponse", 1000000L);
testingResponse.setProperty("name", name);
testingResponse.setProperty("age", age);
return testingResponse;
}
}
пом. xml (только частичное, которое, я думаю, здесь актуально ...)
<groupId>endpoints</groupId>
<artifactId>endpoints</artifactId>
<properties>
<endpoints.project.id>MYCLOUDRUNSERVICENAME-HASHCODE-uc.a.run.app</endpoints.project.id>
<appengine.maven.plugin.version>2.3.0</appengine.maven.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
<endpoints.framework.version>2.2.1</endpoints.framework.version>
<endpoints.management.version>1.0.4</endpoints.management.version>
</properties>
<dependencies>...</dependencies>
<build>
<plugins>...</plugins>
</build>
appengine-web -. xml
<threadsafe>true</threadsafe>
<sessions-enabled>false</sessions-enabled>
<service>default</service> <!-- THIS IS USED TO UPLOAD TO A SPECIFIC SERVICE. REMOVE THIS FOR DEFAULT -->
<runtime>java8</runtime>
<system-properties>
<property name="java.util.logging.config.file"
value="WEB-INF/logging.properties" />
</system-properties>
<env-variables>
<env-var name="ENDPOINTS_SERVICE_NAME" value="${endpoints.project.id}" />
</env-variables>
веб. xml
<servlet>
<servlet-name>EndpointsServlet</servlet-name>
<servlet-class>com.google.api.server.spi.EndpointsServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.example.endpoints.Echo</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>EndpointsServlet</servlet-name>
<url-pattern>/_ah/api/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>endpoints-api-configuration</filter-name>
<filter-class>com.google.api.control.ServiceManagementConfigFilter</filter-class>
</filter>
<filter>
<filter-name>endpoints-api-controller</filter-name>
<filter-class>com.google.api.control.extensions.appengine.GoogleAppEngineControlFilter</filter-class>
<init-param>
<param-name>endpoints.projectId</param-name>
<param-value>${endpoints.project.id}</param-value>
</init-param>
<init-param>
<param-name>endpoints.serviceName</param-name>
<param-value>${endpoints.project.id}</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>endpoints-api-configuration</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>endpoints-api-controller</filter-name>
<servlet-name>EndpointsServlet</servlet-name>
</filter-mapping>
deployendpoint.yaml
swagger: '2.0'
info:
title: MyEndPointTestApi771 API
description: Sample API on Cloud Endpoints with a Cloud Run, Cloud Function and App Engine with IAP backend
version: 1.0.0
host: MYCLOUDRUNSERVICENAME-HASHCODE-uc.a.run.app
basePath: /_ah/api
schemes:
- https
consumes:
- application/json
produces:
- application/json
x-google-backend:
address: https://MYPROJECTID.uc.r.appspot.com
jwt_audience: IAP_CREATED_WEBCLIENTID_FROM_CREDENTIALS
x-google-allow: all
paths:
/echo/v1/echoonly:
post:
summary: echoonly
operationId: EchoEchoonly
responses:
'200':
description: A successful response
schema:
$ref: "#/definitions/Entity"
security:
- google_id_token: []
/echo/v1/echoname/{name}:
post:
summary: echoname
operationId: EchoEchoname
parameters:
- in: path
name: name
required: true
type: string
responses:
'200':
description: A successful response
schema:
$ref: "#/definitions/Entity"
security:
- google_id_token: []
/echo/v1/echoage/{name}/{age}:
post:
summary: echoage
operationId: EchoEchoage
parameters:
- in: path
name: name
required: true
type: string
- in: path
name: age
required: true
type: string
responses:
'200':
description: A successful response
schema:
$ref: "#/definitions/Entity"
security:
- google_id_token: []
definitions:
_any:
type: "object"
Entity:
type: "object"
properties:
appId:
type: "string"
key:
$ref: "#/definitions/Key"
kind:
type: "string"
namespace:
type: "string"
parent:
$ref: "#/definitions/Key"
properties:
$ref: "#/definitions/Map_String_Object"
propertiesFrom:
$ref: "#/definitions/Entity"
Map_String_Object:
type: "object"
additionalProperties:
$ref: "#/definitions/_any"
JsonMap:
type: "object"
Key:
type: "object"
properties:
appId:
type: "string"
complete:
type: "boolean"
id:
type: "integer"
format: "int64"
kind:
type: "string"
name:
type: "string"
namespace:
type: "string"
parent:
$ref: "#/definitions/Key"
securityDefinitions:
api_key:
type: "apiKey"
name: "key"
in: "query"
google_id_token:
authorizationUrl: 'https://accounts.google.com/o/oauth2/v2/auth?client_id=IAP_CREATED_WEBCLIENTID_FROM_CREDENTIALS&response_type=code&scope=openid%20email&access_type=offline&redirect_uri=urn:ietf:wg:oauth:2.0:oob'
flow: "implicit"
type: "oauth2"
x-google-issuer: "https://accounts.google.com"
x-google-jwks_uri: "https://www.googleapis.com/oauth2/v3/certs"
x-google-audiences: "IAP_CREATED_WEBCLIENTID_FROM_CREDENTIALS"
Update Я не мог понять этого и пошел с Spring @RestController, который работал идеально, не беспокоясь о создании API конечных точек на Google Cloud Platform