AppEngine(或其嵌入式服务器)如​​何处理不同的URL

时间:2012-05-21 09:36:26

标签: google-app-engine jetty http-status-code-404

我创建了一个简单的appengine项目,用于访问http://commerce.qa.mycomp.com中托管的restful webservice(mycomp应该替换为我的实际公司名称)。

我正在使用Jersey客户端发出客户端请求。我对上面的网址发出POST请求。 当我在本地运行应用程序时,它总是返回404 Not Found响应。为了进行实验,我向http://www.bbc.co.uk/news/发出了POST请求,这样可以正常工作,并返回200作为状态。

我只是将我的应用程序与appengine分离并在单独配置的tomcat服务器中运行它,并且它工作正常并返回200状态代码。我认为appengine使用Jetty作为服务器。 Jetty是否有任何处理url的错误,例如commerce.qa.mycomp.com。为什么我要问这是从www.any.com开始的网址似乎工作正常。

当在本地appengine中运行时,下面显示的两个代码段无效(即使我将其托管到appspot也没有运行)。

Client client = Client.create();
WebResource service = client.resource("http://commerce.qa.mycomp.com/rest");
ClientResponse response = service
    .header("Content-Type", "text/xml; Charset=utf-8")
.header("Authorization", "Basic dwt3hkl553lsfsfssf3")
.post(ClientResponse.class, "does not need to be actual xml");

URL url = new URL("http://commerce.qa.mycomp.com/rest");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "text/xml; Charset=utf-8");
conn.addRequestProperty("Authorization", "Basic dwt3hkl553lsfsfssf3");
OutputStream os = conn.getOutputStream();
os.write("no need to be actual xml".getBytes());
os.flush();
System.out.println("Response Code: " + conn.getResponseCode());

但是当使用tomcat运行时,它才能正常工作。

我的装置是: Google App Engine Java SDK 1.6.1 适用于Eclipse的Google插件3.7 jersey-client-1.12,jersey-core-1.12,jersey-json-1.8

请分享想法。

0 个答案:

没有答案