You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by jo...@apache.org on 2011/03/01 03:17:27 UTC
svn commit: r1075621 - in /shindig/trunk/java:
gadgets/src/main/java/org/apache/shindig/gadgets/servlet/RpcSwfServlet.java
server/src/main/webapp/WEB-INF/web.xml
Author: johnh
Date: Tue Mar 1 02:17:26 2011
New Revision: 1075621
URL: http://svn.apache.org/viewvc?rev=1075621&view=rev
Log:
Simple servlet for emitting xpc.swf, relay for Flash transport.
Default install at /xpc.swf, but this should be modified for real production use cases.
Further CLs will add some testing as well as origin/referer validation hooks (for sanity).
Added:
shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/RpcSwfServlet.java
Modified:
shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml
Added: shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/RpcSwfServlet.java
URL: http://svn.apache.org/viewvc/shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/RpcSwfServlet.java?rev=1075621&view=auto
==============================================================================
--- shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/RpcSwfServlet.java (added)
+++ shindig/trunk/java/gadgets/src/main/java/org/apache/shindig/gadgets/servlet/RpcSwfServlet.java Tue Mar 1 02:17:26 2011
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.shindig.gadgets.servlet;
+
+import com.google.inject.Inject;
+import com.google.inject.name.Named;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.shindig.common.servlet.HttpUtil;
+import org.apache.shindig.common.util.HashUtil;
+import org.apache.shindig.common.util.ResourceLoader;
+import org.apache.shindig.gadgets.uri.UriCommon;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Trivial servlet that does precisely one thing: serves the SWF needed for gadgets.rpc's
+ * Flash-based transport.
+ */
+public class RpcSwfServlet extends HttpServlet {
+ private static final String SWF_RESOURCE_NAME = "files/xpc.swf";
+ private static final int ONE_YEAR_IN_SEC = 365 * 24 * 60 * 60;
+ private static final int DEFAULT_SWF_TTL = 24 * 60 * 60;
+
+ private final byte[] swfBytes;
+ private final String hash;
+ private int defaultSwfTtl = DEFAULT_SWF_TTL;
+
+ public RpcSwfServlet() {
+ this(SWF_RESOURCE_NAME);
+ }
+
+ public RpcSwfServlet(String swfResource) {
+ byte[] bytes = null;
+ try {
+ InputStream is = ResourceLoader.openResource(swfResource);
+ if (is == null) {
+ throw new RuntimeException("Failed to locate Flash SWF");
+ }
+ bytes = IOUtils.toByteArray(is);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ this.swfBytes = bytes;
+ this.hash = HashUtil.checksum(swfBytes);
+ }
+
+ @Inject(optional = true)
+ public void setDefaultRpcSwfTtl(@Named("shindig.rpc.swf.defaultTtl") Integer defaultTtl) {
+ defaultSwfTtl = defaultTtl;
+ }
+
+ public String getSwfHash() {
+ return hash;
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ resp.setStatus(HttpServletResponse.SC_OK);
+
+ // Similar versioning method to other APIs, implemented more compactly.
+ String v = req.getParameter(UriCommon.Param.VERSION.getKey());
+ if (v != null && v.equals(hash)) {
+ HttpUtil.setCachingHeaders(resp, ONE_YEAR_IN_SEC);
+ } else {
+ HttpUtil.setCachingHeaders(resp, defaultSwfTtl);
+ }
+
+ resp.setHeader("Content-Type", "application/x-shockwave-flash");
+
+ resp.getOutputStream().write(swfBytes);
+ }
+}
Modified: shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml?rev=1075621&r1=1075620&r2=1075621&view=diff
==============================================================================
--- shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml (original)
+++ shindig/trunk/java/server/src/main/webapp/WEB-INF/web.xml Tue Mar 1 02:17:26 2011
@@ -227,6 +227,13 @@
</servlet-class>
</servlet>
+ <servlet>
+ <servlet-name>rpcSwf</servlet-name>
+ <servlet-class>
+ org.apache.shindig.gadgets.servlet.RpcSwfServlet
+ </servlet-class>
+ </servlet>
+
<servlet-mapping>
<servlet-name>js</servlet-name>
<url-pattern>/gadgets/js/*</url-pattern>
@@ -285,4 +292,9 @@
<servlet-name>sampleOAuth</servlet-name>
<url-pattern>/oauth/*</url-pattern>
</servlet-mapping>
+
+ <servlet-mapping>
+ <servlet-name>rpcSwf</servlet-name>
+ <url-pattern>xpc.swf</url-pattern>
+ </servlet-mapping>
</web-app>