[Osgi-messages] SF.net SVN: osgi:[249] papoose-cmpn/trunk
Status: Beta
Brought to you by:
maguro
|
From: <osg...@li...> - 2010-02-23 19:46:00
|
Revision: 249
http://osgi.svn.sourceforge.net/osgi/?rev=249&view=rev
Author: maguro
Date: 2010-02-23 19:45:40 +0000 (Tue, 23 Feb 2010)
Log Message:
-----------
Starting sketch of http
Modified Paths:
--------------
papoose-cmpn/trunk/http/pom.xml
papoose-cmpn/trunk/pom.xml
Added Paths:
-----------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/util/
Modified: papoose-cmpn/trunk/http/pom.xml
===================================================================
--- papoose-cmpn/trunk/http/pom.xml 2010-02-21 20:17:14 UTC (rev 248)
+++ papoose-cmpn/trunk/http/pom.xml 2010-02-23 19:45:40 UTC (rev 249)
@@ -9,17 +9,23 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>papoose-cmpn-http</artifactId>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<name>Papoose :: HTTP Service</name>
<description>HTTP Service</description>
<build>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
<configuration>
- <argLine>-enableassertions</argLine>
+ <instructions>
+ <Bundle-SymbolicName>org.papoose.cmpn.event</Bundle-SymbolicName>
+ <Export-Package>org.papoose.event</Export-Package>
+ <Import-Package>org.osgi.framework;version="[1.0,1.6)",org.osgi.service.event;version="[1.1,1.3)",org.osgi.service.log;version="[1.1,1.4)",org.osgi.util.tracker;version="[1.3,1.5)"</Import-Package>
+ <Private-Package>org.papoose.event.util</Private-Package>
+ </instructions>
</configuration>
</plugin>
</plugins>
@@ -28,6 +34,13 @@
<dependencies>
<dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</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/FilterImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java 2010-02-23 19:45:40 UTC (rev 249)
@@ -0,0 +1,51 @@
+/**
+ *
+ * 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 javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.io.IOException;
+import java.util.logging.Logger;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class FilterImpl implements Filter
+{
+ private final static String CLASS_NAME = FilterImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+
+ public void init(FilterConfig filterConfig) throws ServletException
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void destroy()
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/FilterImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java 2010-02-23 19:45:40 UTC (rev 249)
@@ -0,0 +1,81 @@
+/**
+ *
+ * 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 javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class HttpServiceImpl implements HttpService
+{
+ private final static String CLASS_NAME = HttpServiceImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final Map<HttpContext, ServletContextImpl> contexts = new HashMap<HttpContext, ServletContextImpl>();
+ private final Map<String, ServletRegistration> registrations = new HashMap<String, ServletRegistration>();
+
+ public void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext httpContext) throws ServletException, NamespaceException
+ {
+ if (registrations.containsKey(alias)) throw new NamespaceException("Alias " + alias + " already registered");
+ if (httpContext == null) httpContext = createDefaultHttpContext();
+ ServletRegistration registration = new ServletRegistration(alias, servlet, initparams, httpContext);
+ registrations.put(alias, registration);
+
+ ServletContextImpl servletContext = contexts.get(httpContext);
+ if (servletContext == null) contexts.put(httpContext, servletContext = new ServletContextImpl(httpContext));
+ servletContext.incrementReferenceCount();
+
+ servlet.init(new ServletConfigImpl(alias, servletContext, initparams));
+
+
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void registerResources(String alias, String name, HttpContext context) throws NamespaceException
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void unregister(String alias)
+ {
+ ServletRegistration registration = registrations.get(alias);
+
+ registration.getServlet().destroy();
+ ServletContextImpl servletContext = contexts.get(registration.getContext());
+
+ servletContext.decrementReferenceCount();
+ if (servletContext.getReferenceCount() == 0) contexts.remove(registration.getContext());
+
+
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public HttpContext createDefaultHttpContext()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/HttpServiceImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java 2010-02-23 19:45:40 UTC (rev 249)
@@ -0,0 +1,61 @@
+/**
+ *
+ * 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 javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.logging.Logger;
+
+import org.osgi.service.http.HttpContext;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ServletConfigImpl implements ServletConfig
+{
+ private final static String CLASS_NAME = ServletConfigImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+
+ public ServletConfigImpl(String alias, ServletContextImpl servletContext, Dictionary httpContext)
+ {
+
+
+ }
+
+ public String getServletName()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public ServletContext getServletContext()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getInitParameter(String name)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Enumeration getInitParameterNames()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletConfigImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java 2010-02-23 19:45:40 UTC (rev 249)
@@ -0,0 +1,187 @@
+/**
+ *
+ * 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 javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import org.osgi.service.http.HttpContext;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ServletContextImpl implements ServletContext
+{
+ private final static String CLASS_NAME = ServletContextImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final HttpContext httpContext;
+ private int referenceCount;
+
+ public ServletContextImpl(HttpContext httpContext)
+ {
+ this.httpContext = httpContext;
+ }
+
+ public int getReferenceCount()
+ {
+ return referenceCount;
+ }
+
+ public void incrementReferenceCount()
+ {
+ referenceCount--;
+ }
+
+ public void decrementReferenceCount()
+ {
+ referenceCount++;
+ }
+
+ public String getContextPath()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public ServletContext getContext(String uripath)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public int getMajorVersion()
+ {
+ return 0; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public int getMinorVersion()
+ {
+ return 0; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getMimeType(String file)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Set getResourcePaths(String path)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public URL getResource(String path) throws MalformedURLException
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public InputStream getResourceAsStream(String path)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public RequestDispatcher getRequestDispatcher(String path)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public RequestDispatcher getNamedDispatcher(String name)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Servlet getServlet(String name) throws ServletException
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Enumeration getServlets()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Enumeration getServletNames()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void log(String msg)
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void log(Exception exception, String msg)
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void log(String message, Throwable throwable)
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getRealPath(String path)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getServerInfo()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getInitParameter(String name)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Enumeration getInitParameterNames()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Object getAttribute(String name)
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Enumeration getAttributeNames()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setAttribute(String name, Object object)
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removeAttribute(String name)
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getServletContextName()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletContextImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-23 19:45:40 UTC (rev 249)
@@ -0,0 +1,80 @@
+/**
+ *
+ * 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 javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ServletDispatcher extends HttpServlet
+{
+ private final static String CLASS_NAME = ServletDispatcher.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final List<ServletRegistration> registrations = new CopyOnWriteArrayList<ServletRegistration>();
+
+ @Override
+ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ {
+ String path = req.getPathInfo();
+
+ for (ServletRegistration registration : registrations)
+ {
+ if (path.startsWith(registration.getAlias()))
+ {
+ if (registration.getContext().handleSecurity(req, resp))
+ {
+ try
+ {
+ registration.getServlet().service(req, resp);
+ }
+ catch (ServletException e)
+ {
+ throw e;
+ }
+ catch (IOException e)
+ {
+ throw e;
+ }
+ catch(Throwable t)
+ {
+ LOGGER.log(Level.WARNING, "Problems calling ", t);
+ }
+ }
+ }
+ }
+ }
+
+ void register(ServletRegistration registration)
+ {
+
+ }
+
+ void unregister(ServletRegistration registration)
+ {
+
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java 2010-02-23 19:45:40 UTC (rev 249)
@@ -0,0 +1,65 @@
+/**
+ *
+ * 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 javax.servlet.Servlet;
+import java.util.Dictionary;
+import java.util.logging.Logger;
+
+import org.osgi.service.http.HttpContext;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ServletRegistration
+{
+ private final static String CLASS_NAME = ServletRegistration.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+ private final String alias;
+ private final Servlet servlet;
+ private final Dictionary initparams;
+ private final HttpContext context;
+
+ public ServletRegistration(String alias, Servlet servlet, Dictionary initparams, HttpContext context)
+ {
+ this.alias = alias;
+ this.servlet = servlet;
+ this.initparams = initparams;
+ this.context = context;
+ }
+
+ public HttpContext getContext()
+ {
+ return context;
+ }
+
+ public String getAlias()
+ {
+ return alias;
+ }
+
+ public Servlet getServlet()
+ {
+ return servlet;
+ }
+
+ public Dictionary getInitparams()
+ {
+ return initparams;
+ }
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletRegistration.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Modified: papoose-cmpn/trunk/pom.xml
===================================================================
--- papoose-cmpn/trunk/pom.xml 2010-02-21 20:17:14 UTC (rev 248)
+++ papoose-cmpn/trunk/pom.xml 2010-02-23 19:45:40 UTC (rev 249)
@@ -25,7 +25,6 @@
</modules>
<properties>
- <jettyVersion>6.1.9</jettyVersion>
<paxExamVersion>1.2.0</paxExamVersion>
<papooseTestVersion>1.0-SNAPSHOT</papooseTestVersion>
</properties>
@@ -35,12 +34,6 @@
<pluginManagement>
<plugins>
<plugin>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>maven-jetty-plugin</artifactId>
- <version>${jettyVersion}</version>
- </plugin>
-
- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
@@ -89,12 +82,6 @@
</dependency>
<dependency>
- <groupId>org.mortbay.jetty</groupId>
- <artifactId>jetty-embedded</artifactId>
- <version>${jettyVersion}</version>
- </dependency>
-
- <dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam</artifactId>
<version>${paxExamVersion}</version>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|