[Osgi-messages] SF.net SVN: osgi:[265] papoose-cmpn/trunk
Status: Beta
Brought to you by:
maguro
|
From: <osg...@li...> - 2010-03-06 18:50:44
|
Revision: 265
http://osgi.svn.sourceforge.net/osgi/?rev=265&view=rev
Author: maguro
Date: 2010-03-06 18:50:37 +0000 (Sat, 06 Mar 2010)
Log Message:
-----------
Some more tests
Modified Paths:
--------------
papoose-cmpn/trunk/http/pom.xml
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java
papoose-cmpn/trunk/pom.xml
papoose-cmpn/trunk/tck/tests/pom.xml
papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java
Added Paths:
-----------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServer.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/JettyHttpServer.java
papoose-cmpn/trunk/http/src/test/java/org/papoose/http/JettyHttpServerTest.java
papoose-cmpn/trunk/http/src/test/resources/car/
papoose-cmpn/trunk/http/src/test/resources/car/c
Modified: papoose-cmpn/trunk/http/pom.xml
===================================================================
--- papoose-cmpn/trunk/http/pom.xml 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/http/pom.xml 2010-03-06 18:50:37 UTC (rev 265)
@@ -23,7 +23,7 @@
<instructions>
<Bundle-SymbolicName>org.papoose.cmpn.event</Bundle-SymbolicName>
<Export-Package>org.papoose.http</Export-Package>
- <Import-Package>org.papoose.core;resolution:=optional,javax.servlet;version="[2.4,3)",javax.servlet.http;version="[2.4,3)",org.osgi.framework;version="[1,2)",org.osgi.service.http;version="[1.2,2)"</Import-Package>
+ <Import-Package>org.mortbay.jetty;version="[6.1,6.2)",org.mortbay.jetty.nio;version="[6.1,6.2)",org.mortbay.jetty.security;version="[6.1,6.2)",org.mortbay.jetty.servlet;version="[6.1,6.2)",org.mortbay.thread;version="[6.1,6.2)",org.papoose.core;resolution:=optional,javax.servlet;version="[2.4,3)",javax.servlet.http;version="[2.4,3)",org.osgi.framework;version="[1,2)",org.osgi.service.http;version="[1.2,2)"</Import-Package>
<Private-Package>org.papoose.http.util</Private-Package>
</instructions>
</configuration>
@@ -46,6 +46,13 @@
</dependency>
<dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>${jettyVersion}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServer.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServer.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServer.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -0,0 +1,38 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * 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.papoose.http;
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public interface HttpServer
+{
+ public final static String HTTP_MAX_THREAD_SIZE = "org.osgi.service.http.pool.size";
+ public final static String HTTP_PORT = "org.osgi.service.http.port";
+ public final static String HTTP_PORT_SECURE = "org.osgi.service.http.port.secure";
+ public final static String HTTP_KEYSTORE = "org.papoose.service.http.keystore";
+ public final static String HTTP_KEYSTORE_PASSWORD = "org.papoose.service.http.keystore.password";
+ public final static String HTTP_TRUSTSTORE = "org.papoose.service.http.truststore";
+ public final static String HTTP_TRUSTSTORE_PASSWORD = "org.papoose.service.http.truststore.password";
+ public final static String HTTP_SERVER_PASSWORD = "org.papoose.service.http.server.password";
+
+ ServletDispatcher getServletDispatcher();
+
+ void start();
+
+ void stop();
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/JettyHttpServer.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/JettyHttpServer.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/JettyHttpServer.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -0,0 +1,135 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * 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.papoose.http;
+
+import java.util.Properties;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.security.SslSocketConnector;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.thread.QueuedThreadPool;
+
+import org.papoose.http.util.Util;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class JettyHttpServer implements HttpServer
+{
+ private final static String CLASS_NAME = JettyHttpServer.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final Server server = new Server();
+ private final ServletDispatcher servletDispatcher = new ServletDispatcher();
+
+ public ServletDispatcher getServletDispatcher()
+ {
+ return servletDispatcher;
+ }
+
+ public void start()
+ {
+ LOGGER.entering(CLASS_NAME, "start");
+
+ try
+ {
+ server.start();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error starting container", e);
+ }
+
+ LOGGER.exiting(CLASS_NAME, "start");
+ }
+
+ public void stop()
+ {
+ LOGGER.entering(CLASS_NAME, "stop");
+
+ try
+ {
+ server.stop();
+ }
+ catch (Exception e)
+ {
+ LOGGER.log(Level.WARNING, "Error stopping container", e);
+ }
+
+ LOGGER.exiting(CLASS_NAME, "stop");
+ }
+
+ public static HttpServer generate(Properties properties)
+ {
+ LOGGER.entering(CLASS_NAME, "generate", properties);
+
+ JettyHttpServer server = new JettyHttpServer(properties);
+
+ LOGGER.exiting(CLASS_NAME, "generate", server);
+
+ return server;
+ }
+
+ private JettyHttpServer(Properties properties)
+ {
+ int maxThreads = Util.parseInt(properties.getProperty(HTTP_MAX_THREAD_SIZE), 5);
+
+ if (LOGGER.isLoggable(Level.CONFIG)) LOGGER.config("Max threads: " + maxThreads);
+
+ server.setThreadPool(new QueuedThreadPool(maxThreads));
+
+ Context root = new Context(server, "/", Context.SESSIONS);
+
+ root.addServlet(new ServletHolder(servletDispatcher), "/*");
+
+ int port = Util.parseInt(properties.getProperty(HTTP_PORT), -1);
+ int securePort = Util.parseInt(properties.getProperty(HTTP_PORT_SECURE), -1);
+
+ if (port != -1)
+ {
+ if (LOGGER.isLoggable(Level.CONFIG)) LOGGER.config("port: " + port);
+
+ SelectChannelConnector connector = new SelectChannelConnector();
+
+ connector.setPort(port);
+
+ server.addConnector(connector);
+ }
+
+ if (securePort != -1)
+ {
+ if (LOGGER.isLoggable(Level.CONFIG)) LOGGER.config("securePort: " + securePort);
+
+ SslSocketConnector sslConnector = new SslSocketConnector();
+
+ if (properties.containsKey(HTTP_KEYSTORE)) sslConnector.setKeystore(properties.getProperty(HTTP_KEYSTORE));
+ if (properties.containsKey(HTTP_TRUSTSTORE)) sslConnector.setTruststore(properties.getProperty(HTTP_TRUSTSTORE));
+ if (properties.containsKey(HTTP_KEYSTORE_PASSWORD)) sslConnector.setPassword(properties.getProperty(HTTP_KEYSTORE_PASSWORD));
+ if (properties.containsKey(HTTP_TRUSTSTORE_PASSWORD)) sslConnector.setTrustPassword(properties.getProperty(HTTP_TRUSTSTORE_PASSWORD));
+ if (properties.containsKey(HTTP_SERVER_PASSWORD)) sslConnector.setKeyPassword(properties.getProperty(HTTP_SERVER_PASSWORD));
+
+ sslConnector.setMaxIdleTime(30000);
+ sslConnector.setPort(securePort);
+
+ server.addConnector(sslConnector);
+ }
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/JettyHttpServer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/PapooseBootLevelService.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -16,8 +16,12 @@
*/
package org.papoose.http;
+import java.util.logging.Level;
import java.util.logging.Logger;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.http.HttpService;
+
import org.papoose.core.Papoose;
@@ -28,16 +32,51 @@
{
private final static String CLASS_NAME = PapooseBootLevelService.class.getName();
private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private volatile HttpServer server;
+ private volatile HttpServiceImpl httpService;
public void start(Papoose papoose)
{
LOGGER.entering(CLASS_NAME, "start", papoose);
+
+ if (papoose == null) throw new IllegalArgumentException("Papoose instance is null");
+
+ if (server != null)
+ {
+ LOGGER.log(Level.WARNING, "Http service already started");
+ return;
+ }
+
+ LOGGER.finest("Provisioning Jetty server");
+ server = JettyHttpServer.generate(papoose.getProperties());
+
+ server.start();
+
+ BundleContext bundleContext = papoose.getSystemBundleContext();
+
+ httpService = new HttpServiceImpl(bundleContext, server.getServletDispatcher());
+
+ httpService.start();
+ bundleContext.registerService(HttpService.class.getName(), httpService, null);
+
LOGGER.exiting(CLASS_NAME, "start");
}
public void stop()
{
LOGGER.entering(CLASS_NAME, "stop");
+
+ if (server == null)
+ {
+ LOGGER.log(Level.WARNING, "Http service already stopped");
+ return;
+ }
+
+ httpService.stop();
+ httpService = null;
+ server.stop();
+ server = null;
+
LOGGER.exiting(CLASS_NAME, "stop");
}
}
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceServletWrapper.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -104,7 +104,7 @@
if (exception instanceof ServletException) throw (ServletException) exception;
if (exception instanceof IOException) throw (IOException) exception;
- resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
catch (IOException ioe)
{
@@ -112,7 +112,8 @@
}
catch (Exception e)
{
- resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ System.err.println(e);
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
LOGGER.exiting(CLASS_NAME, "service");
@@ -131,7 +132,7 @@
if (lastModified == 0 || modifiedSince == -1 || lastModified > modifiedSince)
{
resp.setContentLength(copyResource(conn.getInputStream(), resp.getOutputStream()));
- resp.setStatus(HttpServletResponse.SC_FOUND);
+ resp.setStatus(HttpServletResponse.SC_OK);
}
else
{
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -69,7 +69,7 @@
catch (Throwable t)
{
LOGGER.log(Level.WARNING, "Problems calling ", t);
- resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
}
@@ -86,7 +86,7 @@
path = path.substring(0, index);
}
- resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ resp.sendError(HttpServletResponse.SC_NOT_FOUND);
}
void register(ServletRegistration registration)
Added: papoose-cmpn/trunk/http/src/test/java/org/papoose/http/JettyHttpServerTest.java
===================================================================
--- papoose-cmpn/trunk/http/src/test/java/org/papoose/http/JettyHttpServerTest.java (rev 0)
+++ papoose-cmpn/trunk/http/src/test/java/org/papoose/http/JettyHttpServerTest.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -0,0 +1,44 @@
+/**
+ *
+ * Copyright 2010 (C) The original author or authors
+ *
+ * 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.papoose.http;
+
+import java.util.Properties;
+
+import org.junit.Test;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class JettyHttpServerTest
+{
+ @Test
+ public void test() throws Exception
+ {
+ Properties properties = new Properties();
+
+ properties.setProperty(HttpServer.HTTP_PORT, "8080");
+
+ HttpServer server = JettyHttpServer.generate(properties);
+
+ server.start();
+
+ Thread.sleep(1 * 1000);
+
+ server.stop();
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/test/java/org/papoose/http/JettyHttpServerTest.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java
===================================================================
--- papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/http/src/test/java/org/papoose/http/ServletDispatcherTest.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -51,7 +51,7 @@
dispatcher.service(request, response);
- verify(response, only()).setStatus(HttpServletResponse.SC_NOT_FOUND);
+ verify(response, only()).sendError(HttpServletResponse.SC_NOT_FOUND);
}
@Test
@@ -158,7 +158,7 @@
dispatcher.service(request, response);
verify(context, only()).handleSecurity(request, response);
- verify(response, only()).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ verify(response, only()).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
@Test
@@ -186,7 +186,7 @@
}
verify(context, only()).handleSecurity(request, response);
- verify(response, never()).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ verify(response, never()).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
@Test
@@ -215,7 +215,7 @@
dispatcher.service(request, response);
verify(context, never()).handleSecurity(request, response);
- verify(response, only()).setStatus(HttpServletResponse.SC_NOT_FOUND);
+ verify(response, only()).sendError(HttpServletResponse.SC_NOT_FOUND);
}
@Test
@@ -244,6 +244,6 @@
dispatcher.service(request, response);
verify(context, never()).handleSecurity(request, response);
- verify(response, only()).setStatus(HttpServletResponse.SC_NOT_FOUND);
+ verify(response, only()).sendError(HttpServletResponse.SC_NOT_FOUND);
}
}
Added: papoose-cmpn/trunk/http/src/test/resources/car/c
===================================================================
--- papoose-cmpn/trunk/http/src/test/resources/car/c (rev 0)
+++ papoose-cmpn/trunk/http/src/test/resources/car/c 2010-03-06 18:50:37 UTC (rev 265)
@@ -0,0 +1 @@
+HOW NOW BROWN COW
Property changes on: papoose-cmpn/trunk/http/src/test/resources/car/c
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/pom.xml
===================================================================
--- papoose-cmpn/trunk/pom.xml 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/pom.xml 2010-03-06 18:50:37 UTC (rev 265)
@@ -25,6 +25,7 @@
</modules>
<properties>
+ <jettyVersion>6.1.19</jettyVersion>
<paxExamVersion>1.2.0</paxExamVersion>
<papooseTestVersion>1.0-SNAPSHOT</papooseTestVersion>
</properties>
@@ -77,7 +78,7 @@
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>com.springsource.javax.servlet</artifactId>
- <version>2.4.0</version>
+ <version>2.5.0</version>
</dependency>
<dependency>
Modified: papoose-cmpn/trunk/tck/tests/pom.xml
===================================================================
--- papoose-cmpn/trunk/tck/tests/pom.xml 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/tck/tests/pom.xml 2010-03-06 18:50:37 UTC (rev 265)
@@ -43,6 +43,20 @@
</dependency>
<dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>${jettyVersion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>${jettyVersion}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
<scope>test</scope>
Modified: papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java
===================================================================
--- papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java 2010-03-04 18:28:49 UTC (rev 264)
+++ papoose-cmpn/trunk/tck/tests/src/test/java/org/papoose/tck/http/HttpServiceImplTest.java 2010-03-06 18:50:37 UTC (rev 265)
@@ -16,16 +16,21 @@
*/
package org.papoose.tck.http;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
import org.junit.Assert;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.ops4j.pax.exam.CoreOptions.equinox;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.knopflerfish;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.provision;
@@ -37,10 +42,13 @@
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
+import org.papoose.http.HttpServer;
import org.papoose.http.HttpServiceImpl;
+import org.papoose.http.JettyHttpServer;
import org.papoose.http.ServletDispatcher;
@@ -58,8 +66,8 @@
{
return options(
equinox(),
- // felix(),
- // knopflerfish(),
+ felix(),
+ knopflerfish(),
// papoose(),
compendiumProfile(),
// vmOption("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
@@ -70,16 +78,16 @@
// waitForFrameworkStartup()
provision(
mavenBundle().groupId("javax.servlet").artifactId("com.springsource.javax.servlet").version(asInProject()),
+ mavenBundle().groupId("org.mortbay.jetty").artifactId("jetty").version(asInProject()),
+ mavenBundle().groupId("org.mortbay.jetty").artifactId("jetty-util").version(asInProject()),
mavenBundle().groupId("org.papoose.cmpn").artifactId("papoose-cmpn-http").version(asInProject())
)
);
}
- @Test
- public void test() throws Exception
+ public void testRegistrations() throws Exception
{
Assert.assertNotNull(bundleContext);
- ExecutorService executor = new ThreadPoolExecutor(1, 5, 100, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
ServletDispatcher dispatcher = new ServletDispatcher();
HttpServiceImpl httpService = new HttpServiceImpl(bundleContext, dispatcher);
@@ -107,7 +115,127 @@
finally
{
httpService.stop();
- executor.shutdown();
}
}
-}
\ No newline at end of file
+
+ public void testResourceAbsolute() throws Exception
+ {
+ Assert.assertNotNull(bundleContext);
+
+ Properties properties = new Properties();
+
+ properties.setProperty(HttpServer.HTTP_PORT, "8080");
+
+ HttpServer server = JettyHttpServer.generate(properties);
+
+ server.start();
+
+ HttpServiceImpl httpService = new HttpServiceImpl(bundleContext, server.getServletDispatcher());
+
+ httpService.start();
+ bundleContext.registerService(HttpService.class.getName(), httpService, null);
+
+ try
+ {
+ ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
+ HttpService service = (HttpService) bundleContext.getService(sr);
+
+ service.registerResources("/a/b", "/org/papoose/tck", new HttpContext()
+ {
+ public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException
+ {
+ return true;
+ }
+
+ public URL getResource(String name)
+ {
+ return HttpServiceImplTest.class.getResource(name);
+ }
+
+ public String getMimeType(String name)
+ {
+ return null;
+ }
+ });
+
+ URL url = new URL("http://localhost:8080/a/b/http/HttpServiceImplTest.class");
+
+ DataInputStream reader = new DataInputStream(url.openStream());
+
+ assertEquals((byte) 0xca, reader.readByte());
+ assertEquals((byte) 0xfe, reader.readByte());
+
+ assertEquals((byte) 0xba, reader.readByte());
+ assertEquals((byte) 0xbe, reader.readByte());
+
+ service.unregister("/a/b");
+ }
+ finally
+ {
+ httpService.stop();
+ server.stop();
+ }
+ }
+
+ @Test
+ public void testResourceRelative() throws Exception
+ {
+ Assert.assertNotNull(bundleContext);
+
+ Properties properties = new Properties();
+
+ properties.setProperty(HttpServer.HTTP_PORT, "8080");
+
+ HttpServer server = JettyHttpServer.generate(properties);
+
+ server.start();
+
+ HttpServiceImpl httpService = new HttpServiceImpl(bundleContext, server.getServletDispatcher());
+
+ httpService.start();
+ bundleContext.registerService(HttpService.class.getName(), httpService, null);
+
+ try
+ {
+ ServiceReference sr = bundleContext.getServiceReference(HttpService.class.getName());
+ HttpService service = (HttpService) bundleContext.getService(sr);
+
+ service.registerResources("/a/b", ".", new HttpContext()
+ {
+ public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException
+ {
+ return true;
+ }
+
+ public URL getResource(String name)
+ {
+ name = name.replaceAll("^\\./", "");
+ name = name.replaceAll("/\\./", "/");
+ return HttpServiceImplTest.class.getResource(name);
+ }
+
+ public String getMimeType(String name)
+ {
+ return null;
+ }
+ });
+
+ URL url = new URL("http://localhost:8080/a/b/HttpServiceImplTest.class");
+
+ DataInputStream reader = new DataInputStream(url.openStream());
+
+ assertEquals((byte) 0xca, reader.readByte());
+ assertEquals((byte) 0xfe, reader.readByte());
+
+ assertEquals((byte) 0xba, reader.readByte());
+ assertEquals((byte) 0xbe, reader.readByte());
+
+ service.unregister("/a/b");
+ }
+ finally
+ {
+ httpService.stop();
+ server.stop();
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|