[Osgi-messages] SF.net SVN: osgi:[259] papoose-cmpn/trunk
Status: Beta
Brought to you by:
maguro
|
From: <osg...@li...> - 2010-02-25 23:55:57
|
Revision: 259
http://osgi.svn.sourceforge.net/osgi/?rev=259&view=rev
Author: maguro
Date: 2010-02-25 23:55:50 +0000 (Thu, 25 Feb 2010)
Log Message:
-----------
More sketchwork
Modified Paths:
--------------
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java
Added Paths:
-----------
papoose-cmpn/trunk/config/src/main/java/org/
papoose-cmpn/trunk/config/src/main/java/org/papoose/
papoose-cmpn/trunk/config/src/main/java/org/papoose/config/
papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationAdminImpl.java
papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationImpl.java
papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java
papoose-cmpn/trunk/test.java
Added: papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationAdminImpl.java
===================================================================
--- papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationAdminImpl.java (rev 0)
+++ papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationAdminImpl.java 2010-02-25 23:55:50 UTC (rev 259)
@@ -0,0 +1,59 @@
+/**
+ *
+ * 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.config;
+
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ConfigurationAdminImpl implements ConfigurationAdmin
+{
+ private final static String CLASS_NAME = ConfigurationAdminImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+
+ public Configuration createFactoryConfiguration(String factoryPid) throws IOException
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Configuration createFactoryConfiguration(String factoryPid, String location) throws IOException
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Configuration getConfiguration(String pid, String location) throws IOException
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Configuration getConfiguration(String pid) throws IOException
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException
+ {
+ return new Configuration[0]; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationAdminImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationImpl.java
===================================================================
--- papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationImpl.java (rev 0)
+++ papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationImpl.java 2010-02-25 23:55:50 UTC (rev 259)
@@ -0,0 +1,73 @@
+/**
+ *
+ * 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.config;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.logging.Logger;
+
+import org.osgi.service.cm.Configuration;
+
+
+/**
+ * @version $Revision: $ $Date: $
+ */
+public class ConfigurationImpl implements Configuration
+{
+ private final static String CLASS_NAME = ConfigurationImpl.class.getName();
+ private final static Logger LOGGER = Logger.getLogger(CLASS_NAME);
+
+ public String getPid()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Dictionary getProperties()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void update(Dictionary properties) throws IOException
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void delete() throws IOException
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getFactoryPid()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void update() throws IOException
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setBundleLocation(String bundleLocation)
+ {
+ //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getBundleLocation()
+ {
+ return null; //Todo change body of implemented methods use File | Settings | File Templates.
+ }
+}
Property changes on: papoose-cmpn/trunk/config/src/main/java/org/papoose/config/ConfigurationImpl.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java (rev 0)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java 2010-02-25 23:55:50 UTC (rev 259)
@@ -0,0 +1,24 @@
+/**
+ *
+ * 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 class ResourceNotFoundException extends RuntimeException
+{
+}
Property changes on: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ResourceNotFoundException.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
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-02-25 20:22:55 UTC (rev 258)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletDispatcher.java 2010-02-25 23:55:50 UTC (rev 259)
@@ -41,9 +41,6 @@
{
String path = req.getPathInfo();
- ServletRegistration r = null;
-
- done:
while (true)
{
for (ServletRegistration registration : registrations)
@@ -52,8 +49,29 @@
{
if (registration.getContext().handleSecurity(req, resp))
{
- r = registration;
- break done;
+ try
+ {
+ registration.getServlet().service(req, resp);
+ return;
+ }
+ catch (ServletException e)
+ {
+ throw e;
+ }
+ catch (IOException e)
+ {
+ throw e;
+ }
+ catch (ResourceNotFoundException e)
+ {
+ if (LOGGER.isLoggable(Level.FINEST)) LOGGER.finest("Registration at " + registration.getAlias() + " has no resource");
+ }
+ catch (Throwable t)
+ {
+ LOGGER.log(Level.WARNING, "Problems calling ", t);
+ resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ return;
+ }
}
else
{
@@ -68,30 +86,7 @@
path = path.substring(0, index);
}
- if (r != null)
- {
- try
- {
- r.getServlet().service(req, resp);
- }
- catch (ServletException e)
- {
- throw e;
- }
- catch (IOException e)
- {
- throw e;
- }
- catch (Throwable t)
- {
- LOGGER.log(Level.WARNING, "Problems calling ", t);
- resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- }
- }
- else
- {
- resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
- }
+ resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
}
void register(ServletRegistration registration)
Modified: papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java
===================================================================
--- papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java 2010-02-25 20:22:55 UTC (rev 258)
+++ papoose-cmpn/trunk/http/src/main/java/org/papoose/http/ServletWrapper.java 2010-02-25 23:55:50 UTC (rev 259)
@@ -21,7 +21,14 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
import java.security.AccessControlContext;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.logging.Logger;
import org.osgi.service.http.HttpContext;
@@ -48,8 +55,81 @@
}
@Override
- protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+ protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException
{
- super.service(req, resp); //Todo change body of overridden methods use File | Settings | File Templates.
+
+ final URL url = httpContext.getResource(name);
+
+ if (url == null) throw new ResourceNotFoundException();
+
+ String contentType = getServletContext().getMimeType(name);
+ if (contentType != null) resp.setContentType(contentType);
+
+ try
+ {
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Void>()
+ {
+ public Void run() throws Exception
+ {
+ URLConnection conn = url.openConnection();
+
+ long lastModified = conn.getLastModified();
+ if (lastModified != 0) resp.setDateHeader("Last-Modified", lastModified);
+
+ long modifiedSince = req.getDateHeader("If-Modified-Since");
+ if (lastModified == 0 || modifiedSince == -1 || lastModified > modifiedSince)
+ {
+ resp.setContentLength(copyResource(conn.getInputStream(), resp.getOutputStream()));
+ resp.setStatus(HttpServletResponse.SC_FOUND);
+ }
+ else
+ {
+ resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+ }
+
+ return null;
+ }
+ }, acc);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Exception exception = pae.getException();
+ if (exception instanceof ServletException) throw (ServletException) exception;
+ if (exception instanceof IOException) throw (IOException) exception;
+
+ resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
+ catch (Exception e)
+ {
+ resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ }
}
+
+ private int copyResource(InputStream in, OutputStream out) throws IOException
+ {
+ LOGGER.entering(CLASS_NAME, "copyResource", new Object[]{ in, out });
+
+ byte[] buf = new byte[4096];
+ int length = 0;
+ int n;
+
+ try
+ {
+ while ((n = in.read(buf, 0, buf.length)) != -1)
+ {
+ out.write(buf, 0, n);
+ length += n;
+ }
+
+ LOGGER.exiting(CLASS_NAME, "copyResource", length);
+
+ return length;
+ }
+ finally
+ {
+ in.close();
+ out.close();
+ }
+ }
+
}
Property changes on: papoose-cmpn/trunk/test.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|