App Engine용 Cloud Endpoints Frameworks 버전 2.0으로 이전

이 페이지에서는 기존의 Cloud Endpoints 버전 1.0 애플리케이션을 Java의 App Engine용 Endpoints Frameworks로 이전하는 방법을 설명합니다.

이점

새로운 프레임워크에는 다음과 같은 여러 가지 장점이 있습니다.

  • 요청 지연 시간 감소
  • App Engine 기능(예: 커스텀 도메인)과의 통합 향상
  • Guice 구성 공식 지원
  • 새로운 API 관리 기능(선택사항)

Endpoints 프레임워크 버전 2.0은 API에 대한 인터페이스에 영향을 주지 않습니다. 기존 클라이언트는 이전 후에도 클라이언트 측 코드 변경 없이 계속 작동합니다.

현재 제외된 기능과 도구

다음 기능은 현재 사용할 수 없습니다. 이 중에서 필요한 기능이 있으면 기능 요청을 제출하세요.

  • 이전 iOS 클라이언트에 필요한 JSON-RPC 프로토콜. Endpoints 프레임워크 버전 2.0 API의 iOS 클라이언트를 만들려면 REST API용 Google API Objective-C 클라이언트 라이브러리를 사용하는 것이 좋습니다.
  • 자동 ETag
  • 자동 종류 필드
  • IDE 통합
  • fields 부분 응답
  • 자동 PATCH API 메서드 생성

또한 Android 스튜디오는 Endpoints 버전 1.0은 지원하지만 버전 2.0은 현재 지원하지 않습니다.

Endpoints 프레임워크 버전 2.0으로 마이그레이션

Endpoints 프레임워크 버전 2.0은 com.google.endpoints 그룹의 Maven 아티팩트로 이동되었습니다. 기본 필수 JAR은 endpoints-framework 아티팩트에 있습니다. Guice 구성을 사용하려면 endpoints-framework-guice 아티팩트를 추가하세요.

다음 안내에서는 Endpoints 프레임워크 버전 1.0에서 Endpoints 프레임워크 버전 2.0으로 마이그레이션하는 방법의 예시를 보여줍니다. 검색 문서

  1. Google Cloud CLI를 다운로드하고 초기화합니다.
  2. 다음 명령어를 실행합니다.
    1. gcloud CLI가 다음에서 데이터와 서비스에 액세스할 수 있는 권한이 있는지 확인합니다. Google Cloud
      gcloud auth login
    2. 애플리케이션 기본 사용자 인증 정보를 사용합니다.
      gcloud auth application-default login
    3. Google Cloud SDK app-engine-java 구성요소를 설치합니다.
      gcloud components install app-engine-java
    4. Google Cloud SDK와 모든 구성요소를 최신 버전으로 업데이트합니다.
      gcloud components update

Maven 또는 Gradle을 사용하여 이전

Maven

  1. 기존 종속 항목인 appengine-endpoints 아티팩트를 삭제합니다.
    <dependency>
          <groupId>com.google.appengine</groupId>
          <artifactId>appengine-endpoints</artifactId>
          <version>1.9.53</version>
    </dependency>
  2. 새로운 Endpoints 프레임워크 종속 항목을 추가합니다.
    <dependency>
        <groupId>com.google.endpoints</groupId>
        <artifactId>endpoints-framework</artifactId>
        <version>2.2.1</version>
    </dependency>
  3. 새로운 Endpoints 프레임워크 플러그인을 추가하고 생성된 탐색 문서의 호스트 이름을 정의합니다.
    <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>endpoints-framework-maven-plugin</artifactId>
        <version>1.0.2</version>
        <configuration>
            <!-- plugin configuration -->
            <hostname>YOUR-PROJECT-ID.appspot.com</hostname>
        </configuration>
    </plugin>
  4. 새로운 App Engine Maven 플러그인을 추가합니다.
    <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>appengine-maven-plugin</artifactId>
        <version>1.3.2</version>
        <configuration>
            <!-- deploy configuration -->
        </configuration>
    </plugin>
  5. 프로젝트 web.xml 파일에서 API 진입점을 업데이트합니다.
    • SystemServiceServlet 의 모든 항목을 EndpointsServlet으로 이름을 바꿉니다.
    • 경로 /_ah/spi/ 의 모든 항목을 새 필수 경로 /_ah/api/
      로 바꿉니다.

    다음은 이전 전후의 web.xml 콘텐츠를 보여줍니다.

    마이그레이션 전

    Endpoints 프레임워크 버전 1.0 web.xml:
    <servlet>
        <servlet-name>SystemServiceServlet</servlet-name>
        <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
        <init-param>
            <param-name>services</param-name>
            <param-value>com.example.helloendpoints.Greetings</param-value>
        </init-param>
        <init-param>
            <param-name>restricted</param-name>
            <param-value>false</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>SystemServiceServlet</servlet-name>
        <url-pattern>/_ah/spi/*</url-pattern>
    </servlet-mapping>

    이전 후

    Endpoints 프레임워크 버전 2.0 web.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.helloendpoints.Greetings</param-value>
        </init-param>
        <init-param>
            <param-name>restricted</param-name>
            <param-value>false</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>EndpointsServlet</servlet-name>
        <url-pattern>/_ah/api/*</url-pattern>
    </servlet-mapping>

  6. 종속 항목을 수정한 후 프로젝트를 삭제하세요.
    mvn clean
  7. 탐색 문서를 생성할 수 있습니다.
    mvn endpoints-framework:discoveryDocs
    Maven Endpoints Frameworks 플러그인 목표에 대해 자세히 알아보세요.
  8. 프로젝트를 배포할 수 있습니다.
    mvn appengine:deploy

    Maven App Engine 플러그인 목표에 대해 자세히 알아보세요.

Gradle

  1. 기존 종속 항목인 appengine-endpoints 아티팩트를 삭제합니다.
    compile group: 'com.google.appengine', name: 'appengine-endpoints', version: '+'
  2. 새로운 Endpoints 프레임워크 종속 항목을 추가합니다.
    compile group: 'com.google.endpoints', name: 'endpoints-framework', version: '2.0.8'
  3. 새로운 App Engine 및 Endpoints 프레임워크 플러그인을 추가합니다.
    buildscript {    // Configuration for building
      repositories {
        mavenCentral()
        jcenter()    // Bintray's repository - a fast Maven Central mirror & more
      }
      dependencies {
        // App Engine Gradle plugin
        classpath 'com.google.cloud.tools:appengine-gradle-plugin:1.3.3'
    
        // Endpoints Frameworks Gradle plugin
        classpath 'com.google.cloud.tools:endpoints-framework-gradle-plugin:1.0.2'
      }
    }
  4. 새로운 App Engine 및 Endpoints 프레임워크 플러그인을 적용합니다.
    apply plugin: 'com.google.cloud.tools.appengine'
    apply plugin: 'com.google.cloud.tools.endpoints-framework-server'
  5. 생성된 검색 문서의 호스트 이름 엔드포인트를 정의합니다.
    endpointsServer {
      // Endpoints Framework Plugin server-side configuration
      hostname = "YOUR-PROJECT-ID.appspot.com"
    }
  6. 프로젝트 web.xml 파일에서 API 진입점을 업데이트합니다.
    • SystemServiceServlet 의 모든 항목을 EndpointsServlet으로 이름을 바꿉니다.
    • 경로 /_ah/spi/ 의 모든 항목을 새 필수 경로 /_ah/api/
      로 바꿉니다.

    다음은 이전 전후의 web.xml 콘텐츠를 보여줍니다.

    마이그레이션 전

    Endpoints 프레임워크 버전 1.0 web.xml:
    <servlet>
        <servlet-name>SystemServiceServlet</servlet-name>
        <servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
        <init-param>
            <param-name>services</param-name>
            <param-value>com.example.helloendpoints.Greetings</param-value>
        </init-param>
        <init-param>
            <param-name>restricted</param-name>
            <param-value>false</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>SystemServiceServlet</servlet-name>
        <url-pattern>/_ah/spi/*</url-pattern>
    </servlet-mapping>

    이전 후

    Endpoints 프레임워크 버전 2.0 web.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.helloendpoints.Greetings</param-value>
        </init-param>
        <init-param>
            <param-name>restricted</param-name>
            <param-value>false</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>EndpointsServlet</servlet-name>
        <url-pattern>/_ah/api/*</url-pattern>
    </servlet-mapping>

  7. 종속 항목을 수정한 후 다음 명령어를 사용하여 프로젝트를 삭제하세요.
    gradle clean
  8. 다음 명령어를 사용하여 탐색 문서를 생성할 수 있습니다.
    gradle endpointsDiscoveryDocs
    Gradle Endpoints Frameworks 플러그인 태스크에 대해 자세히 알아보세요.
  9. 다음 명령어를 사용하여 프로젝트를 배포할 수 있습니다.
    gradle appengineDeploy

    Gradle App Engine 플러그인 작업에 대해 자세히 알아보세요.

Guice를 사용하여 자바용 Endpoints Frameworks 구성

Guice를 사용하려면 다음 안내를 따르세요.

  1. 새로운 Endpoints Frameworks Guice 종속 항목을 추가합니다.

    Maven

    <dependency>
        <groupId>com.google.endpoints</groupId>
        <artifactId>endpoints-framework-guice</artifactId>
        <version>2.2.1</version>
    </dependency>

    Gradle

    compile 'com.google.endpoints:endpoints-framework-guice:2.0.9'
  2. EndpointsModule을 확장하는 새 모듈을 선언하고 다음과 같이 구성합니다.
    public class EchoEndpointModule extends EndpointsModule {
      @Override
      public void configureServlets() {
        super