You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2011/06/12 21:23:13 UTC

svn commit: r1134963 - in /incubator/wookie/trunk: WebContent/WEB-INF/ src-tests/org/apache/wookie/tests/flatpack/ src-tests/org/apache/wookie/tests/functional/ src/org/apache/wookie/flatpack/

Author: scottbw
Date: Sun Jun 12 19:23:12 2011
New Revision: 1134963

URL: http://svn.apache.org/viewvc?rev=1134963&view=rev
Log:
Removed the "WAC extensions" functionality in flatpack package - this is because WAC 2.0 uses exactly the same W3C Widget API already supported by Wookie. Also enabled use of resource paths as well as parameters to identify instances (same as widget instances API), and tidied up the javadoc comments.

Modified:
    incubator/wookie/trunk/WebContent/WEB-INF/web.xml
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/FlatpackFactoryTest.java
    incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FlatpackControllerTest.java
    incubator/wookie/trunk/src/org/apache/wookie/flatpack/FlatpackController.java
    incubator/wookie/trunk/src/org/apache/wookie/flatpack/FlatpackFactory.java

Modified: incubator/wookie/trunk/WebContent/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/WebContent/WEB-INF/web.xml?rev=1134963&r1=1134962&r2=1134963&view=diff
==============================================================================
--- incubator/wookie/trunk/WebContent/WEB-INF/web.xml (original)
+++ incubator/wookie/trunk/WebContent/WEB-INF/web.xml Sun Jun 12 19:23:12 2011
@@ -147,7 +147,7 @@
 	</servlet>	
 	<servlet-mapping>
 		<servlet-name>Flatpack</servlet-name>
