AppEngine X-AppEngine-Inbound-AppId在servlet中收到,但不在Endpoint中收到

时间:2016-05-02 12:29:08

标签: java google-app-engine servlets

我正在使用带有内部微服务(模块)的Google Appengine Java端点。

当我执行从端点到模块Servlet的调用时,我按照文档(request.getHeader(“X-Appengine-Inbound-Appid”)接收X-AppEngine-Inbound-AppId并且一切都很好。 当我尝试调用模块端点时,我不再收到它了!

我使用相同的代码来执行所有HTTP请求。

  public GenericResponse makePOSTRequest(String urlString, Object requestObject, String jSessionId, boolean parseSessionId) {
    GenericResponse genericResponse;

    String rawPayload = mJsonParser.toJson(requestObject);
    URL url = new URL(urlString);

    HttpURLConnection connection = (HttpURLConnection) url.openConnection();

    connection.setInstanceFollowRedirects(false);
    connection.setConnectTimeout(60000);
    connection.setReadTimeout(60000);

    connection.setDoOutput(true);
    connection.setRequestMethod("POST");

    connection.setRequestProperty("Content-Type", "application/json");
    connection.setRequestProperty("Content-Length", String.valueOf(rawPayload.getBytes("UTF-8").length));

    if (jSessionId != null) {
        connection.setRequestProperty("Cookie", "JSESSIONID=" + jSessionId);
    }

    OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
    writer.write(rawPayload);
    writer.close();

    InputStreamReader isr = new InputStreamReader(connection.getInputStream(), "UTF-8");
    BufferedReader br = new BufferedReader(isr);
    StringBuilder sb = new StringBuilder();
    String line;

    while ((line = br.readLine()) != null) {
        sb.append(line);
    }
    br.close();

    if (!parseSessionId) {
        genericResponse = new GenericResponse(connection.getResponseCode(), sb.toString());
    } else {
        String responseSessionId = parseSessionId(connection);
        genericResponse = new GenericResponse(connection.getResponseCode(), sb.toString(), responseSessionId);
    }


    return genericResponse;

0 个答案:

没有答案