【发布时间】:2013-12-23 08:51:05
【问题描述】:
在我的本地机器上运行时,我发现我的代码行为不一致。 AWS 弹性豆茎。该代码用于接收来自 Google Glass 的通知。
代码 sn-p 如下所示:
public class NotifyServlet extends HttpServlet implements WeiboConstants{
private static final Logger LOG = Logger.getLogger(NotifyServlet.class.getSimpleName());
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Respond with OK and status 200 in a timely fashion to prevent redelivery
response.setContentType("text/html");
Writer writer = response.getWriter();
writer.append("OK");
writer.close();
LOG.info("perpare reading");
BufferedReader notificationReader =
new BufferedReader(new InputStreamReader(request.getInputStream()));
String notificationString = "";
LOG.info("begin reading ");
// Count the lines as a very basic way to prevent Denial of Service attacks
int lines = 0;
while (notificationReader.ready()) {
LOG.info("reading");
notificationString += notificationReader.readLine();
lines++;
// No notification would ever be this long. Something is very wrong.
if (lines > 1000) {
throw new IOException("Attempted to parse notification payload that was unexpectedly long.");
}
}
LOG.info("got raw notification " + notificationString);
JsonFactory jsonFactory = new JacksonFactory();
Google的服务器会做POST,单独注册:
Subscription subscription = MirrorClient.insertSubscription(credential, "https://mirrornotifications.appspot.com/forward?url=http://foo.elasticbeanstalk.com/notify", userId,
"timeline");
在本地机器上进行测试时,我运行了 mvn jetty:run 并将上面代码中的 foo 更改为 my ip address:8080。
我可以收到来自 google 的通知:
{ “集合”:“时间线”,“itemId”:“5cbf8f54-822d-4a8e-9a9f-508687bbb9e2”,“操作”:“INSERT”,“userToken”:“105242333117256730066”,“userActions”:[{ “类型”:“启动”}]}
但是当我将war (mvn war:war) 打包并部署到AWS 时,从日志中可以看到它已经成功注册到Google,并且我得到了来自Google 的POST在 /notify 上,但似乎正文是空的,如以下日志所示:
Dec 06, 2013 5:01:55 AM com.google.glassware.NotifyServlet doPost
INFO: perpare reading
Dec 06, 2013 5:01:55 AM com.google.glassware.NotifyServlet doPost
INFO: begin reading
Dec 06, 2013 5:01:55 AM com.google.glassware.NotifyServlet doPost
INFO: got raw notification
Dec 06, 2013 5:01:55 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [notify] in context with path [] threw exception
java.lang.IllegalArgumentException: no JSON input found
如何进一步调试?
更新
我将相同的 war 文件部署到运行 Jetty 而不是 Tomcat 的服务器上,它工作正常,似乎是 Tomcat 特定的问题?
【问题讨论】:
标签: java maven amazon-web-services amazon-elastic-beanstalk google-glass