Attachment 'jackrabbit-webapp-SPIServer-1.patch'

Download

   1 Index: pom.xml
   2 ===================================================================
   3 --- pom.xml	(revision 668156)
   4 +++ pom.xml	(working copy)
   5 @@ -79,6 +79,16 @@
   6        <artifactId>jackrabbit-jcr-rmi</artifactId>
   7      </dependency>
   8      <dependency>
   9 +      <groupId>org.apache.jackrabbit</groupId>
  10 +      <artifactId>jackrabbit-spi-rmi</artifactId>
  11 +      <version>1.5-SNAPSHOT</version>
  12 +    </dependency>
  13 +    <dependency>
  14 +      <groupId>org.apache.jackrabbit</groupId>
  15 +      <artifactId>jackrabbit-spi2jcr</artifactId>
  16 +      <version>1.5-SNAPSHOT</version>
  17 +    </dependency>
  18 +    <dependency>
  19        <groupId>org.slf4j</groupId>
  20        <artifactId>slf4j-log4j12</artifactId>
  21      </dependency>
  22 Index: src/main/java/org/apache/jackrabbit/j2ee/SPIServerStartupServlet.java
  23 ===================================================================
  24 --- src/main/java/org/apache/jackrabbit/j2ee/SPIServerStartupServlet.java	(revision 0)
  25 +++ src/main/java/org/apache/jackrabbit/j2ee/SPIServerStartupServlet.java	(revision 0)
  26 @@ -0,0 +1,90 @@
  27 +package org.apache.jackrabbit.j2ee;
  28 +
  29 +import java.rmi.AlreadyBoundException;
  30 +import java.rmi.RemoteException;
  31 +import java.rmi.registry.LocateRegistry;
  32 +import java.rmi.registry.Registry;
  33 +import java.util.Hashtable;
  34 +
  35 +import javax.jcr.Repository;
  36 +import javax.naming.Context;
  37 +import javax.naming.InitialContext;
  38 +import javax.naming.NamingException;
  39 +import javax.servlet.ServletContext;
  40 +import javax.servlet.ServletException;
  41 +import javax.servlet.http.HttpServlet;
  42 +
  43 +import org.apache.jackrabbit.spi.Name;
  44 +import org.apache.jackrabbit.spi.RepositoryService;
  45 +import org.apache.jackrabbit.spi.rmi.server.ServerRepositoryService;
  46 +import org.apache.jackrabbit.spi2jcr.BatchReadConfig;
  47 +import org.apache.jackrabbit.spi2jcr.RepositoryServiceImpl;
  48 +import org.slf4j.Logger;
  49 +import org.slf4j.LoggerFactory;
  50 +
  51 +public class SPIServerStartupServlet extends HttpServlet {
  52 +    /**
  53 +     * the default logger
  54 +     */
  55 +    private static final Logger log = LoggerFactory.getLogger(SPIServerStartupServlet.class);
  56 +
  57 +    private ServerRepositoryService remoteService;
  58 +    
  59 +	public void init() throws ServletException {
  60 +		super.init();
  61 +
  62 +		ServletContext servletContext = getServletContext();
  63 +		RepositoryStartupServlet repoServlet = RepositoryStartupServlet.getInstance(servletContext);
  64 +		
  65 +		BootstrapConfig bootConfig = repoServlet.getConfig();
  66 +		
  67 +        Hashtable env = new Hashtable();
  68 +        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory");
  69 +        env.put(Context.PROVIDER_URL, "http://www.apache.org/jackrabbit");
  70 +		try {
  71 +			InitialContext ctx = new InitialContext(env);
  72 +			Repository repository = (Repository) ctx.lookup("jackrabbit.repository");
  73 +			log.info("Found repository: " + repository);
  74 +			
  75 +	        RepositoryService repoService = new RepositoryServiceImpl(repository, new BatchReadConfig(){
  76 +	        	// increase the default depth for efficiency 
  77 +	        	public int getDepth(Name ntName) {
  78 +	        		int defaultDepth = super.getDepth(ntName);
  79 +	        		if(defaultDepth == DEPTH_DEFAULT){
  80 +	        			return 1;
  81 +	        		}
  82 +	        		return defaultDepth;
  83 +	        	}
  84 +	        });
  85 +	        log.info("Wrapped with SPI2JCR");
  86 +
  87 +	        // create spi server
  88 +	        remoteService = new ServerRepositoryService(repoService);
  89 +	        log.info("Wrapped with SPI-RMI");
  90 +
  91 +	        // register server
  92 +	        Registry reg = LocateRegistry.getRegistry(bootConfig.getRmiConfig().getRmiHost(), Registry.REGISTRY_PORT);
  93 +	        reg.bind("jackrabbit.spi-server", remoteService);
  94 +	        log.info("Bound to RMI Registry");
  95 +
  96 +	        String[] list = reg.list();
  97 +	        String listStr = "";
  98 +	        for (int i=0; i<list.length; i++) {
  99 +				listStr += list[i] + ", ";
 100 +			}
 101 +	        
 102 +	        log.info("Currently bound objects: " + listStr);
 103 +			
 104 +		} catch (NamingException e) {
 105 +			// TODO Auto-generated catch block
 106 +			e.printStackTrace();
 107 +		} catch (RemoteException e) {
 108 +			// TODO Auto-generated catch block
 109 +			e.printStackTrace();
 110 +		} catch (AlreadyBoundException e) {
 111 +			// TODO Auto-generated catch block
 112 +			e.printStackTrace();
 113 +		}
 114 +
 115 +	}
 116 +}
 117 

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.