use of com.sun.enterprise.deployment.web.ServletFilterMapping in project Payara by payara.
the class WebBundleDescriptorImpl method combineServletFilterMappings.
@Override
protected void combineServletFilterMappings(WebBundleDescriptor webBundleDescriptor) {
Map<String, ServletFilterMappingInfo> map = new HashMap<String, ServletFilterMappingInfo>();
for (ServletFilterMapping sfMapping : getServletFilterMappings()) {
ServletFilterMappingInfo sfmInfo = map.get(sfMapping.getName());
if (sfmInfo == null) {
sfmInfo = new ServletFilterMappingInfo();
sfmInfo.servletFilterMapping = sfMapping;
map.put(sfMapping.getName(), sfmInfo);
}
if (!sfmInfo.hasMapping) {
sfmInfo.hasMapping = (sfMapping.getServletNames().size() > 0 || sfMapping.getUrlPatterns().size() > 0);
}
if (!sfmInfo.hasDispatcher) {
sfmInfo.hasDispatcher = (sfMapping.getDispatchers().size() > 0);
}
}
for (ServletFilterMapping sfMapping : webBundleDescriptor.getServletFilterMappings()) {
ServletFilterMappingInfo sfmInfo = map.get(sfMapping.getName());
if (sfmInfo != null) {
if (!sfmInfo.hasMapping) {
sfmInfo.servletFilterMapping.getServletNames().addAll(sfMapping.getServletNames());
sfmInfo.servletFilterMapping.getUrlPatterns().addAll(sfMapping.getUrlPatterns());
}
if (!sfmInfo.hasDispatcher) {
sfmInfo.servletFilterMapping.getDispatchers().addAll(sfMapping.getDispatchers());
}
} else {
addServletFilterMapping(sfMapping);
}
}
}
use of com.sun.enterprise.deployment.web.ServletFilterMapping in project Payara by payara.
the class WeldDeployer method registerWeldConversationFilter.
private void registerWeldConversationFilter(WebBundleDescriptor webBundleDescriptor) {
for (ServletFilterMapping filterMapping : webBundleDescriptor.getServletFilterMappings()) {
if (WELD_CONVERSATION_FILTER_NAME.equals(((ServletFilterMappingDescriptor) filterMapping).getDisplayName())) {
ServletFilterDescriptor servletFilter = new ServletFilterDescriptor();
servletFilter.setClassName(WELD_CONVERSATION_FILTER_CLASS);
servletFilter.setName(WELD_CONVERSATION_FILTER_NAME);
webBundleDescriptor.addServletFilter(servletFilter);
break;
}
}
}
use of com.sun.enterprise.deployment.web.ServletFilterMapping in project Payara by payara.
the class WebFilterHandler method processAnnotation.
private HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, WebBundleDescriptor webBundleDesc) throws AnnotationProcessorException {
Class filterClass = (Class) ainfo.getAnnotatedElement();
if (!javax.servlet.Filter.class.isAssignableFrom(filterClass)) {
log(Level.SEVERE, ainfo, localStrings.getLocalString("web.deployment.annotation.handlers.needtoimpl", "The Class {0} having annotation {1} need to implement the interface {2}.", new Object[] { filterClass.getName(), WebFilter.class.getName(), javax.servlet.Filter.class.getName() }));
return getDefaultFailedResult();
}
WebFilter webFilterAn = (WebFilter) ainfo.getAnnotation();
String filterName = webFilterAn.filterName();
if (filterName == null || filterName.length() == 0) {
filterName = filterClass.getName();
}
ServletFilterDescriptor servletFilterDesc = null;
for (ServletFilter sfDesc : webBundleDesc.getServletFilters()) {
if (filterName.equals(sfDesc.getName())) {
servletFilterDesc = (ServletFilterDescriptor) sfDesc;
break;
}
}
if (servletFilterDesc == null) {
servletFilterDesc = new ServletFilterDescriptor();
servletFilterDesc.setName(filterName);
webBundleDesc.addServletFilter(servletFilterDesc);
} else {
String filterImpl = servletFilterDesc.getClassName();
if (filterImpl != null && filterImpl.length() > 0 && !filterImpl.equals(filterClass.getName())) {
log(Level.SEVERE, ainfo, localStrings.getLocalString("web.deployment.annotation.handlers.filternamedontmatch", "The filter ''{0}'' has implementation ''{1}'' in xml. It does not match with ''{2}'' from annotation @{3}.", new Object[] { filterName, filterImpl, filterClass.getName(), WebFilter.class.getName() }));
return getDefaultFailedResult();
}
}
servletFilterDesc.setClassName(filterClass.getName());
if (servletFilterDesc.getDescription() == null || servletFilterDesc.getDescription().length() == 0) {
servletFilterDesc.setDescription(webFilterAn.description());
}
if (servletFilterDesc.hasSetDisplayName()) {
servletFilterDesc.setDisplayName(webFilterAn.displayName());
}
if (servletFilterDesc.getInitializationParameters().size() == 0) {
WebInitParam[] initParams = webFilterAn.initParams();
if (initParams != null && initParams.length > 0) {
for (WebInitParam initParam : initParams) {
servletFilterDesc.addInitializationParameter(new EnvironmentProperty(initParam.name(), initParam.value(), initParam.description()));
}
}
}
if (servletFilterDesc.getSmallIconUri() == null) {
servletFilterDesc.setSmallIconUri(webFilterAn.smallIcon());
}
if (servletFilterDesc.getLargeIconUri() == null) {
servletFilterDesc.setLargeIconUri(webFilterAn.largeIcon());
}
if (servletFilterDesc.isAsyncSupported() == null) {
servletFilterDesc.setAsyncSupported(webFilterAn.asyncSupported());
}
ServletFilterMapping servletFilterMappingDesc = null;
boolean hasUrlPattern = false;
boolean hasServletName = false;
for (ServletFilterMapping sfm : webBundleDesc.getServletFilterMappings()) {
if (filterName.equals(sfm.getName())) {
servletFilterMappingDesc = sfm;
hasUrlPattern = hasUrlPattern || (sfm.getUrlPatterns().size() > 0);
hasServletName = hasServletName || (sfm.getServletNames().size() > 0);
}
}
if (servletFilterMappingDesc == null) {
servletFilterMappingDesc = new ServletFilterMappingDescriptor();
servletFilterMappingDesc.setName(filterName);
webBundleDesc.addServletFilterMapping(servletFilterMappingDesc);
}
if (!hasUrlPattern) {
String[] urlPatterns = webFilterAn.urlPatterns();
if (urlPatterns == null || urlPatterns.length == 0) {
urlPatterns = webFilterAn.value();
}
// accept here as url patterns may be defined in top level xml
boolean validUrlPatterns = true;
if (urlPatterns != null && urlPatterns.length > 0) {
for (String up : urlPatterns) {
if (!URLPattern.isValid(up)) {
validUrlPatterns = false;
break;
}
servletFilterMappingDesc.addURLPattern(up);
}
}
if (!validUrlPatterns) {
String urlPatternString = (urlPatterns != null) ? Arrays.toString(urlPatterns) : "";
throw new IllegalArgumentException(localStrings.getLocalString("web.deployment.annotation.handlers.invalidUrlPatterns", "Invalid url patterns: {0}.", urlPatternString));
}
}
if (!hasServletName) {
String[] servletNames = webFilterAn.servletNames();
if (servletNames != null && servletNames.length > 0) {
for (String sn : servletNames) {
servletFilterMappingDesc.addServletName(sn);
}
}
}
if (servletFilterMappingDesc.getDispatchers().size() == 0) {
DispatcherType[] dispatcherTypes = webFilterAn.dispatcherTypes();
if (dispatcherTypes != null && dispatcherTypes.length > 0) {
for (DispatcherType dType : dispatcherTypes) {
servletFilterMappingDesc.addDispatcher(dType.name());
}
}
}
return getDefaultProcessedResult();
}
use of com.sun.enterprise.deployment.web.ServletFilterMapping in project Payara by payara.
the class ServletFilterMappingDescriptor method equals.
/**
* compare equals
*/
public boolean equals(Object obj) {
if (obj instanceof ServletFilterMapping) {
ServletFilterMapping o = (ServletFilterMapping) obj;
Set<DispatcherType> otherDispatchers = o.getDispatchers();
boolean sameDispatchers = ((dispatchers == null && (otherDispatchers == null || otherDispatchers.size() == 0)) || (dispatchers != null && dispatchers.equals(otherDispatchers)));
if (this.getName().equals(o.getName()) && this.getServletNames().equals(o.getServletNames()) && this.getUrlPatterns().equals(o.getUrlPatterns()) && sameDispatchers) {
return true;
}
}
return false;
}
Aggregations