2

I have two services running on the Google App Engine (MS1 & MS2). MS1 is deployed in the Standard Environment and MS2 is deployed in the Flexible Environment. I am invoking an API from Standard Environment to the Flexible Environment. I want to make sure that MS2 only accepts requests originating from MS1. So, I decided to use this feature from App Engine. I am setting the X-Appengine-Inbound-Appid header and setInstanceFollowRedirects to false in MS1, but looks like App Engine is removing this header. I am not able to find this header in 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);
Mithun
  • 7,747
  • 6
  • 52
  • 68

1 Answers1

6

Following is the answer I got from the Google Support:

The X-Appengine-Inbound-Appid header is set only if we are using the URLFetch service. In the java8 runtime environment, the default is native which uses the standard Java network classes. So, I had to set the URL stream handler to urlfetch in appengine-web.xml as below:

<url-stream-handler>urlfetch</url-stream-handler>
Mithun
  • 7,747
  • 6
  • 52
  • 68