【问题标题】:apiKeyRequired in google cloud endpoint not getting resolved谷歌云端点中的 apiKeyRequired 未得到解决
【发布时间】:2017-02-14 18:55:23
【问题描述】:

我正在创建谷歌云端点 api,我正在尝试使用

apiKeyRequired = AnnotationBoolean.TRUE

https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/appengine/endpoints-frameworks-v2/backend/src/main/java/com/example/echo/Echo.java为例

 @ApiMethod(name = "echo_api_key", path = "echo_api_key", apiKeyRequired =AnnotationBoolean.TRUE) 
  public Message echoApiKey(Message message, @Named("n") @Nullable Integer n) {
return doEcho(message, n);
} 

我的代码是这样的。 IDE 无法解析此属性。

  @ApiMethod(
        name = "get",
        path = "name/{id}",
        httpMethod = ApiMethod.HttpMethod.GET,
        apikeyRequired = AnnotationBoolean.TRUE)

我反编译了ApiMethod注解,它没有apikeyRequired属性

  package com.google.api.server.spi.config;

 import com.google.api.server.spi.config.ApiMethodCacheControl;
 import com.google.api.server.spi.config.AuthLevel;
 import com.google.api.server.spi.config.Authenticator;
 import com.google.api.server.spi.config.PeerAuthenticator;
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;

 @Retention(RetentionPolicy.RUNTIME)
 @Target({ElementType.METHOD})
public @interface ApiMethod {
String name() default "";

String path() default "";

String httpMethod() default "";

/** @deprecated */
@Deprecated
ApiMethodCacheControl cacheControl() default @ApiMethodCacheControl;

AuthLevel authLevel() default AuthLevel.UNSPECIFIED;

String[] scopes() default {"_UNSPECIFIED_LIST_STRING_VALUE"};

String[] audiences() default {"_UNSPECIFIED_LIST_STRING_VALUE"};

String[] clientIds() default {"_UNSPECIFIED_LIST_STRING_VALUE"};

Class<? extends Authenticator>[] authenticators() default {Authenticator.class};

Class<? extends PeerAuthenticator>[] peerAuthenticators() default {PeerAuthenticator.class};

public static class HttpMethod {
    public static final String GET = "GET";
    public static final String POST = "POST";
    public static final String PUT = "PUT";
    public static final String DELETE = "DELETE";

    public HttpMethod() {
    }
   }
     }

【问题讨论】:

  • Cloud Endpoints Framework 2.0 中添加了 apiKeyRequired 属性。检查您的依赖项:com.google.endpoints:endpoints-framework:2.0.0(旧版本类似于 com.google.appengine:appengine-endpoints:1.x.x)

标签: java google-app-engine annotations google-cloud-endpoints


【解决方案1】:

我之前也遇到过同样的问题。您需要确保删除所有旧的 app-engine-endpoints 依赖项并使用新的端点框架

compile group: 'com.google.endpoints', name: 'endpoints-framework', version: '2.0.+'

【讨论】:

    【解决方案2】:

    您需要将 k 大写。也就是说,apiKeyRequired,而不是apikeyRequired

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-06
      • 1970-01-01
      • 2015-10-27
      • 2014-07-05
      • 1970-01-01
      相关资源
      最近更新 更多