You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by rg...@apache.org on 2010/06/11 02:00:05 UTC

svn commit: r953508 - in /incubator/wookie/trunk: ./ src/org/apache/wookie/controller/Controller.java src/org/apache/wookie/controller/ParticipantsController.java src/org/apache/wookie/controller/WidgetInstancesController.java

Author: rgardler
Date: Fri Jun 11 00:00:05 2010
New Revision: 953508

URL: http://svn.apache.org/viewvc?rev=953508&view=rev
Log:
- url decode parameters (the connectors are encoding them)

- some javadoc

- some logging

Modified:
    incubator/wookie/trunk/   (props changed)
    incubator/wookie/trunk/src/org/apache/wookie/controller/Controller.java
    incubator/wookie/trunk/src/org/apache/wookie/controller/ParticipantsController.java
    incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java

Propchange: incubator/wookie/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Jun 11 00:00:05 2010
@@ -2,3 +2,7 @@ bin
 IMS_Docs
 Thumbs.db
 non-cvs
+
+build
+
+widgetDB

Modified: incubator/wookie/trunk/src/org/apache/wookie/controller/Controller.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/controller/Controller.java?rev=953508&r1=953507&r2=953508&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/controller/Controller.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/controller/Controller.java Fri Jun 11 00:00:05 2010
@@ -23,6 +23,7 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.log4j.Logger;
 import org.apache.wookie.exceptions.InvalidParametersException;
 import org.apache.wookie.exceptions.ResourceDuplicationException;
 import org.apache.wookie.exceptions.ResourceNotFoundException;
@@ -34,6 +35,7 @@ import org.apache.wookie.exceptions.Unau
 public abstract class Controller extends HttpServlet{
 
 	private static final long serialVersionUID = 2791062551643568756L;
+  static Logger _logger = Logger.getLogger(Controller.class.getName()); 
 
 	/**
 	 * Content type for XML output
@@ -96,6 +98,7 @@ public abstract class Controller extends
 		} catch (UnauthorizedAccessException e){
 			response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
 		} catch (InvalidParametersException e){
+		  _logger.debug(e);
 			response.sendError(HttpServletResponse.SC_BAD_REQUEST);
 		}
 	}
@@ -114,11 +117,14 @@ public abstract class Controller extends
 				response.setStatus(HttpServletResponse.SC_OK);				
 			}
 		} catch (ResourceDuplicationException e) {
+		  _logger.error(e.getMessage(), e);
 			response.sendError(HttpServletResponse.SC_CONFLICT);// already exists with same name - need error message for this
 		} catch (InvalidParametersException e){
-			response.sendError(HttpServletResponse.SC_BAD_REQUEST); 
+		  _logger.error(e.getMessage(), e);
+      response.sendError(HttpServletResponse.SC_BAD_REQUEST); 
 		} catch (UnauthorizedAccessException e){
-			response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+		  _logger.error(e.getMessage(), e);
+      response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
 		}
 	}
 

Modified: incubator/wookie/trunk/src/org/apache/wookie/controller/ParticipantsController.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/controller/ParticipantsController.java?rev=953508&r1=953507&r2=953508&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/controller/ParticipantsController.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/controller/ParticipantsController.java Fri Jun 11 00:00:05 2010
@@ -84,6 +84,16 @@ public class ParticipantsController exte
 			UnauthorizedAccessException {
 		return create(request);
 	}
+	
+	/**
+	 * Add a participant to a widget.
+	 * 
+	 * @param request
+	 * @return
+	 * @throws ResourceDuplicationException
+	 * @throws InvalidParametersException
+	 * @throws UnauthorizedAccessException
+	 */
 	public static boolean create(HttpServletRequest request)
 			throws ResourceDuplicationException, InvalidParametersException,
 			UnauthorizedAccessException {
@@ -98,7 +108,10 @@ public class ParticipantsController exte
 		String participant_thumbnail_url = request.getParameter("participant_thumbnail_url"); //$NON-NLS-1$
 		
 		// Check required params
-		if (participant_id == null || participant_id.trim().equals("")) throw new InvalidParametersException();
+		if (participant_id == null || participant_id.trim().equals("")) {
+		  _logger.error("participant_id parameter cannot be null");
+		  throw new InvalidParametersException();
+		}
 
 		if (addParticipantToWidgetInstance(instance, participant_id, participant_display_name, participant_thumbnail_url)){
 			Notifier.notifyWidgets(session, instance, Notifier.PARTICIPANTS_UPDATED);

Modified: incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java
URL: http://svn.apache.org/viewvc/incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java?rev=953508&r1=953507&r2=953508&view=diff
==============================================================================
--- incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java (original)
+++ incubator/wookie/trunk/src/org/apache/wookie/controller/WidgetInstancesController.java Fri Jun 11 00:00:05 2010
@@ -16,8 +16,10 @@ package org.apache.wookie.controller;
 
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.net.URLDecoder;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -323,17 +325,27 @@ public class WidgetInstancesController e
 			instance = WidgetInstance.findByIdKey(id_key);
 			return instance;
 		}
+
+    try {
+  		String apiKey = URLDecoder.decode(request.getParameter("api_key"), "UTF-8"); //$NON-NLS-1$
+  		String userId = URLDecoder.decode(request.getParameter("userid"), "UTF-8"); //$NON-NLS-1$
+  		String sharedDataKey = WidgetInstancesController.getSharedDataKey(request);	
+  		String serviceType = URLDecoder.decode(request.getParameter("servicetype"), "UTF-8"); //$NON-NLS-1$
+  		String widgetId = URLDecoder.decode(request.getParameter("widgetid"), "UTF-8"); //$NON-NLS-1$
+      if (widgetId != null){
+        _logger.info("Looking for widget instance with widgetid of " + widgetId);
+        instance = WidgetInstance.getWidgetInstanceById(apiKey, userId, sharedDataKey, widgetId);
+      } else {
+        _logger.info("Looking for widget instance of service type " + serviceType);
+        instance = WidgetInstance.getWidgetInstance(apiKey, userId, sharedDataKey, serviceType);
+      }
+      if (instance == null) {
+        _logger.error("No widget instance for found");
+      }
+      return instance;
+    } catch (UnsupportedEncodingException e) {
+      throw new RuntimeException("Server must support UTF-8 encoding", e);
+    } //$NON-NLS-1$
 		
-		String apiKey = request.getParameter("api_key"); //$NON-NLS-1$
-		String userId = request.getParameter("userid"); //$NON-NLS-1$
-		String sharedDataKey = WidgetInstancesController.getSharedDataKey(request);	
-		String serviceType = request.getParameter("servicetype"); //$NON-NLS-1$
-		String widgetId = request.getParameter("widgetid"); //$NON-NLS-1$
-		if (widgetId != null){
-			instance = WidgetInstance.getWidgetInstanceById(apiKey, userId, sharedDataKey, widgetId);
-		} else {
-			instance = WidgetInstance.getWidgetInstance(apiKey, userId, sharedDataKey, serviceType);
-		}
-		return instance;
 	}
 }
\ No newline at end of file