use of org.apache.felix.http.base.internal.context.ExtServletContext in project felix by apache.
the class PerBundleHttpServiceImpl method registerServlet.
/**
* @see org.osgi.service.http.HttpService#registerServlet(java.lang.String, javax.servlet.Servlet, java.util.Dictionary, org.osgi.service.http.HttpContext)
*/
@Override
public void registerServlet(String alias, Servlet servlet, Dictionary initParams, HttpContext context) throws ServletException, NamespaceException {
if (servlet == null) {
throw new IllegalArgumentException("Servlet must not be null");
}
if (!PatternUtil.isValidPattern(alias) || !alias.startsWith("/")) {
throw new IllegalArgumentException("Malformed servlet alias [" + alias + "]");
}
final Map<String, String> paramMap = new HashMap<>();
if (initParams != null && initParams.size() > 0) {
Enumeration e = initParams.keys();
while (e.hasMoreElements()) {
Object key = e.nextElement();
Object value = initParams.get(key);
if ((key instanceof String) && (value instanceof String)) {
paramMap.put((String) key, (String) value);
}
}
}
synchronized (this.localServlets) {
if (this.localServlets.contains(servlet)) {
throw new ServletException("Servlet instance " + servlet + " already registered");
}
this.localServlets.add(servlet);
}
final ServletInfo servletInfo = new ServletInfo(String.format("%s_%d", servlet.getClass(), this.hashCode()), alias, paramMap);
final ExtServletContext httpContext = getServletContext(context);
boolean success = false;
try {
this.sharedHttpService.registerServlet(alias, httpContext, servlet, servletInfo);
success = true;
} finally {
if (!success) {
synchronized (this.localServlets) {
this.localServlets.remove(servlet);
}
}
}
}
use of org.apache.felix.http.base.internal.context.ExtServletContext in project felix by apache.
the class WhiteboardManager method sessionDestroyed.
public void sessionDestroyed(@Nonnull final HttpSession session, final Set<String> contextNames) {
for (final String contextName : contextNames) {
final WhiteboardContextHandler handler = this.getContextHandler(contextName);
if (handler != null) {
final ExtServletContext context = handler.getServletContext(this.httpBundleContext.getBundle());
new HttpSessionWrapper(session, context, true).invalidate();
handler.ungetServletContext(this.httpBundleContext.getBundle());
}
}
}
use of org.apache.felix.http.base.internal.context.ExtServletContext in project felix by apache.
the class WhiteboardManager method registerWhiteboardService.
/**
* Register whiteboard service in the http service
* @param handler Context handler
* @param info Whiteboard service info
*/
private void registerWhiteboardService(final WhiteboardContextHandler handler, final WhiteboardServiceInfo<?> info) {
try {
int failureCode = -1;
if (info instanceof ServletInfo) {
final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
if (servletContext == null) {
failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
} else {
final ServletHandler servletHandler = new WhiteboardServletHandler(handler.getContextInfo().getServiceId(), servletContext, (ServletInfo) info, handler.getBundleContext(), info.getServiceReference().getBundle(), this.httpBundleContext.getBundle());
handler.getRegistry().registerServlet(servletHandler);
}
} else if (info instanceof FilterInfo) {
final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
if (servletContext == null) {
failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
} else {
final FilterHandler filterHandler = new WhiteboardFilterHandler(handler.getContextInfo().getServiceId(), servletContext, (FilterInfo) info, handler.getBundleContext());
handler.getRegistry().registerFilter(filterHandler);
}
} else if (info instanceof ResourceInfo) {
final ServletInfo servletInfo = ((ResourceInfo) info).getServletInfo();
final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
if (servletContext == null) {
failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
} else {
final ServletHandler servleHandler = new HttpServiceServletHandler(handler.getContextInfo().getServiceId(), servletContext, servletInfo, new ResourceServlet(servletInfo.getPrefix()));
handler.getRegistry().registerServlet(servleHandler);
}
} else if (info instanceof ListenerInfo) {
final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
if (servletContext == null) {
failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
} else {
final ListenerHandler listenerHandler = new WhiteboardListenerHandler(handler.getContextInfo().getServiceId(), servletContext, (ListenerInfo) info, handler.getBundleContext());
handler.getRegistry().registerListeners(listenerHandler);
}
} else {
// This should never happen, but we log anyway
SystemLogger.error("Unknown whiteboard service " + info.getServiceReference(), null);
}
if (failureCode != -1) {
this.failureStateHandler.addFailure(info, handler.getContextInfo().getServiceId(), failureCode);
}
} catch (final Exception e) {
this.failureStateHandler.addFailure(info, handler.getContextInfo().getServiceId(), FAILURE_REASON_UNKNOWN, e);
}
}
use of org.apache.felix.http.base.internal.context.ExtServletContext in project felix by apache.
the class ErrorPageRegistryTest method createServletHandler.
private static ServletHandler createServletHandler(final long id, final int ranking, final String... codes) throws InvalidSyntaxException {
final ServletInfo si = createServletInfo(id, ranking, codes);
final ExtServletContext ctx = mock(ExtServletContext.class);
final Servlet servlet = mock(Servlet.class);
return new HttpServiceServletHandler(ctx, si, servlet);
}
use of org.apache.felix.http.base.internal.context.ExtServletContext in project felix by apache.
the class EventListenerRegistryTest method createFilterHandler.
private static FilterHandler createFilterHandler(final long id, final int ranking, final String... paths) throws InvalidSyntaxException {
final FilterInfo si = createFilterInfo(id, ranking, paths);
final ExtServletContext ctx = mock(ExtServletContext.class);
final Filter filter = mock(Filter.class);
return new HttpServiceFilterHandler(ctx, si, filter);
}
Aggregations