Skip to content

Commit

Permalink
Refactoring of uxloader app to a point where it works. Not configurab…
Browse files Browse the repository at this point in the history
…le yet,

though. Maps /tmp/dev to /dev and /tmp/devwidgets to /devwidgets
  • Loading branch information
danatcaret committed Apr 6, 2009
1 parent 5c0d95b commit e012c84
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 199 deletions.
36 changes: 27 additions & 9 deletions slingtests/osgikernel/bundles/uxloader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,23 @@
</instructions>
</configuration>
</plugin>
<!--
<plugin> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId> <executions> <execution>
<id>embed-dependencies</id> <goals> <goal>copy-dependencies</goal> </goals> <configuration>
<includeArtifactIds>jetty; jetty-util</includeArtifactIds>
<excludeTransitive>false</excludeTransitive> <outputDirectory>
${project.build.outputDirectory} </outputDirectory> </configuration> </execution>
</executions> </plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>embed-dependencies</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>commons-io,commons-lang</includeArtifactIds>
<excludeTransitive>false</excludeTransitive>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down Expand Up @@ -84,5 +92,15 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.sakaiproject.kernel2.uxloader;

import java.io.File;
import java.util.Dictionary;
import java.util.Hashtable;

import javax.servlet.ServletException;

import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
import org.sakaiproject.kernel.api.memory.CacheManagerService;

public class ActivationProcess {
private HttpService http;
private HttpContext context;
private CacheManagerService cache;

public ActivationProcess(HttpService http,CacheManagerService cache) {
this.http=http;
this.context=http.createDefaultHttpContext();
this.cache=cache;
}

public void map(String url,String filesystem) throws ServletException, NamespaceException {
Dictionary<String, String> uxLoaderParams = new Hashtable<String, String>();
uxLoaderParams.put(FileServlet.BASE_FILE,filesystem);
uxLoaderParams.put(FileServlet.MAX_CACHE_SIZE, "102400");
uxLoaderParams.put(FileServlet.WELCOME_FILE, "index.html");
http.registerServlet(url, new FileServlet(cache),uxLoaderParams,context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,76 +33,12 @@
/**
*
*/
public class Activator implements BundleActivator {


private static final Logger logger = LoggerFactory.getLogger(Activator.class);
/**
* HttpService reference.
*/
private ServiceReference m_httpServiceRef;
private ServiceReference m_cacheManager;

/**
* Called when the OSGi framework starts our bundle
*/
@SuppressWarnings("unchecked")
public void start(BundleContext bc) throws Exception {
m_httpServiceRef = bc.getServiceReference(HttpService.class.getName());
logger.info("Locating CacheManagerService as "+CacheManagerService.class.getName());
m_cacheManager = bc.getServiceReference(CacheManagerService.class.getName());
logger.info("Service Reference is "+m_cacheManager);
CacheManagerService cacheManagerService = (CacheManagerService) bc.getService(m_cacheManager);
logger.info("Service is "+cacheManagerService);
if (m_httpServiceRef != null) {
final HttpService httpService = (HttpService) bc.getService(m_httpServiceRef);
if (httpService != null) {
// create a default context to share between registrations
final HttpContext httpContext = httpService.createDefaultHttpContext();
// register the hello world servlet
final Dictionary initParams = new Hashtable();
initParams.put("from", "HttpService");
httpService.registerServlet("/helloworld/hs", // alias
new HelloWorldServlet("/helloworld/hs"), // registered servlet
initParams, // init params
httpContext // http context
);

Dictionary uxLoaderParams = new Hashtable();
File working = new File(".");
File uxdev = new File(working, "uxdev");
String location = uxdev.getAbsolutePath();
uxLoaderParams.put(FileServlet.BASE_FILE, location);
uxLoaderParams.put(FileServlet.MAX_CACHE_SIZE, "102400");
uxLoaderParams.put(FileServlet.WELCOME_FILE, "index.html");

httpService.registerServlet("/dev", new FileServlet(cacheManagerService), uxLoaderParams,
httpContext);

Dictionary uxwidgetsLoaderParams = new Hashtable();
File uxwidgets = new File(working, "uxwidgets");
String widgetsLocation = uxwidgets.getAbsolutePath();
uxwidgetsLoaderParams.put(FileServlet.BASE_FILE, widgetsLocation);
uxwidgetsLoaderParams.put(FileServlet.MAX_CACHE_SIZE, "102400");
uxwidgetsLoaderParams.put(FileServlet.WELCOME_FILE, "index.html");

httpService.registerServlet("/devwidgets", new FileServlet(cacheManagerService), uxLoaderParams,
httpContext);

// register images as resources
httpService.registerResources("/images", "/images", httpContext);
}
}
public class Activator extends SimpleBaseActivator implements BundleActivator {
public void go(BundleContext bc) throws Exception {
HttpService http=(HttpService)getService(bc,HttpService.class);
CacheManagerService cache=(CacheManagerService)getService(bc,CacheManagerService.class);
ActivationProcess activation=new ActivationProcess(http,cache);
activation.map("/dev","/tmp/dev");
activation.map("/devwidgets","/tmp/devwidgets");
}

/**
* Called when the OSGi framework stops our bundle
*/
public void stop(BundleContext bc) throws Exception {
if (m_httpServiceRef != null) {
bc.ungetService(m_httpServiceRef);
m_httpServiceRef = null;
}
}

}
Loading

0 comments on commit e012c84

Please sign in to comment.