use of org.apache.felix.http.base.internal.runtime.FilterInfo in project felix by apache.
the class FailedDTOHolder method add.
public void add(final AbstractInfo<?> info, final long contextId, final int failureCode) {
if (info instanceof ServletContextHelperInfo) {
final FailedServletContextDTO dto = (FailedServletContextDTO) ServletContextDTOBuilder.build((ServletContextHelperInfo) info, null, failureCode);
this.failedServletContextDTOs.add(dto);
} else if (info instanceof ServletInfo) {
boolean isError = false;
if (((ServletInfo) info).getErrorPage() != null) {
isError = true;
final FailedErrorPageDTO dto = (FailedErrorPageDTO) ErrorPageDTOBuilder.build((ServletInfo) info, true);
dto.failureReason = failureCode;
final ErrorPageRegistry.ErrorRegistration reg = ErrorPageRegistry.getErrorRegistration((ServletInfo) info);
dto.errorCodes = reg.errorCodes;
dto.exceptions = reg.exceptions;
dto.servletContextId = contextId;
this.failedErrorPageDTOs.add(dto);
}
if (((ServletInfo) info).getPatterns() != null || ((ServletInfo) info).getName() != null || !isError) {
final FailedServletDTO dto = (FailedServletDTO) ServletDTOBuilder.build((ServletInfo) info, failureCode);
if (((ServletInfo) info).getPatterns() != null) {
dto.patterns = ((ServletInfo) info).getPatterns();
} else {
dto.patterns = BuilderConstants.EMPTY_STRING_ARRAY;
}
dto.name = ((ServletInfo) info).getName();
dto.servletContextId = contextId;
this.failedServletDTOs.add(dto);
}
} else if (info instanceof FilterInfo) {
final FailedFilterDTO dto = (FailedFilterDTO) FilterDTOBuilder.build((FilterInfo) info, failureCode);
dto.failureReason = failureCode;
dto.servletContextId = contextId;
this.failedFilterDTOs.add(dto);
} else if (info instanceof ResourceInfo) {
final FailedResourceDTO dto = (FailedResourceDTO) ResourceDTOBuilder.build((ResourceInfo) info, true);
dto.failureReason = failureCode;
dto.servletContextId = contextId;
this.failedResourceDTOs.add(dto);
} else if (info instanceof ListenerInfo) {
final FailedListenerDTO dto = (FailedListenerDTO) ListenerDTOBuilder.build((ListenerInfo) info, failureCode);
dto.servletContextId = contextId;
this.failedListenerDTOs.add(dto);
} else if (info instanceof PreprocessorInfo) {
final FailedPreprocessorDTO dto = (FailedPreprocessorDTO) PreprocessorDTOBuilder.build((PreprocessorInfo) info, failureCode);
this.failedPreprocessorDTOs.add(dto);
} else {
SystemLogger.error("Unsupported info type: " + info.getClass(), null);
}
}
use of org.apache.felix.http.base.internal.runtime.FilterInfo 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.runtime.FilterInfo 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);
}
use of org.apache.felix.http.base.internal.runtime.FilterInfo in project felix by apache.
the class EventListenerRegistryTest method createFilterInfo.
private static FilterInfo createFilterInfo(final long id, final int ranking, final String... paths) throws InvalidSyntaxException {
final BundleContext bCtx = mock(BundleContext.class);
when(bCtx.createFilter(Matchers.anyString())).thenReturn(null);
final Bundle bundle = mock(Bundle.class);
when(bundle.getBundleContext()).thenReturn(bCtx);
final ServiceReference<Filter> ref = mock(ServiceReference.class);
when(ref.getBundle()).thenReturn(bundle);
when(ref.getProperty(Constants.SERVICE_ID)).thenReturn(id);
when(ref.getProperty(Constants.SERVICE_RANKING)).thenReturn(ranking);
when(ref.getProperty(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN)).thenReturn(paths);
when(ref.getPropertyKeys()).thenReturn(new String[0]);
final FilterInfo si = new FilterInfo(ref);
return si;
}
use of org.apache.felix.http.base.internal.runtime.FilterInfo in project felix by apache.
the class PerBundleHttpServiceImpl method registerFilter.
/**
* @see org.apache.felix.http.api.ExtHttpService#registerFilter(javax.servlet.Filter, java.lang.String, java.util.Dictionary, int, org.osgi.service.http.HttpContext)
*/
@Override
public void registerFilter(final Filter filter, final String pattern, final Dictionary initParams, final int ranking, final HttpContext context) throws ServletException {
if (filter == null) {
throw new IllegalArgumentException("Filter must not be null");
}
final Map<String, String> paramMap = new HashMap<String, String>();
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);
}
}
}
final FilterInfo filterInfo = new FilterInfo(String.format("%s_%d", filter.getClass(), this.hashCode()), pattern, ranking, paramMap);
if (!filterInfo.isValid()) {
throw new ServletException("Invalid registration information for filter.");
}
final ExtServletContext httpContext = getServletContext(context);
final FilterHandler holder = new HttpServiceFilterHandler(httpContext, filterInfo, filter);
if (this.sharedHttpService.registerFilter(holder)) {
synchronized (this.localFilters) {
this.localFilters.add(holder);
}
}
}
Aggregations