Add browser channel support and bump SDK ver to 1.3.6

This commit is contained in:
burke.davey
2010-08-30 20:22:55 +00:00
parent c20a12cee5
commit 9b3454aaef
5 changed files with 83 additions and 4 deletions

View File

@@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="c2dm"/>
<classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="com.google.appengine.eclipse.core.GAE_CONTAINER/App Engine"/>
<classpathentry kind="output" path="war/WEB-INF/classes"/>
</classpath>

View File

@@ -1,4 +1,4 @@
#Mon May 31 20:22:11 BST 2010
#Sun Aug 29 18:14:05 BST 2010
eclipse.preferences.version=1
filesCopiedToWebInfLib=appengine-api-1.0-sdk-1.3.4.jar|appengine-api-labs-1.3.4.jar|appengine-jsr107cache-1.3.4.jar|jsr107cache-1.1.jar|datanucleus-appengine-1.0.7.final.jar|datanucleus-core-1.1.5.jar|datanucleus-jpa-1.1.5.jar|geronimo-jpa_3.0_spec-1.1.1.jar|geronimo-jta_1.1_spec-1.1.1.jar|jdo2-api-2.3-eb.jar
filesCopiedToWebInfLib=appengine-api-1.0-sdk-1.3.6.jar|appengine-api-labs-1.3.6.jar|appengine-jsr107cache-1.3.6.jar|jsr107cache-1.1.jar|datanucleus-appengine-1.0.7.final.jar|datanucleus-core-1.1.5.jar|datanucleus-jpa-1.1.5.jar|geronimo-jpa_3.0_spec-1.1.1.jar|geronimo-jta_1.1_spec-1.1.1.jar|jdo2-api-2.3-eb.jar
ormEnhancementInclusions=src/**|c2dm/**

View File

@@ -0,0 +1,68 @@
/*
* Copyright 2010 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.chrometophone.server;
import java.io.IOException;
import java.util.logging.Logger;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.appengine.api.channel.ChannelMessage;
import com.google.appengine.api.channel.ChannelService;
import com.google.appengine.api.channel.ChannelServiceFactory;
import com.google.appengine.api.users.User;
@SuppressWarnings("serial")
public class BrowserChannelServlet extends HttpServlet {
private static final String OK_STATUS = "OK";
private static final String LOGIN_REQUIRED_STATUS = "LOGIN_REQUIRED";
private static final String ERROR_STATUS = "ERROR";
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
// Basic XSRF protection
if (req.getHeader("X-Same-Domain") == null) {
resp.setStatus(400);
resp.getWriter().println(ERROR_STATUS);
return;
}
User user = RegisterServlet.checkUser(req, resp, false);
if (user == null) {
resp.setStatus(400);
resp.getWriter().println(LOGIN_REQUIRED_STATUS);
} else {
String channelToken = String.valueOf(user.hashCode()); // channel per user
String data = req.getParameter("data");
if (data != null) { // send data
getChannelService().sendMessage(new ChannelMessage(channelToken, data));
resp.getWriter().print(OK_STATUS);
} else { // setup channel
String channelId = getChannelService().createChannel(channelToken);
resp.getWriter().print(channelId);
}
}
}
private ChannelService getChannelService() {
return ChannelServiceFactory.getChannelService();
}
}

View File

@@ -16,7 +16,7 @@
-->
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>chrometophone</application>
<version>4</version>
<version>5</version>
<system-properties>
<property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
</system-properties>

View File

@@ -41,6 +41,12 @@
<servlet-class>com.google.android.chrometophone.server.AuthServlet
</servlet-class>
</servlet>
<servlet>
<servlet-name>BrowserChannelServlet</servlet-name>
<servlet-class>com.google.android.chrometophone.server.BrowserChannelServlet
</servlet-class>
</servlet>
<servlet>
<servlet-name>dataMessagingServlet</servlet-name>
@@ -73,6 +79,11 @@
<servlet-name>AuthServlet</servlet-name>
<url-pattern>/signout</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>BrowserChannelServlet</servlet-name>
<url-pattern>/browserchannel</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dataMessagingServlet</servlet-name>