Index: contrib/gdata-server/webroot/web.xml
===================================================================
--- contrib/gdata-server/webroot/web.xml (revision 0)
+++ contrib/gdata-server/webroot/web.xml (revision 0)
@@ -0,0 +1,19 @@
+
+AbstractGdataServlet
+ * @author Simon Willnauer
+ *
+ */
+ static class StubGDataServlet extends AbstractGdataServlet {
+
+ private static final long serialVersionUID = -6271464588547620925L;
+
+ protected void doDelete(HttpServletRequest arg0,
+ HttpServletResponse arg1) {
+ if (arg0.getHeader(METHOD_HEADER_NAME) == null)
+ assertEquals("Http-Method --DELETE--", METHOD_DELETE, arg0
+ .getMethod());
+ else
+ assertEquals("Http-Method override --DELETE--", METHOD_DELETE,
+ arg0.getHeader(METHOD_HEADER_NAME));
+
+ }
+
+ protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) {
+ if (arg0.getHeader(METHOD_HEADER_NAME) == null)
+ assertEquals("Http-Method --GET--", arg0.getMethod(),
+ METHOD_GET);
+ else
+ assertEquals("Http-Method override --GET--", arg0
+ .getHeader(METHOD_HEADER_NAME), METHOD_GET);
+ }
+
+ protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) {
+ if (arg0.getHeader(METHOD_HEADER_NAME) == null)
+ assertEquals("Http-Method --POST--", arg0.getMethod(),
+ METHOD_POST);
+ else
+ assertEquals("Http-Method override --POST--", METHOD_POST, arg0
+ .getHeader(METHOD_HEADER_NAME));
+
+ }
+
+ protected void doPut(HttpServletRequest arg0, HttpServletResponse arg1) {
+ if (arg0.getHeader(METHOD_HEADER_NAME) == null)
+ assertEquals("Http-Method --PUT--", arg0.getMethod(),
+ METHOD_PUT);
+ else
+ assertEquals("Http-Method override --PUT--", arg0
+ .getHeader(METHOD_HEADER_NAME), METHOD_PUT);
+ }
+
+ }
+
+}
Index: contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/RequestControllerServlet.java
===================================================================
--- contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/RequestControllerServlet.java (revision 0)
+++ contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/RequestControllerServlet.java (revision 0)
@@ -0,0 +1,102 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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 org.apache.lucene.gdata.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.lucene.gdata.servlet.handler.DefaultRequestHandlerFactory;
+import org.apache.lucene.gdata.servlet.handler.GDataRequestHandler;
+import org.apache.lucene.gdata.servlet.handler.RequestHandlerFactory;
+
+/**
+ * Provides a clean basic interface for GDATA Client API and requests to the
+ * GDATA Server. This Servlet dispatches the incoming requests to defined GDATA
+ * request handlers. Each of the handler processes the incoming request and
+ * responds according to the requested action.
+ *
+ * @author Simon Willnauer
+ *
+ */
+public class RequestControllerServlet extends AbstractGdataServlet {
+ private static RequestHandlerFactory HANDLER_FACTORY = null;
+
+ /**
+ * Version ID since this class implements
+ *
+ * @see java.io.Serializable
+ */
+ private static final long serialVersionUID = 7540810742476175576L;
+
+ /**
+ * @see javax.servlet.http.HttpServlet#doDelete(javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
+ */
+ protected void doDelete(HttpServletRequest arg0, HttpServletResponse arg1)
+ throws ServletException, IOException {
+ GDataRequestHandler hanlder = HANDLER_FACTORY.getDeleteHandler();
+ hanlder.processRequest(arg0, arg1);
+ }
+
+ /**
+ * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
+ */
+ protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1)
+ throws ServletException, IOException {
+ GDataRequestHandler hanlder = HANDLER_FACTORY.getQueryHandler();
+ hanlder.processRequest(arg0, arg1);
+ }
+
+ /**
+ * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
+ */
+ protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1)
+ throws ServletException, IOException {
+ GDataRequestHandler hanlder = HANDLER_FACTORY.getInsertHandler();
+ hanlder.processRequest(arg0, arg1);
+ }
+
+ /**
+ * @see javax.servlet.http.HttpServlet#doPut(javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
+ */
+ protected void doPut(HttpServletRequest arg0, HttpServletResponse arg1)
+ throws ServletException, IOException {
+ GDataRequestHandler hanlder = HANDLER_FACTORY.getUpdateHandler();
+ hanlder.processRequest(arg0, arg1);
+ }
+
+ /**
+ * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
+ */
+ public void init(ServletConfig arg0) throws ServletException {
+ /*
+ * The Factory implementation could be configured as an initial
+ * parameter or by an external config file.
+ *
+ */
+ HANDLER_FACTORY = RequestHandlerFactory
+ .getInstance(DefaultRequestHandlerFactory.class);
+
+ }
+}
Index: contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AbstractGdataServlet.java
===================================================================
--- contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AbstractGdataServlet.java (revision 0)
+++ contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AbstractGdataServlet.java (revision 0)
@@ -0,0 +1,96 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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 org.apache.lucene.gdata.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * Provides an abstract class to be subclassed to create an GDATA servlet
+ * suitable for a GDATA serverside implementation.
+ *
+ * @see javax.servlet.http.HttpServlet
+ *
+ * @author Simon Willnauer
+ *
+ */
+public abstract class AbstractGdataServlet extends HttpServlet {
+ private static final String METHOD_HEADER_NAME = "x-http-method-override";
+
+ private static final String METHOD_DELETE = "DELETE";
+
+ private static final String METHOD_GET = "GET";
+
+ private static final String METHOD_POST = "POST";
+
+ private static final String METHOD_PUT = "PUT";
+
+ /**
+ * This overwrites the protected service method to dispatch
+ * the request to the correponding do method. There is
+ * ususaly no need for overwriting this method. The GData protool and the
+ * Google GData API uses the x-http-method-override header to
+ * get through firewalls. The http method will be overritten by the
+ * x-http-method-override and dispatched to the
+ * doXXX methods defined in this class. This method
+ * is an GDATA-specific version of the {@link javax.servlet.Servlet#service}
+ * method.
+ *
+ * @see HttpServlet#service(javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
+ */
+ protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
+ throws ServletException, IOException {
+ if (arg0.getHeader(METHOD_HEADER_NAME) == null) {
+ super.service(arg0, arg1);
+ return;
+ }
+ overrideMethod(arg0, arg1);
+
+ }
+
+ private void overrideMethod(HttpServletRequest arg0,
+ HttpServletResponse arg1) throws ServletException, IOException {
+ final String method = arg0.getMethod();
+ final String overrideHeaderMethod = arg0.getHeader(METHOD_HEADER_NAME);
+ if (overrideHeaderMethod.equals(method)) {
+ super.service(arg0, arg1);
+ return;
+ }
+ // These methodes are use by GDATA Client APIs
+ if (overrideHeaderMethod.equals(METHOD_DELETE)) {
+ doDelete(arg0, arg1);
+ } else if (overrideHeaderMethod.equals(METHOD_GET)) {
+ doGet(arg0, arg1);
+ } else if (overrideHeaderMethod.equals(METHOD_POST)) {
+ doPost(arg0, arg1);
+ } else if (overrideHeaderMethod.equals(METHOD_PUT)) {
+ doPut(arg0, arg1);
+ } else {
+ // if another method has been overwritten follow the HttpServlet
+ // implementation
+ super.service(arg0, arg1);
+ }
+
+ }
+
+}
Index: contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultRequestHandlerFactory.java
===================================================================
--- contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultRequestHandlerFactory.java (revision 0)
+++ contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/DefaultRequestHandlerFactory.java (revision 0)
@@ -0,0 +1,74 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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 org.apache.lucene.gdata.servlet.handler;
+
+
+/**
+ * Default implementation for RequestHandlerFactory
+ * @author Simon Willnauer
+ *
+ */
+public class DefaultRequestHandlerFactory extends RequestHandlerFactory {
+
+ DefaultRequestHandlerFactory() {
+ //
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.servlet.handler.RequestHandlerFactory#getUpdateHandler()
+ */
+ public GDataRequestHandler getUpdateHandler() {
+
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.servlet.handler.RequestHandlerFactory#getDeleteHandler()
+ */
+ public GDataRequestHandler getDeleteHandler() {
+
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.servlet.handler.RequestHandlerFactory#getQueryHandler()
+ */
+ public GDataRequestHandler getQueryHandler() {
+
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.servlet.handler.RequestHandlerFactory#getInsertHandler()
+ */
+ public GDataRequestHandler getInsertHandler() {
+
+ return null;
+ }
+
+ /**
+ * @see org.apache.lucene.gdata.servlet.handler.RequestHandlerFactory#getGetHandler()
+ */
+ public GDataRequestHandler getGetHandler() {
+
+ return null;
+ }
+
+
+
+
+}
Index: contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/GDataRequestHandlerException.java
===================================================================
--- contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/GDataRequestHandlerException.java (revision 0)
+++ contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/GDataRequestHandlerException.java (revision 0)
@@ -0,0 +1,64 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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 org.apache.lucene.gdata.servlet.handler;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public class GDataRequestHandlerException extends RuntimeException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -418225239671624153L;
+
+
+ /**
+ *
+ */
+ public GDataRequestHandlerException() {
+ super();
+
+ }
+
+ /**
+ * @param arg0
+ */
+ public GDataRequestHandlerException(String arg0) {
+ super(arg0);
+
+ }
+
+ /**
+ * @param arg0
+ * @param arg1
+ */
+ public GDataRequestHandlerException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+
+ }
+
+ /**
+ * @param arg0
+ */
+ public GDataRequestHandlerException(Throwable arg0) {
+ super(arg0);
+
+ }
+
+}
Index: contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/GDataRequestHandler.java
===================================================================
--- contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/GDataRequestHandler.java (revision 0)
+++ contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/GDataRequestHandler.java (revision 0)
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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 org.apache.lucene.gdata.servlet.handler;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ *
+ * Based on the Command pattern [GoF], the Command and Controller Strategy
+ * suggests providing a generic interface to the handler components to which the
+ * controller may delegate responsibility, minimizing the coupling among these
+ * components.
+ *
+ * Adding to or changing the work that needs to be completed by these handlers
+ * does not require any changes to the interface between the controller and the
+ * handlers, but rather to the type and/or content of the commands. This provides
+ * a flexible and easily extensible mechanism for developers to add request
+ * handling behaviors.
+ *
+ * The controller invokes the processRequest method from the corresponding servlet doXXX
+ * method to delegate the request to the handler.
+ *
+ *
+ * @author Simon Willnauer
+ *
+ */
+public interface GDataRequestHandler {
+ /**
+ * Processes the GDATA Client request
+ *
+ * @param request - the client request to be processed
+ * @param response - the response to the client request
+ * @throws ServletException - if a servlet exception is thrown by the request or response
+ * @throws IOException - if an input/output error occurs due to accessing an IO steam
+ */
+ public abstract void processRequest(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException, IOException;
+}
Index: contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/RequestHandlerFactory.java
===================================================================
--- contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/RequestHandlerFactory.java (revision 0)
+++ contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/RequestHandlerFactory.java (revision 0)
@@ -0,0 +1,122 @@
+/**
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * 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 org.apache.lucene.gdata.servlet.handler;
+
+/**
+ * @author Simon Willnauer
+ *
+ */
+public abstract class RequestHandlerFactory {
+
+ private static RequestHandlerFactory INSTANCE = null;
+
+ /**
+ * This method creates a singleton instance of the given type. The fist call
+ * will create an instance of the given class which will be returned in
+ * every subsequent call. Any subsequent call to this method will ignore the
+ * given class object.
+ *
+ * @param factoryImplementation -
+ * the factory implementation (must be a subtype of this Class)
+ *
+ * @return - a singleton instance of the given type
+ *
+ */
+ public static synchronized RequestHandlerFactory getInstance(
+ Class factoryImplementation) {
+ if (INSTANCE == null) {
+
+ INSTANCE = createInstance(factoryImplementation);
+ }
+ return INSTANCE;
+ }
+
+ /**
+ * Singleton - Pattern using private constructor
+ *
+ */
+ RequestHandlerFactory() {
+ super();
+
+ }
+
+ private static RequestHandlerFactory createInstance(
+ final Class qualifiedClass) {
+ if (qualifiedClass == null)
+ throw new IllegalArgumentException(
+ "Factory class is null -- must be a implementation of org.apache.lucene.gdata.servlet.handler.RequestHandlerFactory");
+ try {
+ return (RequestHandlerFactory) qualifiedClass.newInstance();
+ } catch (Exception e) {
+ FactoryImplementationException ex = new FactoryImplementationException(
+ "Factory implementation could not be created", e.getCause());
+ ex.setStackTrace(e.getStackTrace());
+ throw ex;
+ }
+ }
+
+ /**
+ * Creates a UpdateHandler which processes a GDATA UPDATE request.
+ * @return - an RequestHandlerInstance
+ */
+ public abstract GDataRequestHandler getUpdateHandler();
+
+ /**
+ * Creates a DeleteHandler which processes a GDATA DELETE request.
+ * @return - an RequestHandlerInstance
+ */
+ public abstract GDataRequestHandler getDeleteHandler();
+
+ /**
+ * Creates a QueryHandler which processes a GDATA Query / Get request.
+ * @return - an RequestHandlerInstance
+ */
+ public abstract GDataRequestHandler getQueryHandler();
+
+ /**
+ * Creates a InsertHandler which processes a GDATA Insert request.
+ * @return - an RequestHandlerInstance
+ */
+ public abstract GDataRequestHandler getInsertHandler();
+
+
+
+ private static class FactoryImplementationException extends
+ RuntimeException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 3166033278825112569L;
+
+ /**
+ * Constructs a new FactoryImplementationException with the specified
+ * cause and message
+ *
+ * @param arg0 -
+ * the detail message
+ * @param arg1 -
+ * the throw cause
+ */
+ public FactoryImplementationException(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+
+ }
+
+ }
+
+}
Index: contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/package.html
===================================================================
--- contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/package.html (revision 0)
+++ contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/package.html (revision 0)
@@ -0,0 +1,10 @@
+
+
+