You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by si...@apache.org on 2006/05/27 18:23:47 UTC
svn commit: r409834 - in /lucene/nutch/trunk/contrib/web2/src/main:
java/org/apache/nutch/webapp/common/ java/org/apache/nutch/webapp/controller/
java/org/apache/nutch/webapp/servlet/ java/org/apache/nutch/webapp/tiles/
test/ test/org/ test/org/apache/...
Author: siren
Date: Sat May 27 09:23:45 2006
New Revision: 409834
URL: http://svn.apache.org/viewvc?rev=409834&view=rev
Log:
add support for jsp templates and static resources inside plugin jars
Added:
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebAppModule.java
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/JspDispatcherServlet.java
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/ResourceServlet.java
lucene/nutch/trunk/contrib/web2/src/main/test/
lucene/nutch/trunk/contrib/web2/src/main/test/org/
lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/
lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/
lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/webapp/
lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/
lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestNutchHttpServlet.java
lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestWebAppModule.java
Modified:
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/SearchController.java
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/NutchHttpServlet.java
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/ExtendableDefinitionsFactory.java
lucene/nutch/trunk/contrib/web2/src/main/webapp/WEB-INF/web.xml
Added: lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebAppModule.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebAppModule.java?rev=409834&view=auto
==============================================================================
--- lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebAppModule.java (added)
+++ lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/WebAppModule.java Sat May 27 09:23:45 2006
@@ -0,0 +1,195 @@
+/*
+ * Copyright 2006 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.nutch.webapp.common;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import java.lang.ClassLoader;
+
+/**
+ * This class is responsible for parsing web.xml definitions from plugins (put
+ * there by jspc when precompiling jsp files).
+ *
+ * Extracted information is used at runtime when dispatching requests targetted
+ * to jsp resources to the precompiled servlet classes.
+ */
+public class WebAppModule {
+
+ HashMap servlets;
+
+ List urlPatterns;
+
+ ClassLoader loader = null;
+
+ HashMap servletObjects = new HashMap();
+
+ private ServletConfig servletConfig;
+
+ /**
+ * Construct new WebAppModule
+ *
+ * @param input
+ * ionputstream to web.xml type of document
+ */
+ public WebAppModule(InputStream input) {
+ loader = Thread.currentThread().getContextClassLoader();
+ init(input);
+ }
+
+ public void init(InputStream input) {
+ Document doc;
+ servlets = new HashMap();
+ urlPatterns = new ArrayList();
+
+ if (input != null) {
+
+ try {
+ doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
+ input);
+ parse(doc);
+ } catch (SAXException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ }
+ }
+ loadServlets();
+ }
+
+ public void loadServlets() {
+
+ Iterator i = getPaths().iterator();
+
+ while (i.hasNext()) {
+
+ String key = (String) i.next();
+ String servletName = (String) servlets.get(key);
+ HttpServlet servletObject;
+ Class servletClass;
+ try {
+ servletClass = loader.loadClass(servletName);
+ servletObject = (HttpServlet) servletClass.newInstance();
+ servletObject.init(servletConfig);
+ servletObjects.put(key, servletObject);
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (ServletException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public WebAppModule(ClassLoader loader, ServletConfig config) {
+ servletConfig = config;
+ this.loader=loader;
+ init(loader.getResourceAsStream("META-INF/jsp-servlet-mappings.xml"));
+ }
+
+ /**
+ * Get jsp paths available
+ *
+ * @return
+ */
+ public List getPaths() {
+ return urlPatterns;
+ }
+
+ public Map getMappings() {
+ return servlets;
+ }
+
+ /**
+ * Return Servlet name for path or null if non existing
+ *
+ * @param path
+ * @return
+ */
+ public String getServletName(String path) {
+ return (String) servlets.get(path);
+ }
+
+ public void parse(Document doc) {
+
+ Element root = doc.getDocumentElement();
+ NodeList mappings = root.getElementsByTagName("servlet-mapping");
+ for (int i = 0; i < mappings.getLength(); i++) {
+ Element mapping = (Element) mappings.item(i);
+ Element servlet = (Element) mapping.getElementsByTagName("servlet-name")
+ .item(0);
+ Element pattern = (Element) mapping.getElementsByTagName("url-pattern")
+ .item(0);
+
+ String servletName = servlet.getTextContent().trim();
+ String urlPattern = pattern.getTextContent().trim();
+
+ servlets.put(urlPattern, servletName);
+ urlPatterns.add(urlPattern);
+ }
+ }
+
+ /**
+ * Dispatches request to precompiled jsp
+ *
+ * @param relPath
+ * @param request
+ * @param response
+ */
+ public void dispatch(String relPath, HttpServletRequest request,
+ HttpServletResponse response) {
+
+ HttpServlet servletObject;
+ if (servletObjects.containsKey(relPath)) {
+ servletObject = (HttpServlet) servletObjects.get(relPath);
+ } else {
+ // servlet not found??
+ return;
+ }
+ try {
+ servletObject.service(request, response);
+ } catch (ServletException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+}
Modified: lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/SearchController.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/SearchController.java?rev=409834&r1=409833&r2=409834&view=diff
==============================================================================
--- lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/SearchController.java (original)
+++ lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/controller/SearchController.java Sat May 27 09:23:45 2006
@@ -30,6 +30,9 @@
/* This is the main controller of nutch search application
*/
public class SearchController extends NutchController {
+
+ public static final String REQ_ATTR_SEARCH="nutchSearch";
+ public static final String REQ_ATTR_RESULTINFO="resultInfo";
public void nutchPerform(ComponentContext tileContext, HttpServletRequest request,
HttpServletResponse response, ServletContext servletContext)
@@ -38,10 +41,10 @@
ServiceLocator locator=getServiceLocator(request);
Search search=locator.getSearch();
- request.setAttribute("nutchSearch", search);
+ request.setAttribute(REQ_ATTR_SEARCH, search);
NutchBean bean = locator.getNutchBean();
search.performSearch(bean);
- request.setAttribute("resultInfo", search.getResultInfo());
+ request.setAttribute(REQ_ATTR_RESULTINFO, search.getResultInfo());
}
}
Added: lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/JspDispatcherServlet.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/JspDispatcherServlet.java?rev=409834&view=auto
==============================================================================
--- lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/JspDispatcherServlet.java (added)
+++ lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/JspDispatcherServlet.java Sat May 27 09:23:45 2006
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2006 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.nutch.webapp.servlet;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.nutch.plugin.Extension;
+import org.apache.nutch.plugin.ExtensionPoint;
+import org.apache.nutch.webapp.common.WebAppModule;
+import org.apache.nutch.webapp.extension.UIExtensionPoint;
+
+/**
+ * This Servlet is responsible for dispatching requests to jsp resources from
+ * plugins.
+ */
+public class JspDispatcherServlet extends NutchHttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ HashMap allMappings = new HashMap();
+
+ public void init(ServletConfig conf) throws ServletException {
+ super.init(conf);
+
+ // TODO should perhaps first try handle core definitions
+
+ // process extensions
+ ExtensionPoint point = getServiceLocator().getPluginRepository()
+ .getExtensionPoint(UIExtensionPoint.X_POINT_ID);
+
+ if (point != null) {
+
+ Extension[] extensions = point.getExtensions();
+
+ for (int i = 0; i < extensions.length; i++) {
+ Extension extension = extensions[i];
+
+ WebAppModule module = new WebAppModule(extension.getDescriptor()
+ .getClassLoader(), conf);
+ Iterator iterator = module.getPaths().iterator();
+
+ while (iterator.hasNext()) {
+ String path = (String) iterator.next();
+ allMappings.put(path, module);
+ }
+ }
+ }
+ }
+
+ /**
+ * Process request to jsp inside plugin (jsps must be precompiled)
+ *
+ */
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ //get jsp include path_info from request object
+ String relPath=(String)request.getAttribute("javax.servlet.include.path_info");
+
+ if (allMappings.containsKey(relPath)) {
+ WebAppModule module=(WebAppModule)allMappings.get(relPath);
+ module.dispatch(relPath, request,response);
+ }
+ }
+}
Modified: lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/NutchHttpServlet.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/NutchHttpServlet.java?rev=409834&r1=409833&r2=409834&view=diff
==============================================================================
--- lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/NutchHttpServlet.java (original)
+++ lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/NutchHttpServlet.java Sat May 27 09:23:45 2006
@@ -18,6 +18,7 @@
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
import org.apache.nutch.webapp.common.ServiceLocator;
import org.apache.nutch.webapp.common.ServletContextServiceLocator;
@@ -31,11 +32,41 @@
private ServiceLocator locator;
- public void init(ServletConfig servletConfig) throws ServletException {
- locator = ServletContextServiceLocator.getInstance(servletConfig
- .getServletContext());
+ public void init(final ServletConfig servletConfig) throws ServletException {
+ super.init(servletConfig);
+ locator = ServletContextServiceLocator.getInstance(getServletContext());
}
+ /**
+ * Return context relative path
+ *
+ * @return
+ */
+ public String getContextRelativePath(final HttpServletRequest request) {
+ return request.getRequestURI().substring(request.getContextPath().length());
+ }
+
+ /**
+ * Removes the first part of path String and returns new String
+ * if there is no path available return null
+ * @param path original path
+ * @return
+ */
+ public String getMappingRelativePath(final String path){
+
+ String relPath=null;
+
+ if(path.indexOf("/",(path.startsWith("/")?1:0))!=-1){
+ relPath=path.substring(path.indexOf('/',(path.startsWith("/")?1:0)));
+ }
+
+ return relPath;
+ }
+
+ /**
+ * Get ServiceLocator instance
+ * @return
+ */
public ServiceLocator getServiceLocator(){
return locator;
}
Added: lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/ResourceServlet.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/ResourceServlet.java?rev=409834&view=auto
==============================================================================
--- lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/ResourceServlet.java (added)
+++ lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/servlet/ResourceServlet.java Sat May 27 09:23:45 2006
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2006 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.nutch.webapp.servlet;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.nutch.plugin.PluginDescriptor;
+
+/**
+ * Simple Servlet that serves resources from plugins.
+ *
+ * Plugin must put resources to be exposed into path /resources/ for example
+ * resource /resources/possible/sub/folder/resource.jpg will then be available
+ * in location <contextPath>/resources/<plugin_id>/possible/sub/folder/resource.jpg
+ *
+ */
+public class ResourceServlet extends NutchHttpServlet {
+
+ private static final String PATH = "/resources/";
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Extract plugin id from path
+ *
+ * @param path
+ * @return
+ */
+ private String getPluginId(final String path) {
+ String pluginid = null;
+
+ if (path != null && path.length() >= PATH.length()) {
+ String stripped = path.substring(PATH.length());
+ if (stripped.indexOf("/") != -1) {
+ pluginid = stripped.substring(0, stripped.indexOf("/"));
+ }
+ }
+ return pluginid;
+ }
+
+ /**
+ * Extract plugin relative path from path
+ *
+ * @param path
+ * @return
+ */
+ private String getPluginRelativePath(final String path) {
+ String resource = path.substring(PATH.length() + getPluginId(path).length()
+ + 1);
+ return resource;
+ }
+
+ /**
+ * Process a request for resource inside plugin
+ */
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ PluginDescriptor descriptor = null;
+ String resPath = null;
+
+ String path = getContextRelativePath(request);
+ String id = getPluginId(path);
+ if (id != null) {
+ resPath = PATH.substring(1) + getPluginRelativePath(path);
+
+ descriptor = getServiceLocator().getPluginRepository()
+ .getPluginDescriptor(id);
+
+ if (descriptor != null) {
+
+ if (descriptor != null) {
+ InputStream is = descriptor.getClassLoader().getResourceAsStream(
+ resPath);
+ if (is != null) {
+ // buffer for content
+ byte[] buffer = new byte[response.getBufferSize()];
+
+ int len;
+ String contentType = getServletContext().getMimeType(path).toString();
+
+ response.setContentType(contentType);
+ while ((len = is.read(buffer)) != -1) {
+ // copy to outputStream
+ response.getOutputStream().write(buffer, 0, len);
+ }
+ is.close();
+ response.flushBuffer();
+ return;
+ }
+ }
+ }
+ }
+
+ //of no resource was found dispay error
+ response.setContentType("text/plain");
+ PrintWriter pw = response.getWriter();
+ pw.println("type:" + getServletContext().getMimeType(path));
+ pw.println("path:" + path);
+ pw.println("plugin-id:" + id);
+ pw.println("plugin:" + descriptor);
+ pw.println("plugin relative path:" + resPath);
+ return;
+ }
+}
Modified: lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/ExtendableDefinitionsFactory.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/ExtendableDefinitionsFactory.java?rev=409834&r1=409833&r2=409834&view=diff
==============================================================================
--- lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/ExtendableDefinitionsFactory.java (original)
+++ lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/tiles/ExtendableDefinitionsFactory.java Sat May 27 09:23:45 2006
@@ -92,9 +92,11 @@
protected XmlDefinitionsSet getDefinitions() {
+ System.out.println("getDefinitions()");
+
XmlDefinitionsSet definitions = new XmlDefinitionsSet();
//
- // global definitions
+ // core definitions
//
String configFiles = config.getDefinitionConfigFiles();
LOG.info("config files:" + configFiles);
@@ -103,8 +105,10 @@
LOG.info("Trying to load " + files[i]);
InputStream input = servletContext.getResourceAsStream(files[i]);
+ LOG.info("Stream: " + input);
+
if (input != null) {
- parseXMLDefinitionSet(input, definitions, files[i]);
+ parseXMLDefinitionSet(input, definitions, files[i], "nutch-core");
} else {
LOG.info("Cannot find static " + files[i]);
}
@@ -152,7 +156,7 @@
return;
}
parseXMLDefinitionSet(is, definitions, "Plugin " + extension.getId()
- + " : tiles-defs.xml");
+ + " : tiles-defs.xml", extension.getId());
try {
is.close();
} catch (Exception e) {
@@ -161,9 +165,12 @@
}
protected void parseXMLDefinitionSet(InputStream input,
- XmlDefinitionsSet definitions, String info) {
+ XmlDefinitionsSet definitions, String info, String pluginid) {
+ XmlDefinitionsSet newSet=new XmlDefinitionsSet();
+
try {
- xmlParser.parse(input, definitions);
+ xmlParser.parse(input, newSet);
+ preprocessDefinitions(newSet);
} catch (IOException e) {
LOG.info("IOException (" + e.getMessage() + ") parsing definitions "
+ info);
@@ -176,6 +183,21 @@
LOG.info("Definitions:" + definitions.getDefinitions().size() + " : "
+ definitions.toString());
+
+ copySet(definitions,newSet);
+
+ }
+
+ private void copySet(XmlDefinitionsSet definitions2, XmlDefinitionsSet newSet) {
+
+ Iterator iterator=newSet.getDefinitions().keySet().iterator();
+
+ while(iterator.hasNext()){
+ String key=(String)iterator.next();
+ System.out.println("adding: -----------> " + key);
+ XmlDefinition value=newSet.getDefinition(key);
+ definitions2.putDefinition(value);
+ }
}
/*
@@ -202,7 +224,19 @@
Thread.currentThread().setContextClassLoader(current);
this.definitions = definitions.getDefinitions();
-
+ }
+
+ private void preprocessDefinitions(XmlDefinitionsSet set){
+ Map definitions=set.getDefinitions();
+ Iterator i=definitions.keySet().iterator();
+
+ while(i.hasNext()){
+ String key=(String)i.next();
+ XmlDefinition definition=(XmlDefinition)definitions.get(key);
+ if(definition.getPath()!=null && definition.getPath().startsWith("@plugin@")){
+ definition.setPath("goooo" + definition.getPath());
+ }
+ }
}
private void initDefinitions(XmlDefinitionsSet definitions) {
@@ -218,7 +252,6 @@
e.printStackTrace(System.out);
}
}
- LOG.fine("Restoring ClassLoader.");
}
/*
@@ -245,5 +278,4 @@
public DefinitionsFactoryConfig getConfig() {
return config;
}
-
}
Added: lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestNutchHttpServlet.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestNutchHttpServlet.java?rev=409834&view=auto
==============================================================================
--- lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestNutchHttpServlet.java (added)
+++ lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestNutchHttpServlet.java Sat May 27 09:23:45 2006
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2006 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.nutch.webapp.servlet;
+
+import junit.framework.TestCase;
+
+public class TestNutchHttpServlet extends TestCase {
+
+ /*
+ * Test method for 'org.apache.nutch.webapp.servlet.NutchHttpServlet.getMappingRelativePath(String)'
+ */
+ public void testGetMappingRelativePath() {
+
+ NutchHttpServlet servlet=new NutchHttpServlet(){};
+
+ assertEquals(null,servlet.getMappingRelativePath("test.jsp"));
+ assertEquals("/kissa.jsp",servlet.getMappingRelativePath("/somepath/kissa.jsp"));
+ assertEquals("/kissa.jsp",servlet.getMappingRelativePath("somepath/kissa.jsp"));
+ }
+}
Added: lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestWebAppModule.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestWebAppModule.java?rev=409834&view=auto
==============================================================================
--- lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestWebAppModule.java (added)
+++ lucene/nutch/trunk/contrib/web2/src/main/test/org/apache/nutch/webapp/servlet/TestWebAppModule.java Sat May 27 09:23:45 2006
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006 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.nutch.webapp.servlet;
+
+import java.io.ByteArrayInputStream;
+
+import org.apache.nutch.webapp.common.WebAppModule;
+
+import junit.framework.TestCase;
+
+public class TestWebAppModule extends TestCase {
+
+ public void testWebAppModule() {
+ String webxml = "<web-app><servlet-mapping><servlet-name>a</servlet-name><url-pattern>/a.jsp</url-pattern></servlet-mapping>";
+ webxml += "<servlet-mapping><servlet-name>b</servlet-name><url-pattern>/b.jsp</url-pattern></servlet-mapping>";
+ webxml += "<servlet-mapping><servlet-name>c</servlet-name><url-pattern>/c.jsp</url-pattern></servlet-mapping></web-app>";
+
+ WebAppModule module;
+ module = new WebAppModule(new ByteArrayInputStream(webxml.getBytes()));
+ assertEquals(3, module.getPaths().size());
+
+ assertEquals("/a.jsp", module.getPaths().get(0));
+ assertEquals("/b.jsp", module.getPaths().get(1));
+ assertEquals("/c.jsp", module.getPaths().get(2));
+
+ assertEquals("a", module.getServletName("/a.jsp"));
+ assertEquals("b", module.getServletName("/b.jsp"));
+ assertEquals("c", module.getServletName("/c.jsp"));
+ }
+}
Modified: lucene/nutch/trunk/contrib/web2/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/src/main/webapp/WEB-INF/web.xml?rev=409834&r1=409833&r2=409834&view=diff
==============================================================================
--- lucene/nutch/trunk/contrib/web2/src/main/webapp/WEB-INF/web.xml (original)
+++ lucene/nutch/trunk/contrib/web2/src/main/webapp/WEB-INF/web.xml Sat May 27 09:23:45 2006
@@ -42,6 +42,18 @@
org.apache.nutch.webapp.servlet.OpenSearchServlet
</servlet-class>
</servlet>
+ <servlet>
+ <servlet-name>PluginResourceServlet</servlet-name>
+ <servlet-class>
+ org.apache.nutch.webapp.servlet.ResourceServlet
+ </servlet-class>
+ </servlet>
+ <servlet>
+ <servlet-name>PluginJSPDispatcher</servlet-name>
+ <servlet-class>
+ org.apache.nutch.webapp.servlet.JspDispatcherServlet
+ </servlet-class>
+ </servlet>
<servlet-mapping>
<servlet-name>Cached</servlet-name>
<url-pattern>/servlet/cached</url-pattern>
@@ -53,6 +65,14 @@
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>PluginJSPDispatcher</servlet-name>
+ <url-pattern>/plugin/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>PluginResourceServlet</servlet-name>
+ <url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>