[flaptor-util] r199 committed - Added a Simple Servlet that doesn't require a directory structure or a...

0 views
Skip to first unread message

codesite...@google.com

unread,
Aug 6, 2009, 1:37:44 PM8/6/09
to flaptor-o...@googlegroups.com
Revision: 199
Author: jhandl
Date: Thu Aug 6 10:36:48 2009
Log: Added a Simple Servlet that doesn't require a directory structure or a
web.xml file.
Changed the name of a method to make the code more readable.

http://code.google.com/p/flaptor-util/source/detail?r=199

Added:
/trunk/src/com/flaptor/util/remote/ASimpleServlet.java
Modified:
/trunk/src/com/flaptor/util/DomUtil.java
/trunk/src/com/flaptor/util/TrieTree.java
/trunk/src/com/flaptor/util/cache/RmiCacheStub.java
/trunk/src/com/flaptor/util/parser/HtmlParser.java
/trunk/src/com/flaptor/util/remote/ARmiClientStub.java
/trunk/src/com/flaptor/util/remote/AlwaysRetryPolicy.java
/trunk/src/com/flaptor/util/remote/ExponentialFallbackPolicy.java
/trunk/src/com/flaptor/util/remote/IRetryPolicy.java

=======================================
--- /dev/null
+++ /trunk/src/com/flaptor/util/remote/ASimpleServlet.java Thu Aug 6
10:36:48 2009
@@ -0,0 +1,48 @@
+package com.flaptor.util.remote;
+
+
+import javax.servlet.http.HttpServlet;
+import org.apache.log4j.Logger;
+import com.flaptor.util.Execute;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.servlet.ServletMapping;
+
+/**
+ * Simple Servlet that doesn't require a directory structure or a web.xml
file.
+ * Must be extended to implement the init and the service methods.
+ */
+public abstract class ASimpleServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+ private static final Logger logger =
Logger.getLogger(Execute.whoAmI());
+
+
+ /**
+ * Start the servlet
+ * @param servletClass the class that extends ASimpleServlet.
+ * @param port the port the servlet will be listenting on.
+ * @param contextPath the context path where the servlet will attend.
+ * @param pathSpec a regular expression selecting the paths the
servlet will attend.
+ * @throws java.lang.Exception may be thrown when starting the server.
+ */
+ public void startServlet(Class servletClass, int port, String
contextPath, String pathSpec) throws Exception {
+ Server server = new Server(port);
+ Context context = new Context();
+ context.setContextPath(contextPath);
+ server.addHandler(context);
+ ServletHandler handler = context.getServletHandler();
+ ServletHolder holder = new ServletHolder();
+ holder.setClassName(servletClass.getName());
+ holder.setName(servletClass.getSimpleName());
+ handler.addServlet(holder);
+ ServletMapping mapping = new ServletMapping();
+ mapping.setServletName(servletClass.getSimpleName());
+ mapping.setPathSpec(pathSpec);
+ handler.addServletMapping(mapping);
+ server.start();
+ }
+
+}
=======================================
--- /trunk/src/com/flaptor/util/DomUtil.java Fri May 15 15:09:59 2009
+++ /trunk/src/com/flaptor/util/DomUtil.java Thu Aug 6 10:36:48 2009
@@ -41,6 +41,7 @@
*/
public static String domToString(final Document doc) {
OutputFormat of = OutputFormat.createPrettyPrint();
+ of.setEncoding("UTF-8");
StringWriter sw = new StringWriter();
XMLWriter writer = null;
try {
=======================================
--- /trunk/src/com/flaptor/util/TrieTree.java Fri Jun 5 13:04:51 2009
+++ /trunk/src/com/flaptor/util/TrieTree.java Thu Aug 6 10:36:48 2009
@@ -121,11 +121,11 @@
}

/**
- * Returns the object stored at the provided key.
+ * Returns the node stored at the provided key.
* @param key the key to search for.
- * @return the stored object associated with the key if found, null
otherwise.
+ * @return the stored node associated with the key if found, null
otherwise.
*/
- public TrieTree<Type> getNode (String key) {
+ private TrieTree<Type> getNode (String key) {
if (null == key || key.length() == 0) { // empty or null keys are
not stored
return null;
}
=======================================
--- /trunk/src/com/flaptor/util/cache/RmiCacheStub.java Thu Oct 2 13:39:31
2008
+++ /trunk/src/com/flaptor/util/cache/RmiCacheStub.java Thu Aug 6 10:36:48
2009
@@ -89,7 +89,7 @@
}

public Object doRemote(RemoteAction remoteAction) throws RpcException {
- if (policy.reconnect()) {
+ if (policy.shouldReconnect()) {
connect();
}
if (policy.callServer()) {
=======================================
--- /trunk/src/com/flaptor/util/parser/HtmlParser.java Fri May 15 15:09:59
2009
+++ /trunk/src/com/flaptor/util/parser/HtmlParser.java Thu Aug 6 10:36:48
2009
@@ -106,7 +106,7 @@
*/
public HtmlParser(String ignoreXPath, String[] separatorTags,
Map<String,String> fieldDefinitions) {
int processors = Runtime.getRuntime().availableProcessors();
- logger.info("constructor: found " + processors + " processors.
Creating the same number of parsers.");
+ logger.debug("constructor: found " + processors + " processors.
Creating the same number of parsers.");
parsers = new ArrayBlockingQueue<DOMParser>(processors);
for (int i = 0; i < processors; i++) {
DOMParser parser = new org.cyberneko.html.parsers.DOMParser();
=======================================
--- /trunk/src/com/flaptor/util/remote/ARmiClientStub.java Tue Dec 2
08:20:17 2008
+++ /trunk/src/com/flaptor/util/remote/ARmiClientStub.java Thu Aug 6
10:36:48 2009
@@ -69,8 +69,8 @@
Reconnects to the searcher if necessary, and return wheather the rpc
should be performed or not.
**/
public boolean checkConnection() throws RemoteException{
- boolean reconnect = policy.reconnect() || !remoteInitialized;
- if (reconnect) {
+ boolean needToReconnect = policy.shouldReconnect() |
| !remoteInitialized;
+ if (needToReconnect) {
try {
connect();
return true;
=======================================
--- /trunk/src/com/flaptor/util/remote/AlwaysRetryPolicy.java Fri Jan 11
11:46:32 2008
+++ /trunk/src/com/flaptor/util/remote/AlwaysRetryPolicy.java Thu Aug 6
10:36:48 2009
@@ -35,7 +35,7 @@
lastSuccess = true;
}

- public boolean reconnect() {
+ public boolean shouldReconnect() {
return !lastSuccess;
}

=======================================
--- /trunk/src/com/flaptor/util/remote/ExponentialFallbackPolicy.java Tue
Oct 14 12:28:36 2008
+++ /trunk/src/com/flaptor/util/remote/ExponentialFallbackPolicy.java Thu
Aug 6 10:36:48 2009
@@ -70,7 +70,7 @@
connectionState = ConnectionState.CONNECTED;
}

- public synchronized boolean reconnect() {
+ public synchronized boolean shouldReconnect() {
boolean retVal;
ConnectionState startState = connectionState;
if (connectionState == ConnectionState.CONNECTED || connectionState
== ConnectionState.RECONECTING) {
=======================================
--- /trunk/src/com/flaptor/util/remote/IRetryPolicy.java Fri Jan 11
11:46:32 2008
+++ /trunk/src/com/flaptor/util/remote/IRetryPolicy.java Thu Aug 6
10:36:48 2009
@@ -51,5 +51,5 @@
* the first time it's called.
* @return true if the ClientStub is to try to reconnect to the server.
*/
- public boolean reconnect();
-}
+ public boolean shouldReconnect();
+}

Reply all
Reply to author
Forward
0 new messages