/*
* Copyright 2004,2005 The Apache Software Foundation.
*
* 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.eclipse.equinox.jsp.examples;
import org.eclipse.equinox.http.helper.BundleEntryHttpContext;
import org.eclipse.equinox.http.helper.ContextPathServletAdaptor;
import org.eclipse.equinox.jsp.jasper.JspServlet;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.util.tracker.ServiceTracker;
import javax.servlet.Servlet;
/*
*
*/
public class HttpServiceTracker extends ServiceTracker {
public HttpServiceTracker(BundleContext context) {
super(context, HttpService.class.getName(), null);
}
public Object addingService(ServiceReference reference) {
final HttpService httpService = (HttpService) context.getService(reference);
try {
HttpContext commonContext =
new BundleEntryHttpContext(context.getBundle(), "/web");
httpService.registerResources("/jsp-examples", "/",
commonContext);
Servlet adaptedJspServlet = new ContextPathServletAdaptor(
new JspServlet(context.getBundle(), "/web"),
"/jsp-examples");
httpService.registerServlet("/jsp-examples/*.jsp", adaptedJspServlet, null,
commonContext);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return httpService;
}
public void removedService(ServiceReference reference, Object service) {
final HttpService httpService = (HttpService) service;
httpService.unregister("/jsp-examples"); //$NON-NLS-1$
httpService.unregister("/jsp-examples/*.jsp"); //$NON-NLS-1$
super.removedService(reference, service);
}
}