use of org.osgi.service.http.HttpContext in project motech by motech.
the class Activator method serviceAdded.
/**
* Initializes the security chain by fetching the proxy manager,
* registers the security filter and spring dispatcher servlet.
*/
private void serviceAdded(ExtHttpService service) {
DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setContextConfigLocation(CONTEXT_CONFIG_LOCATION);
dispatcherServlet.setContextClass(WebSecurityApplicationContext.class);
ClassLoader old = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
HttpContext httpContext = HttpContextFactory.getHttpContext(service.createDefaultHttpContext(), bundleContext.getBundle());
service.registerServlet(SERVLET_URL_MAPPING, dispatcherServlet, null, null);
service.registerResources(RESOURCE_URL_MAPPING, "/webapp", httpContext);
LOGGER.debug("Servlet registered");
filter = new MotechDelegatingFilterProxy("springSecurityFilterChain", dispatcherServlet.getWebApplicationContext());
MotechProxyManager proxyManager = dispatcherServlet.getWebApplicationContext().getBean(MotechProxyManager.class);
LOGGER.debug("Creating initial proxy chain");
proxyManager.initializeProxyChain();
service.registerFilter(filter, "/.*", null, 0, httpContext);
LOGGER.debug("Filter registered");
} catch (NamespaceException e) {
throw new ServletRegistrationException("Web-security servlet already registered", e);
} catch (ServletException e) {
throw new ServletRegistrationException("Unable to register servlet for web-security", e);
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
use of org.osgi.service.http.HttpContext in project smarthome by eclipse.
the class HttpContextFactoryServiceImplTest method shouldCreateHttpContext.
@Test
public void shouldCreateHttpContext() {
HttpContext context = httpContextFactoryService.createDefaultHttpContext(bundle);
assertThat(context, is(notNullValue()));
}
use of org.osgi.service.http.HttpContext in project cxf by apache.
the class ServletExporter method updated.
@SuppressWarnings("rawtypes")
@Override
public void updated(Dictionary properties) throws ConfigurationException {
if (alias != null) {
try {
LOG.log(Level.INFO, "Unregistering previous instance of \"" + alias + "\" servlet");
httpService.unregister(alias);
} catch (IllegalArgumentException e) {
// NOTE: pax-web specific...
if (e.getMessage() != null && e.getMessage().contains("was never registered")) {
LOG.log(Level.INFO, "CXF OSGi servlet was not unregistered: " + e.getMessage());
} else {
LOG.log(Level.SEVERE, e.getMessage(), e);
}
}
if (properties == null) {
// otherwise, we'll try to register the servlet
return;
}
alias = null;
}
if (properties == null) {
properties = new Properties();
}
Properties sprops = new Properties();
sprops.put("init-prefix", getProp(properties, CXF_SERVLET_PREFIX + "init-prefix", ""));
sprops.put("servlet-name", getProp(properties, CXF_SERVLET_PREFIX + "name", "cxf-osgi-transport-servlet"));
sprops.put("hide-service-list-page", getProp(properties, CXF_SERVLET_PREFIX + "hide-service-list-page", "false"));
sprops.put("disable-address-updates", getProp(properties, CXF_SERVLET_PREFIX + "disable-address-updates", "true"));
sprops.put("base-address", getProp(properties, CXF_SERVLET_PREFIX + "base-address", ""));
sprops.put("service-list-path", getProp(properties, CXF_SERVLET_PREFIX + "service-list-path", ""));
sprops.put("static-resources-list", getProp(properties, CXF_SERVLET_PREFIX + "static-resources-list", ""));
sprops.put("redirects-list", getProp(properties, CXF_SERVLET_PREFIX + "redirects-list", ""));
sprops.put("redirect-servlet-name", getProp(properties, CXF_SERVLET_PREFIX + "redirect-servlet-name", ""));
sprops.put("redirect-servlet-path", getProp(properties, CXF_SERVLET_PREFIX + "redirect-servlet-path", ""));
sprops.put("service-list-all-contexts", getProp(properties, CXF_SERVLET_PREFIX + "service-list-all-contexts", ""));
sprops.put("service-list-page-authenticate", getProp(properties, CXF_SERVLET_PREFIX + "service-list-page-authenticate", "false"));
sprops.put("service-list-page-authenticate-realm", getProp(properties, CXF_SERVLET_PREFIX + "service-list-page-authenticate-realm", "karaf"));
sprops.put("use-x-forwarded-headers", getProp(properties, CXF_SERVLET_PREFIX + "use-x-forwarded-headers", "false"));
sprops.put("async-supported", getProp(properties, CXF_SERVLET_PREFIX + "async-supported", "true"));
// Accept extra properties by default, can be disabled if it is really needed
if (Boolean.valueOf(getProp(properties, CXF_SERVLET_PREFIX + "support.extra.properties", "true").toString())) {
Enumeration keys = properties.keys();
while (keys.hasMoreElements()) {
String nextKey = keys.nextElement().toString();
if (!nextKey.startsWith(CXF_SERVLET_PREFIX)) {
sprops.put(nextKey, properties.get(nextKey));
}
}
}
if (serviceRegistration != null) {
serviceRegistration.unregister();
}
alias = (String) getProp(properties, CXF_SERVLET_PREFIX + "context", "/cxf");
HttpContext context = httpService.createDefaultHttpContext();
try {
LOG.log(Level.INFO, "Registering new instance of \"" + alias + "\" servlet");
httpService.registerServlet(alias, servlet, sprops, context);
} catch (Exception e) {
LOG.log(Level.WARNING, "Error registering CXF OSGi servlet " + e.getMessage(), e);
}
}
Aggregations