blob: ab832c4a936022dbe2b5bc89ccddbaaf3daaf3e9 [file] [log] [blame]
Felix Meschbergerb76cfdb2007-09-28 14:13:22 +00001/*
Richard S. Hall435c20c2006-09-28 20:11:35 +00002 * 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. Hallfe8e5602006-04-19 15:23:22 +00009 *
Richard S. Hall435c20c2006-09-28 20:11:35 +000010 * http://www.apache.org/licenses/LICENSE-2.0
Richard S. Hallfe8e5602006-04-19 15:23:22 +000011 *
Richard S. Hall435c20c2006-09-28 20:11:35 +000012 * 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. Hallfe8e5602006-04-19 15:23:22 +000018 */
19package org.apache.felix.http.jetty;
20
Felix Meschbergerb76cfdb2007-09-28 14:13:22 +000021
Richard S. Hallfe8e5602006-04-19 15:23:22 +000022import java.net.URL;
23
24import javax.servlet.http.HttpServletRequest;
25import javax.servlet.http.HttpServletResponse;
26
27import org.osgi.framework.Bundle;
28import org.osgi.service.http.HttpContext;
29
Felix Meschbergerb76cfdb2007-09-28 14:13:22 +000030
Richard S. Hallfe8e5602006-04-19 15:23:22 +000031/**
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 */
41public class DefaultContextImpl implements HttpContext
42{
43 private Bundle m_bundle;
44
Felix Meschbergerb76cfdb2007-09-28 14:13:22 +000045
46 public DefaultContextImpl( Bundle bundle )
Richard S. Hallfe8e5602006-04-19 15:23:22 +000047 {
48 m_bundle = bundle;
49 }
50
Felix Meschbergerb76cfdb2007-09-28 14:13:22 +000051
52 public String getMimeType( String name )
Richard S. Hallfe8e5602006-04-19 15:23:22 +000053 {
54 return null;
55 }
56
Felix Meschbergerb76cfdb2007-09-28 14:13:22 +000057
58 public URL getResource( String name )
Richard S. Hallfe8e5602006-04-19 15:23:22 +000059 {
60 //TODO: need to grant "org.osgi.framework.AdminPermission" when
61 // permissions are included.
Felix Meschbergerb76cfdb2007-09-28 14:13:22 +000062 Activator.debug( "getResource for:" + name );
Richard S. Hallfe8e5602006-04-19 15:23:22 +000063
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 Meschbergerb76cfdb2007-09-28 14:13:22 +000067 if ( name.startsWith( "/" ) )
Richard S. Hallfe8e5602006-04-19 15:23:22 +000068 {
Felix Meschbergerb76cfdb2007-09-28 14:13:22 +000069 name = name.substring( 1 );
Richard S. Hallfe8e5602006-04-19 15:23:22 +000070 }
71
Felix Meschbergerb76cfdb2007-09-28 14:13:22 +000072 return m_bundle.getResource( name );
Richard S. Hallfe8e5602006-04-19 15:23:22 +000073 }
74
Felix Meschbergerb76cfdb2007-09-28 14:13:22 +000075
76 public boolean handleSecurity( HttpServletRequest request, HttpServletResponse response )
Richard S. Hallfe8e5602006-04-19 15:23:22 +000077 {
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}