';X-Appengine-Inbound-Appid';使用Spring RestTemplate时未设置标题

';X-Appengine-Inbound-Appid';使用Spring RestTemplate时未设置标题,spring,google-app-engine,spring-restcontroller,spring-rest,google-flexible,Spring,Google App Engine,Spring Restcontroller,Spring Rest,Google Flexible,我有两个服务在谷歌应用程序引擎上运行(MS1和MS2)。MS1部署在标准环境中,MS2部署在灵活环境中。我正在调用一个从标准环境到灵活环境的API。我想确保MS2只接受来自MS1的请求。所以,我决定使用AppEngine的功能。我正在将MS1中的X-Appengine-Inbound-Appid标题和setInstanceFollowRedirects设置为false,但似乎App Engine正在删除此标题。我无法在MS2中找到此标题 HttpHeaders headers = new Htt

我有两个服务在谷歌应用程序引擎上运行(MS1和MS2)。MS1部署在标准环境中,MS2部署在灵活环境中。我正在调用一个从标准环境到灵活环境的API。我想确保MS2只接受来自MS1的请求。所以,我决定使用AppEngine的功能。我正在将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);
HttpHeaders=newhttpheaders();
headers.add(“X-Appengine-Inbound-Appid”,ApiProxy.getCurrentEnvironment().getAppId());
HttpEntity实体=新的HttpEntity(合并PDFSResource,标头);
setRequestFactory(新的SimpleClientHttpRequestFactory(){
受保护的void prepareConnection(HttpURLConnection连接,字符串httpMethod)引发IOException{
super.prepareConnection(连接,httpMethod);
connection.setInstanceFollowDirections(false);
}
});
ResponseEntity response=restTemplate.postForEntity(apiUrl,entity,SomeClass.class);

以下是我从谷歌支持部门得到的答案:

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

<url-stream-handler>urlfetch</url-stream-handler>
urlfetch
可能感兴趣: