SRB:Servlet: Difference between revisions
From Adapt
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
The servlet provides url-based access to items in the SRB. This will allow you to access the srb as follows: | The servlet provides url-based access to items in the SRB. This will allow you to access the srb as follows: | ||
< | <nowiki>http://server.com/SrbServlet/zoneA/home/user.domain/file_or_directory</nowiki> | ||
The | The ''SrbServlet'' is the location of the servlet in your webapp and ''/zoneA/home/user.domain/file_or_directory'' is the full path to a file in the SRB. As the URL's are relatively static, it's easy to throw the servlet behind a proxy and achieve a fairly high performance srb-backed webapp. | ||
==Usage== | |||
Setup tomcat or your webapp container of choice and create a new web app. Drop the jargon.jar and adapt-srb.jar files listed below into your webapp's WEB-INF/lib directory. In the WEB-INF/web.xml for your web app, add the following lines. | Setup tomcat or your webapp container of choice and create a new web app. Drop the jargon.jar and adapt-srb.jar files listed below into your webapp's WEB-INF/lib directory. In the WEB-INF/web.xml for your web app, add the following lines. | ||
< | <pre> | ||
<servlet> | <servlet> | ||
<servlet-name>Browse</servlet-name> | <servlet-name>Browse</servlet-name> | ||
Line 49: | Line 47: | ||
<url-pattern>/Browse/*</url-pattern> | <url-pattern>/Browse/*</url-pattern> | ||
</servlet-mapping> | </servlet-mapping> | ||
</ | </pre> | ||
You will now be able to go to < | You will now be able to go to <nowiki>http://your_site.com/Browse/</nowiki> (ie http://localhost:8080/Browse) and see the same directories listed as if you would have done a 'Sls /' | ||
The webapp is composed of two parts, first is the servlet queries the srb and returns files or directory listings. The second is a factory that creates an actual connection to the srb. The factory can be switched out at any time by editing the | ==Detailed Servlet Configuration== | ||
The webapp is composed of two parts, first is the servlet queries the srb and returns files or directory listings. The second is a factory that creates an actual connection to the srb. The factory can be switched out at any time by editing the ''edu.umiacs.srb.connectionfactory'' parameter in your web.xml and specifying your own implementation of ''edu.umiacs.srb.servlet.ConnectionFactory''. | |||
Parameters to configure the servlet: | Parameters to configure the servlet: | ||
; edu.umiacs.srb.connectionfactory : full name of class that implements =edu.umiacs.srb.servlet.ConnectionFactory= | |||
; edu.umiacs.srb.fileNotFound : (Optional) Message to display if a file/directory does not exist | |||
; edu.umiacs.srb.directoryForbidden : (Optional) Message displayed if a directory listing is forbidden | |||
; edu.umiacs.srb.fileForbidden : (Optional) Message displayed if a file is forbidden | |||
; edu.umiacs.srb.mimeLookup : (Optional) true/false, if true use the mime information in the srb to determine mime type, otherwise use java's built-in functions. This may slow down retrievals | |||
;edu.umiacs.srb.showDirectories : (Optional) true/false, allow srb directory listings, return 403 if false, default true | |||
===Simple Connection Factory=== | |||
The simple connection factory uses a set of static parameters to create connections to the srb. These parameters are passed by the servlet from the init-param list above. To enable this factory, you would set the following in your web.xml | The simple connection factory uses a set of static parameters to create connections to the srb. These parameters are passed by the servlet from the init-param list above. To enable this factory, you would set the following in your web.xml | ||
< | <pre> | ||
<init-param> | <init-param> | ||
<param-name>edu.umiacs.srb.connectionfactory</param-name> | <param-name>edu.umiacs.srb.connectionfactory</param-name> | ||
<param-value>edu.umiacs.srb.servlet.SimpleConnectionFactory</param-value> | <param-value>edu.umiacs.srb.servlet.SimpleConnectionFactory</param-value> | ||
</init-param> | </init-param> | ||
</ | </pre> | ||
Parameters to configure the default factory: | Parameters to configure the default factory: | ||
; srb_mcat : SRB Mcat to connect to | |||
; srb_user : srb username to connect as | |||
; srb_pass : password for the username | |||
; srb_domain : domain of the username | |||
; srb_zone : home zone of the username | |||
; srb_path : (Optional) home directory, defaults to '/' | |||
; srb_port : (Optional) port to use on the mcat host, defaults to 5544 | |||
; srb_resource : (Optional) resource to use when uploading items, default 'null' | |||
===Session Connection Factory=== | |||
The session connection factory pulls information for configuring the srb connection out of a current session rather than statically from the servlet initialization parameters. Since the items are in the session, there is a little more qork required to configure. First there is also a login servlet in the package that will allow you to take items from an html form and set them in the users context, Second, a simple filter needs to be setup to give the factory access to the current http session. | The session connection factory pulls information for configuring the srb connection out of a current session rather than statically from the servlet initialization parameters. Since the items are in the session, there is a little more qork required to configure. First there is also a login servlet in the package that will allow you to take items from an html form and set them in the users context, Second, a simple filter needs to be setup to give the factory access to the current http session. | ||
First, add the following to your web.xml. This will configure the filter and register the | First, add the following to your web.xml. This will configure the filter and register the SrbLoginServlet. You can use your own login method to fill out the session. The session connection factory just looks for the srb configuration items listed above in the session. | ||
< | <pre> | ||
<!-- Filter to bridge a clients session to the factory --> | <!-- Filter to bridge a clients session to the factory --> | ||
<filter> | <filter> | ||
Line 137: | Line 135: | ||
<url-pattern>/Browse2/*</url-pattern> | <url-pattern>/Browse2/*</url-pattern> | ||
</servlet-mapping> | </servlet-mapping> | ||
</ | </pre> | ||
Second, If you're using the login servlet, you will need to create a simple login page. The following shows a sample jsp file that will ask for a username/password and redirect users to the browse servlet if they are successfully in logging in. A sample login page is shown below | |||
<pre> | |||
<%@page contentType="text/html"%> | |||
<%@page pageEncoding="UTF-8"%> | |||
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> | |||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | |||
"http://www.w3.org/TR/html4/loose.dtd"> | |||
<html> | |||
<head> | |||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |||
<title>JSP Page</title> | |||
</head> | |||
<body> | |||
<h1>Sample SRB Login Page</h1> | |||
<form action="SrbLoginServlet" method="post"> | |||
<table> | |||
<tr><td>Mcat </td><td><input type="text" value="${srb_mcat}" name="srb_mcat"></td></tr> | |||
<tr><td>User </td><td><input type="text" size="10" value="${srb_user}" name="srb_user"> </td></tr> | |||
<tr><td>Pass </td><td><input type="password" size="10" value="${srb_pass}" name="srb_pass"> </td></tr> | |||
<tr><td>Domain </td><td><input type="text" size="10" value="${srb_domain}" name="srb_domain"> </td></tr> | |||
<tr><td>Zone </td><td><input type="text" size="10" value="${srb_zone}" name="srb_zone"> </td></tr> | |||
<tr><td>Port </td><td><input type="text" size="10" value="${srb_port}" name="srb_port"> </td></tr> | |||
<!-- | |||
<tr><td>Home </td><td> </td></tr> | |||
<tr><td>Resource </td><td> </td></tr> | |||
--> | |||
<tr><td colspan="2"><input type="submit" name="Login"></td></tr> | |||
</table> | |||
</form> | |||
</body> | |||
</html> | |||
</pre> |
Latest revision as of 20:28, 10 September 2008
The servlet provides url-based access to items in the SRB. This will allow you to access the srb as follows:
http://server.com/SrbServlet/zoneA/home/user.domain/file_or_directory
The SrbServlet is the location of the servlet in your webapp and /zoneA/home/user.domain/file_or_directory is the full path to a file in the SRB. As the URL's are relatively static, it's easy to throw the servlet behind a proxy and achieve a fairly high performance srb-backed webapp.
Usage
Setup tomcat or your webapp container of choice and create a new web app. Drop the jargon.jar and adapt-srb.jar files listed below into your webapp's WEB-INF/lib directory. In the WEB-INF/web.xml for your web app, add the following lines.
<servlet> <servlet-name>Browse</servlet-name> <servlet-class>edu.umiacs.srb.servlet.Browse</servlet-class> <init-param> <param-name>edu.umiacs.srb.connectionfactory</param-name> <param-value>edu.umiacs.srb.servlet.SimpleConnectionFactory</param-value> </init-param> <init-param> <param-name>srb_user</param-name> <param-value>username</param-value> </init-param> <init-param> <param-name>srb_mcat</param-name> <param-value>mcat.host.com</param-value> </init-param> <!-- srb.port is optional --> <init-param> <param-name>srb_port</param-name> <param-value>7618</param-value> </init-param> <init-param> <param-name>srb_pass</param-name> <param-value>password</param-value> </init-param> <init-param> <param-name>srb_zone</param-name> <param-value>zoneA</param-value> </init-param> <init-param> <param-name>srb_domain</param-name> <param-value>domain</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>Browse</servlet-name> <url-pattern>/Browse/*</url-pattern> </servlet-mapping>
You will now be able to go to http://your_site.com/Browse/ (ie http://localhost:8080/Browse) and see the same directories listed as if you would have done a 'Sls /'
Detailed Servlet Configuration
The webapp is composed of two parts, first is the servlet queries the srb and returns files or directory listings. The second is a factory that creates an actual connection to the srb. The factory can be switched out at any time by editing the edu.umiacs.srb.connectionfactory parameter in your web.xml and specifying your own implementation of edu.umiacs.srb.servlet.ConnectionFactory.
Parameters to configure the servlet:
- edu.umiacs.srb.connectionfactory
- full name of class that implements =edu.umiacs.srb.servlet.ConnectionFactory=
- edu.umiacs.srb.fileNotFound
- (Optional) Message to display if a file/directory does not exist
- edu.umiacs.srb.directoryForbidden
- (Optional) Message displayed if a directory listing is forbidden
- edu.umiacs.srb.fileForbidden
- (Optional) Message displayed if a file is forbidden
- edu.umiacs.srb.mimeLookup
- (Optional) true/false, if true use the mime information in the srb to determine mime type, otherwise use java's built-in functions. This may slow down retrievals
- edu.umiacs.srb.showDirectories
- (Optional) true/false, allow srb directory listings, return 403 if false, default true
Simple Connection Factory
The simple connection factory uses a set of static parameters to create connections to the srb. These parameters are passed by the servlet from the init-param list above. To enable this factory, you would set the following in your web.xml
<init-param> <param-name>edu.umiacs.srb.connectionfactory</param-name> <param-value>edu.umiacs.srb.servlet.SimpleConnectionFactory</param-value> </init-param>
Parameters to configure the default factory:
- srb_mcat
- SRB Mcat to connect to
- srb_user
- srb username to connect as
- srb_pass
- password for the username
- srb_domain
- domain of the username
- srb_zone
- home zone of the username
- srb_path
- (Optional) home directory, defaults to '/'
- srb_port
- (Optional) port to use on the mcat host, defaults to 5544
- srb_resource
- (Optional) resource to use when uploading items, default 'null'
Session Connection Factory
The session connection factory pulls information for configuring the srb connection out of a current session rather than statically from the servlet initialization parameters. Since the items are in the session, there is a little more qork required to configure. First there is also a login servlet in the package that will allow you to take items from an html form and set them in the users context, Second, a simple filter needs to be setup to give the factory access to the current http session.
First, add the following to your web.xml. This will configure the filter and register the SrbLoginServlet. You can use your own login method to fill out the session. The session connection factory just looks for the srb configuration items listed above in the session.
<!-- Filter to bridge a clients session to the factory --> <filter> <filter-name>SessionFilter</filter-name> <filter-class>edu.umiacs.srb.servlet.ThreadLocalSessionFilter</filter-class> </filter> <filter-mapping> <filter-name>SessionFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- Configure the login servlet --> <servlet> <servlet-name>SrbLoginServlet</servlet-name> <servlet-class>edu.umiacs.srb.servlet.SrbLoginServlet</servlet-class> <!-- This determines where successfully logged in clients get redirected to --> <init-param> <param-name>edu.umiacs.srb.successPage</param-name> <param-value>Browse2</param-value> </init-param> <!-- This determines where failes clientc get redirected to --> <init-param> <param-name>edu.umiacs.srb.failurePage</param-name> <param-value>login.jsp</param-value> </init-param> </servlet> <!-- Configure browse servlet with the SessionConnectionFactory --> <servlet> <servlet-name>Browse2</servlet-name> <servlet-class>edu.umiacs.srb.servlet.Browse</servlet-class> <init-param> <param-name>edu.umiacs.srb.connectionfactory</param-name> <param-value>edu.umiacs.srb.servlet.SessionConnectionFactory</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>SrbLoginServlet</servlet-name> <url-pattern>/SrbLoginServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Browse2</servlet-name> <url-pattern>/Browse2/*</url-pattern> </servlet-mapping>
Second, If you're using the login servlet, you will need to create a simple login page. The following shows a sample jsp file that will ask for a username/password and redirect users to the browse servlet if they are successfully in logging in. A sample login page is shown below
<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Sample SRB Login Page</h1> <form action="SrbLoginServlet" method="post"> <table> <tr><td>Mcat </td><td><input type="text" value="${srb_mcat}" name="srb_mcat"></td></tr> <tr><td>User </td><td><input type="text" size="10" value="${srb_user}" name="srb_user"> </td></tr> <tr><td>Pass </td><td><input type="password" size="10" value="${srb_pass}" name="srb_pass"> </td></tr> <tr><td>Domain </td><td><input type="text" size="10" value="${srb_domain}" name="srb_domain"> </td></tr> <tr><td>Zone </td><td><input type="text" size="10" value="${srb_zone}" name="srb_zone"> </td></tr> <tr><td>Port </td><td><input type="text" size="10" value="${srb_port}" name="srb_port"> </td></tr> <!-- <tr><td>Home </td><td> </td></tr> <tr><td>Resource </td><td> </td></tr> --> <tr><td colspan="2"><input type="submit" name="Login"></td></tr> </table> </form> </body> </html>