Felix Meschberger | b76cfdb | 2007-09-28 14:13:22 +0000 | [diff] [blame] | 1 | /* |
Richard S. Hall | 435c20c | 2006-09-28 20:11:35 +0000 | [diff] [blame] | 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 9 | * |
Richard S. Hall | 435c20c | 2006-09-28 20:11:35 +0000 | [diff] [blame] | 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 11 | * |
Richard S. Hall | 435c20c | 2006-09-28 20:11:35 +0000 | [diff] [blame] | 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 18 | */ |
| 19 | package org.apache.felix.http.jetty; |
| 20 | |
Felix Meschberger | b76cfdb | 2007-09-28 14:13:22 +0000 | [diff] [blame] | 21 | |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 22 | import java.net.URL; |
| 23 | |
| 24 | import javax.servlet.http.HttpServletRequest; |
| 25 | import javax.servlet.http.HttpServletResponse; |
| 26 | |
| 27 | import org.osgi.framework.Bundle; |
| 28 | import org.osgi.service.http.HttpContext; |
| 29 | |
Felix Meschberger | b76cfdb | 2007-09-28 14:13:22 +0000 | [diff] [blame] | 30 | |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 31 | /** |
| 32 | * Implementation of default HttpContext as per OSGi specification. |
| 33 | * |
| 34 | * Notes |
| 35 | * |
| 36 | * - no current inclusion/support for permissions |
| 37 | * - security allows all request. Spec leaves security handling to be |
| 38 | * implementation specific, but does outline some suggested handling. |
| 39 | * Deeper than my understanding of HTTP at this stage, so left for now. |
| 40 | */ |
| 41 | public class DefaultContextImpl implements HttpContext |
| 42 | { |
| 43 | private Bundle m_bundle; |
| 44 | |
Felix Meschberger | b76cfdb | 2007-09-28 14:13:22 +0000 | [diff] [blame] | 45 | |
| 46 | public DefaultContextImpl( Bundle bundle ) |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 47 | { |
| 48 | m_bundle = bundle; |
| 49 | } |
| 50 | |
Felix Meschberger | b76cfdb | 2007-09-28 14:13:22 +0000 | [diff] [blame] | 51 | |
| 52 | public String getMimeType( String name ) |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 53 | { |
| 54 | return null; |
| 55 | } |
| 56 | |
Felix Meschberger | b76cfdb | 2007-09-28 14:13:22 +0000 | [diff] [blame] | 57 | |
| 58 | public URL getResource( String name ) |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 59 | { |
| 60 | //TODO: need to grant "org.osgi.framework.AdminPermission" when |
| 61 | // permissions are included. |
Felix Meschberger | b76cfdb | 2007-09-28 14:13:22 +0000 | [diff] [blame] | 62 | Activator.debug( "getResource for:" + name ); |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 63 | |
| 64 | //TODO: temp measure for name. Bundle classloading doesn't seem to find |
| 65 | // resources which have a leading "/". This code should be removed |
| 66 | // if the bundle classloader is changed to allow a leading "/" |
Felix Meschberger | b76cfdb | 2007-09-28 14:13:22 +0000 | [diff] [blame] | 67 | if ( name.startsWith( "/" ) ) |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 68 | { |
Felix Meschberger | b76cfdb | 2007-09-28 14:13:22 +0000 | [diff] [blame] | 69 | name = name.substring( 1 ); |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Felix Meschberger | b76cfdb | 2007-09-28 14:13:22 +0000 | [diff] [blame] | 72 | return m_bundle.getResource( name ); |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Felix Meschberger | b76cfdb | 2007-09-28 14:13:22 +0000 | [diff] [blame] | 75 | |
| 76 | public boolean handleSecurity( HttpServletRequest request, HttpServletResponse response ) |
Richard S. Hall | fe8e560 | 2006-04-19 15:23:22 +0000 | [diff] [blame] | 77 | { |
| 78 | //TODO: need to look into what's appropriate for default security |
| 79 | // handling. Default to all requests to be serviced for now. |
| 80 | return true; |
| 81 | } |
| 82 | } |