【问题标题】:'X-Appengine-Inbound-Appid' header is not set when using Spring RestTemplate使用 Spring RestTemplate 时未设置“X-Appengine-Inbound-Appid”标头
【发布时间】:2018-03-26 04:07:32
【问题描述】:

我在 Google App Engine 上运行了两项服务(MS1 和 MS2)。 MS1 部署在标准环境中,MS2 部署在灵活环境中。我正在调用从标准环境到灵活环境的 API。我想确保 MS2 只接受来自 MS1 的请求。所以,我决定使用 App Engine 的this 功能。我在 MS1 中将 X-Appengine-Inbound-Appid 标头和 setInstanceFollowRedirects 设置为 false,但看起来 App Engine 正在删除此标头。我在 MS2 中找不到这个标头。

HttpHeaders headers = new HttpHeaders();
headers.add("X-Appengine-Inbound-Appid", ApiProxy.getCurrentEnvironment().getAppId());
HttpEntity<MergePdfsResource> entity = new HttpEntity<MergePdfsResource>(mergePdfsResource, headers);

restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory() {
        protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
        super.prepareConnection(connection, httpMethod);
        connection.setInstanceFollowRedirects(false);
    }
});

ResponseEntity<SomeClass> response = restTemplate.postForEntity(apiUrl, entity, SomeClass.class);

【问题讨论】:

标签: spring google-app-engine spring-restcontroller spring-rest google-flexible


【解决方案1】:

以下是我从 Google 支持获得的答案:

X-Appengine-Inbound-Appid 标头仅在我们使用 URLFetch 服务时设置。在 java8 运行时环境中,默认为native,它使用标准的 Java 网络类。所以,我必须在appengine-web.xml 中将URL 流处理程序设置为urlfetch,如下所示:

<url-stream-handler>urlfetch</url-stream-handler>

【讨论】:

    猜你喜欢
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    相关资源
    最近更新 更多