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