-		<url-pattern>/flatpack</url-pattern>
+		<url-pattern>/flatpack/*</url-pattern>
 	</servlet-mapping>
 	<servlet-mapping>
  		<servlet-name>default</servlet-name>

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/FlatpackFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/FlatpackFactoryTest.java?rev=1134963&r1=1134962&r2=1134963&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/FlatpackFactoryTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/flatpack/FlatpackFactoryTest.java Sun Jun 12 19:23:12 2011
@@ -33,8 +33,6 @@ import org.junit.Test;
 
 /**
  * Tests the FlatpackFactory functionalty.
- * @author scottbw@apache.org
- *
  */
 public class FlatpackFactoryTest {
 	
@@ -78,7 +76,8 @@ public class FlatpackFactoryTest {
 	public void testNoInstance() throws Exception{
 		FlatpackFactory flatfac = new FlatpackFactory(null);
 		flatfac.setInputWidget(null); // this is the original .wgt
-		File file = flatfac.pack(); // Get the new .wgt file	
+		@SuppressWarnings("unused")
+    File file = flatfac.pack(); // Get the new .wgt file	
 	}
 
 	/**
@@ -215,37 +214,6 @@ public class FlatpackFactoryTest {
 		assertEquals("true", fpWidget.getPrefences().get(0).getValue());
 		assertEquals(1,fpWidget.getPrefences().size());
 	}
-	
-	/**
-	 * Test that we can add WAC feature
-	 * @throws Exception
-	 */
-	@Test
-	public void createFlatpackWithWAC() throws Exception{
-		
-		// upload a new widget to test with
-		W3CWidgetFactory fac = getFactory();
-		File testWidget = new File("build/widgets/bubbles.wgt");
-		fac.parse(testWidget);
-		download = fac.getUnzippedWidgetDirectory(); //download is where we unzipped the widget
-		
-		// Create an instance of it
-		IWidgetInstance instance = new WidgetInstanceMock();
-		
-		// Flatpack it
-		FlatpackFactory flatfac = new FlatpackFactory(instance);
-		flatfac.setParser(fac);
-		flatfac.setIncludeWacFeatures(true);
-		flatfac.setInputWidget(testWidget); // this is the original .wgt
-		flatfac.setFlatpackFolder(flatpack); // flatpack is our new temp folder. This would probably be "/flatpack" or similar in deployment
-		File file = flatfac.pack(); // Get the new .wgt file
-	
-		// Test it works!
-		System.out.println(file.getAbsolutePath());
-		fac.setFeatures(new String[]{"http://jil.org/jil/api/1.1/widget"});
-		W3CWidget fpWidget = fac.parse(file);
-		assertEquals("http://jil.org/jil/api/1.1/widget", fpWidget.getFeatures().get(0).getName());
-	}
 
 	/*
 	 * Construct a standard W3CWidgetFactory for testing

Modified: incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FlatpackControllerTest.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FlatpackControllerTest.java?rev=1134963&r1=1134962&r2=1134963&view=diff
==============================================================================
--- incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FlatpackControllerTest.java (original)
+++ incubator/wookie/trunk/src-tests/org/apache/wookie/tests/functional/FlatpackControllerTest.java Sun Jun 12 19:23:12 2011
@@ -31,6 +31,7 @@ public class FlatpackControllerTest exte
 	
 	private static final String TEST_FLATPACK_SERVICE_URL_VALID = TEST_SERVER_LOCATION+"flatpack";
 	private static final String TEST_EXPORT_SERVICE_URL_VALID = TEST_SERVER_LOCATION+"export";
+	private static String test_id_key = "";
 	
 	@BeforeClass
 	public static void setup() throws HttpException, IOException{
@@ -38,6 +39,7 @@ public class FlatpackControllerTest exte
         PostMethod post = new PostMethod(TEST_INSTANCES_SERVICE_URL_VALID);
         post.setQueryString("api_key="+API_KEY_VALID+"&widgetid="+WIDGET_ID_VALID+"&userid=FPtest&shareddatakey=test");
         client.executeMethod(post);
+        test_id_key = post.getResponseBodyAsString().substring(post.getResponseBodyAsString().indexOf("<identifier>")+12,post.getResponseBodyAsString().indexOf("</identifier>"));
         post.releaseConnection();
 	}
 	
@@ -84,4 +86,28 @@ public class FlatpackControllerTest exte
 	    	fail("post failed");
 	    }
 	}
+	
+	 @Test
+	  public void getPackUsingResourceId(){
+	      try {
+	          HttpClient client = new HttpClient();
+	          PostMethod post = new PostMethod(TEST_FLATPACK_SERVICE_URL_VALID+"/"+test_id_key);
+	          post.setQueryString("api_key="+API_KEY_VALID);
+	          client.executeMethod(post);
+	          int code = post.getStatusCode();
+	          assertEquals(200,code);
+	          String url = post.getResponseBodyAsString();
+	          post.releaseConnection();
+	          
+	          // Now lets try to download it!
+	          GetMethod get = new GetMethod(url);
+	          client.executeMethod(get);
+	          code = get.getStatusCode();
+	          assertEquals(200, code);
+	      }
+	      catch (Exception e) {
+	        e.printStackTrace();
+	        fail("post failed");
+	      }
+	  }
 }

Modified: incubator/wookie/trunk/src/org/apache/wookie/flatpack/FlatpackController.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/flatpack/FlatpackController.java?rev=1134963&r1=1134962&r2=1134963&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/flatpack/FlatpackController.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/flatpack/FlatpackController.java Sun Jun 12 19:23:12 2011
@@ -30,15 +30,17 @@ import org.apache.wookie.exceptions.Unau
 import org.apache.wookie.helpers.WidgetKeyManager;
 
 /**
- * @author scottbw@apache.org
- *
+ * Controller for the Flatpack/exports API
+ * 
+ * This class provides a controller front end for the FlatpackFactory class, enabling the export of Widget Instances via a HTTP POST request.
+ * 
+ * POST /flatpack/ {params: api_key, instance_params OR id_key} creates a new W3C Widget package (.wgt) with an opaque file name for the specified widget instance, and returns the download URL. 
+ * If an invalid API key is supplied, a 401 error code is returned. If no instance can be found, or the parameters supplied are invalid, a 400 error code is returned.
  */
 public class FlatpackController extends Controller {
 
 	private static final long serialVersionUID = 2907712805939515004L;
 	static Logger _logger = Logger.getLogger(FlatpackController.class.getName());	
-	
-	
 
 	/**
 	 * Deny access to the listing of the flatpack folder
@@ -49,6 +51,9 @@ public class FlatpackController extends 
 		response.sendError(HttpServletResponse.SC_FORBIDDEN);
 	}
 
+	/**
+	 * We override the default POST method from Controller as we need to return the package URL in the Response to the client
+	 */
 	@Override
 	protected void doPost(HttpServletRequest request,
 			HttpServletResponse response) throws ServletException, IOException {

Modified: incubator/wookie/trunk/src/org/apache/wookie/flatpack/FlatpackFactory.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/flatpack/FlatpackFactory.java?rev=1134963&r1=1134962&r2=1134963&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/flatpack/FlatpackFactory.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/flatpack/FlatpackFactory.java Sun Jun 12 19:23:12 2011
@@ -21,7 +21,6 @@ import org.apache.wookie.beans.IWidgetIn
 import org.apache.wookie.w3c.IPreferenceEntity;
 import org.apache.wookie.w3c.W3CWidget;
 import org.apache.wookie.w3c.W3CWidgetFactory;
-import org.apache.wookie.w3c.impl.FeatureEntity;
 import org.apache.wookie.w3c.impl.PreferenceEntity;
 import org.apache.wookie.w3c.util.RandomGUID;
 import org.apache.wookie.w3c.util.WidgetOutputter;
@@ -41,8 +40,6 @@ import org.apache.wookie.w3c.util.Widget
  *   <dd>The Widget Instance to be flatpacked.</dd>
  *   <dt>flatpackFolder</dt>
  *   <dd>The folder on the file system where the flatpacked Widget package should be saved. If this is not specified, DEFAULT_FLATPACK_FOLDER will be used</dd>
- *   <dt>includeWacFeatures</dt>
- *   <dd>If set to true, the exported Widget package will include core WAC/JIL feature elements. This is false by default.</dd>
  *   <dt>featuresToFlatten</dt>
  *   <dd>The features that should be "flattened" rather than omitted - that is, that should be injected into the final package.</dd>
  * </dl>
@@ -54,13 +51,11 @@ public class FlatpackFactory {
 	public static final W3CWidgetFactory DEFAULT_PARSER = createDefaultParser();
 	public static final File DEFAULT_FLATPACK_FOLDER = new File("export");
 	private static final String DEFAULT_LOCAL_PATH = "/widgets"; // The default local path to use
-	private static final String WAC_FEATURE_NAME = "http://jil.org/jil/api/1.1/widget";
 	
 	private W3CWidgetFactory parser; // the widget parser to use
 	private IWidgetInstance instance; // the instance of the widget to flatpack
 	private File inputWidget; // the source .wgt file for the instance
 	private File flatpackFolder; // the folder where we put all our flatpack .wgt files once we've created them
-	private boolean includeWacFeatures = false; // set to true if the WAC/JIL core features should be added
 	
 	/**
 	 * Constructor, takes a Widget Instance as its argument
@@ -144,12 +139,6 @@ public class FlatpackFactory {
 		
 		// TODO Remove any flattened features
 		
-		// Add WAC/JIL features if needed
-		if (includeWacFeatures){
-			FeatureEntity wac = new FeatureEntity(WAC_FEATURE_NAME, true);
-			widget.getFeatures().add(wac);
-		}
-		
 		return widget;
 	}
 	
@@ -187,14 +176,6 @@ public class FlatpackFactory {
 	}
 	
 	/**
-	 * Set whether to include WAC/JIL features in the flatpacked Widget
-	 * @param includeWacFeatures
-	 */
-	public void setIncludeWacFeatures(boolean includeWacFeatures){
-		this.includeWacFeatures = includeWacFeatures;
-	}
-	
-	/**
 	 * Sets the W3CWidgetFactory to use as the widget parser
 	 * Note that we override the startPageProcessor with FlatpackProcessor
 	 * and rewrite the local path to DEFAULT_LOCAL_PATH.