use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class JSFManagedBeanProcessor method handleAnnotations.
private void handleAnnotations(final CompositeIndex index, final Set<String> managedBeanClasses) throws DeploymentUnitProcessingException {
final List<AnnotationInstance> annotations = index.getAnnotations(MANAGED_BEAN_ANNOTATION);
if (annotations != null) {
for (final AnnotationInstance annotation : annotations) {
final AnnotationTarget target = annotation.target();
if (target instanceof ClassInfo) {
final String className = ((ClassInfo) target).name().toString();
managedBeanClasses.add(className);
} else {
throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.invalidManagedBeanAnnotation(target));
}
}
}
}
use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class WarAnnotationDeploymentProcessor method processAnnotations.
/**
* Process a single index.
*
* @param index the annotation index
*
* @throws DeploymentUnitProcessingException
*/
protected WebMetaData processAnnotations(Index index) throws DeploymentUnitProcessingException {
Web30MetaData metaData = new Web30MetaData();
// @WebServlet
final List<AnnotationInstance> webServletAnnotations = index.getAnnotations(webServlet);
if (webServletAnnotations != null && webServletAnnotations.size() > 0) {
ServletsMetaData servlets = new ServletsMetaData();
List<ServletMappingMetaData> servletMappings = new ArrayList<ServletMappingMetaData>();
for (final AnnotationInstance annotation : webServletAnnotations) {
ServletMetaData servlet = new ServletMetaData();
AnnotationTarget target = annotation.target();
if (!(target instanceof ClassInfo)) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebServletAnnotation(target));
}
ClassInfo classInfo = ClassInfo.class.cast(target);
servlet.setServletClass(classInfo.toString());
AnnotationValue nameValue = annotation.value("name");
if (nameValue == null || nameValue.asString().isEmpty()) {
servlet.setName(classInfo.toString());
} else {
servlet.setName(nameValue.asString());
}
AnnotationValue loadOnStartup = annotation.value("loadOnStartup");
if (loadOnStartup != null && loadOnStartup.asInt() >= 0) {
servlet.setLoadOnStartupInt(loadOnStartup.asInt());
}
AnnotationValue asyncSupported = annotation.value("asyncSupported");
if (asyncSupported != null) {
servlet.setAsyncSupported(asyncSupported.asBoolean());
}
AnnotationValue initParamsValue = annotation.value("initParams");
if (initParamsValue != null) {
AnnotationInstance[] initParamsAnnotations = initParamsValue.asNestedArray();
if (initParamsAnnotations != null && initParamsAnnotations.length > 0) {
List<ParamValueMetaData> initParams = new ArrayList<ParamValueMetaData>();
for (AnnotationInstance initParamsAnnotation : initParamsAnnotations) {
ParamValueMetaData initParam = new ParamValueMetaData();
AnnotationValue initParamName = initParamsAnnotation.value("name");
AnnotationValue initParamValue = initParamsAnnotation.value();
if (initParamName == null || initParamValue == null) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebInitParamAnnotation(target));
}
AnnotationValue initParamDescription = initParamsAnnotation.value("description");
initParam.setParamName(initParamName.asString());
initParam.setParamValue(initParamValue.asString());
if (initParamDescription != null) {
Descriptions descriptions = getDescription(initParamDescription.asString());
if (descriptions != null) {
initParam.setDescriptions(descriptions);
}
}
initParams.add(initParam);
}
servlet.setInitParam(initParams);
}
}
AnnotationValue descriptionValue = annotation.value("description");
AnnotationValue displayNameValue = annotation.value("displayName");
AnnotationValue smallIconValue = annotation.value("smallIcon");
AnnotationValue largeIconValue = annotation.value("largeIcon");
DescriptionGroupMetaData descriptionGroup = getDescriptionGroup((descriptionValue == null) ? "" : descriptionValue.asString(), (displayNameValue == null) ? "" : displayNameValue.asString(), (smallIconValue == null) ? "" : smallIconValue.asString(), (largeIconValue == null) ? "" : largeIconValue.asString());
if (descriptionGroup != null) {
servlet.setDescriptionGroup(descriptionGroup);
}
ServletMappingMetaData servletMapping = new ServletMappingMetaData();
servletMapping.setServletName(servlet.getName());
List<String> urlPatterns = new ArrayList<String>();
AnnotationValue urlPatternsValue = annotation.value("urlPatterns");
if (urlPatternsValue != null) {
for (String urlPattern : urlPatternsValue.asStringArray()) {
urlPatterns.add(urlPattern);
}
}
urlPatternsValue = annotation.value();
if (urlPatternsValue != null) {
for (String urlPattern : urlPatternsValue.asStringArray()) {
urlPatterns.add(urlPattern);
}
}
if (urlPatterns.size() > 0) {
servletMapping.setUrlPatterns(urlPatterns);
servletMappings.add(servletMapping);
}
servlets.add(servlet);
}
metaData.setServlets(servlets);
metaData.setServletMappings(servletMappings);
}
// @WebFilter
final List<AnnotationInstance> webFilterAnnotations = index.getAnnotations(webFilter);
if (webFilterAnnotations != null && webFilterAnnotations.size() > 0) {
FiltersMetaData filters = new FiltersMetaData();
List<FilterMappingMetaData> filterMappings = new ArrayList<FilterMappingMetaData>();
for (final AnnotationInstance annotation : webFilterAnnotations) {
FilterMetaData filter = new FilterMetaData();
AnnotationTarget target = annotation.target();
if (!(target instanceof ClassInfo)) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebFilterAnnotation(target));
}
ClassInfo classInfo = ClassInfo.class.cast(target);
filter.setFilterClass(classInfo.toString());
AnnotationValue nameValue = annotation.value("filterName");
if (nameValue == null || nameValue.asString().isEmpty()) {
filter.setName(classInfo.toString());
} else {
filter.setName(nameValue.asString());
}
AnnotationValue asyncSupported = annotation.value("asyncSupported");
if (asyncSupported != null) {
filter.setAsyncSupported(asyncSupported.asBoolean());
}
AnnotationValue initParamsValue = annotation.value("initParams");
if (initParamsValue != null) {
AnnotationInstance[] initParamsAnnotations = initParamsValue.asNestedArray();
if (initParamsAnnotations != null && initParamsAnnotations.length > 0) {
List<ParamValueMetaData> initParams = new ArrayList<ParamValueMetaData>();
for (AnnotationInstance initParamsAnnotation : initParamsAnnotations) {
ParamValueMetaData initParam = new ParamValueMetaData();
AnnotationValue initParamName = initParamsAnnotation.value("name");
AnnotationValue initParamValue = initParamsAnnotation.value();
if (initParamName == null || initParamValue == null) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebInitParamAnnotation(target));
}
AnnotationValue initParamDescription = initParamsAnnotation.value("description");
initParam.setParamName(initParamName.asString());
initParam.setParamValue(initParamValue.asString());
if (initParamDescription != null) {
Descriptions descriptions = getDescription(initParamDescription.asString());
if (descriptions != null) {
initParam.setDescriptions(descriptions);
}
}
initParams.add(initParam);
}
filter.setInitParam(initParams);
}
}
AnnotationValue descriptionValue = annotation.value("description");
AnnotationValue displayNameValue = annotation.value("displayName");
AnnotationValue smallIconValue = annotation.value("smallIcon");
AnnotationValue largeIconValue = annotation.value("largeIcon");
DescriptionGroupMetaData descriptionGroup = getDescriptionGroup((descriptionValue == null) ? "" : descriptionValue.asString(), (displayNameValue == null) ? "" : displayNameValue.asString(), (smallIconValue == null) ? "" : smallIconValue.asString(), (largeIconValue == null) ? "" : largeIconValue.asString());
if (descriptionGroup != null) {
filter.setDescriptionGroup(descriptionGroup);
}
filters.add(filter);
FilterMappingMetaData filterMapping = new FilterMappingMetaData();
filterMapping.setFilterName(filter.getName());
List<String> urlPatterns = new ArrayList<String>();
List<String> servletNames = new ArrayList<String>();
List<DispatcherType> dispatchers = new ArrayList<DispatcherType>();
AnnotationValue urlPatternsValue = annotation.value("urlPatterns");
if (urlPatternsValue != null) {
for (String urlPattern : urlPatternsValue.asStringArray()) {
urlPatterns.add(urlPattern);
}
}
urlPatternsValue = annotation.value();
if (urlPatternsValue != null) {
for (String urlPattern : urlPatternsValue.asStringArray()) {
urlPatterns.add(urlPattern);
}
}
if (urlPatterns.size() > 0) {
filterMapping.setUrlPatterns(urlPatterns);
}
AnnotationValue servletNamesValue = annotation.value("servletNames");
if (servletNamesValue != null) {
for (String servletName : servletNamesValue.asStringArray()) {
servletNames.add(servletName);
}
}
if (servletNames.size() > 0) {
filterMapping.setServletNames(servletNames);
}
AnnotationValue dispatcherTypesValue = annotation.value("dispatcherTypes");
if (dispatcherTypesValue != null) {
for (String dispatcherValue : dispatcherTypesValue.asEnumArray()) {
dispatchers.add(DispatcherType.valueOf(dispatcherValue));
}
}
if (dispatchers.size() > 0) {
filterMapping.setDispatchers(dispatchers);
}
if (urlPatterns.size() > 0 || servletNames.size() > 0) {
filterMappings.add(filterMapping);
}
}
metaData.setFilters(filters);
metaData.setFilterMappings(filterMappings);
}
// @WebListener
final List<AnnotationInstance> webListenerAnnotations = index.getAnnotations(webListener);
if (webListenerAnnotations != null && webListenerAnnotations.size() > 0) {
List<ListenerMetaData> listeners = new ArrayList<ListenerMetaData>();
for (final AnnotationInstance annotation : webListenerAnnotations) {
ListenerMetaData listener = new ListenerMetaData();
AnnotationTarget target = annotation.target();
if (!(target instanceof ClassInfo)) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidWebListenerAnnotation(target));
}
ClassInfo classInfo = ClassInfo.class.cast(target);
listener.setListenerClass(classInfo.toString());
AnnotationValue descriptionValue = annotation.value();
if (descriptionValue != null) {
DescriptionGroupMetaData descriptionGroup = getDescriptionGroup(descriptionValue.asString());
if (descriptionGroup != null) {
listener.setDescriptionGroup(descriptionGroup);
}
}
listeners.add(listener);
}
metaData.setListeners(listeners);
}
// @RunAs
final List<AnnotationInstance> runAsAnnotations = index.getAnnotations(runAs);
if (runAsAnnotations != null && runAsAnnotations.size() > 0) {
AnnotationsMetaData annotations = metaData.getAnnotations();
if (annotations == null) {
annotations = new AnnotationsMetaData();
metaData.setAnnotations(annotations);
}
for (final AnnotationInstance annotation : runAsAnnotations) {
AnnotationTarget target = annotation.target();
if (!(target instanceof ClassInfo)) {
continue;
}
ClassInfo classInfo = ClassInfo.class.cast(target);
AnnotationMetaData annotationMD = annotations.get(classInfo.toString());
if (annotationMD == null) {
annotationMD = new AnnotationMetaData();
annotationMD.setClassName(classInfo.toString());
annotations.add(annotationMD);
}
if (annotation.value() == null) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidRunAsAnnotation(target));
}
RunAsMetaData runAs = new RunAsMetaData();
runAs.setRoleName(annotation.value().asString());
annotationMD.setRunAs(runAs);
}
}
// @DeclareRoles
final List<AnnotationInstance> declareRolesAnnotations = index.getAnnotations(declareRoles);
if (declareRolesAnnotations != null && declareRolesAnnotations.size() > 0) {
SecurityRolesMetaData securityRoles = metaData.getSecurityRoles();
if (securityRoles == null) {
securityRoles = new SecurityRolesMetaData();
metaData.setSecurityRoles(securityRoles);
}
for (final AnnotationInstance annotation : declareRolesAnnotations) {
if (annotation.value() == null) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidDeclareRolesAnnotation(annotation.target()));
}
for (String role : annotation.value().asStringArray()) {
SecurityRoleMetaData sr = new SecurityRoleMetaData();
sr.setRoleName(role);
securityRoles.add(sr);
}
}
}
// @MultipartConfig
final List<AnnotationInstance> multipartConfigAnnotations = index.getAnnotations(multipartConfig);
if (multipartConfigAnnotations != null && multipartConfigAnnotations.size() > 0) {
AnnotationsMetaData annotations = metaData.getAnnotations();
if (annotations == null) {
annotations = new AnnotationsMetaData();
metaData.setAnnotations(annotations);
}
for (final AnnotationInstance annotation : multipartConfigAnnotations) {
AnnotationTarget target = annotation.target();
if (!(target instanceof ClassInfo)) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidMultipartConfigAnnotation(target));
}
ClassInfo classInfo = ClassInfo.class.cast(target);
AnnotationMetaData annotationMD = annotations.get(classInfo.toString());
if (annotationMD == null) {
annotationMD = new AnnotationMetaData();
annotationMD.setClassName(classInfo.toString());
annotations.add(annotationMD);
}
MultipartConfigMetaData multipartConfig = new MultipartConfigMetaData();
AnnotationValue locationValue = annotation.value("location");
if (locationValue != null && locationValue.asString().length() > 0) {
multipartConfig.setLocation(locationValue.asString());
}
AnnotationValue maxFileSizeValue = annotation.value("maxFileSize");
if (maxFileSizeValue != null && maxFileSizeValue.asLong() != -1L) {
multipartConfig.setMaxFileSize(maxFileSizeValue.asLong());
}
AnnotationValue maxRequestSizeValue = annotation.value("maxRequestSize");
if (maxRequestSizeValue != null && maxRequestSizeValue.asLong() != -1L) {
multipartConfig.setMaxRequestSize(maxRequestSizeValue.asLong());
}
AnnotationValue fileSizeThresholdValue = annotation.value("fileSizeThreshold");
if (fileSizeThresholdValue != null && fileSizeThresholdValue.asInt() != 0) {
multipartConfig.setFileSizeThreshold(fileSizeThresholdValue.asInt());
}
annotationMD.setMultipartConfig(multipartConfig);
}
}
// @ServletSecurity
final List<AnnotationInstance> servletSecurityAnnotations = index.getAnnotations(servletSecurity);
if (servletSecurityAnnotations != null && servletSecurityAnnotations.size() > 0) {
AnnotationsMetaData annotations = metaData.getAnnotations();
if (annotations == null) {
annotations = new AnnotationsMetaData();
metaData.setAnnotations(annotations);
}
for (final AnnotationInstance annotation : servletSecurityAnnotations) {
AnnotationTarget target = annotation.target();
if (!(target instanceof ClassInfo)) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.invalidServletSecurityAnnotation(target));
}
ClassInfo classInfo = ClassInfo.class.cast(target);
AnnotationMetaData annotationMD = annotations.get(classInfo.toString());
if (annotationMD == null) {
annotationMD = new AnnotationMetaData();
annotationMD.setClassName(classInfo.toString());
annotations.add(annotationMD);
}
ServletSecurityMetaData servletSecurity = new ServletSecurityMetaData();
AnnotationValue httpConstraintValue = annotation.value();
List<String> rolesAllowed = new ArrayList<String>();
if (httpConstraintValue != null) {
AnnotationInstance httpConstraint = httpConstraintValue.asNested();
AnnotationValue httpConstraintERSValue = httpConstraint.value();
if (httpConstraintERSValue != null) {
servletSecurity.setEmptyRoleSemantic(EmptyRoleSemanticType.valueOf(httpConstraintERSValue.asEnum()));
}
AnnotationValue httpConstraintTGValue = httpConstraint.value("transportGuarantee");
if (httpConstraintTGValue != null) {
servletSecurity.setTransportGuarantee(TransportGuaranteeType.valueOf(httpConstraintTGValue.asEnum()));
}
AnnotationValue rolesAllowedValue = httpConstraint.value("rolesAllowed");
if (rolesAllowedValue != null) {
for (String role : rolesAllowedValue.asStringArray()) {
rolesAllowed.add(role);
}
}
}
servletSecurity.setRolesAllowed(rolesAllowed);
AnnotationValue httpMethodConstraintsValue = annotation.value("httpMethodConstraints");
if (httpMethodConstraintsValue != null) {
AnnotationInstance[] httpMethodConstraints = httpMethodConstraintsValue.asNestedArray();
if (httpMethodConstraints.length > 0) {
List<HttpMethodConstraintMetaData> methodConstraints = new ArrayList<HttpMethodConstraintMetaData>();
for (AnnotationInstance httpMethodConstraint : httpMethodConstraints) {
HttpMethodConstraintMetaData methodConstraint = new HttpMethodConstraintMetaData();
AnnotationValue httpMethodConstraintValue = httpMethodConstraint.value();
if (httpMethodConstraintValue != null) {
methodConstraint.setMethod(httpMethodConstraintValue.asString());
}
AnnotationValue httpMethodConstraintERSValue = httpMethodConstraint.value("emptyRoleSemantic");
if (httpMethodConstraintERSValue != null) {
methodConstraint.setEmptyRoleSemantic(EmptyRoleSemanticType.valueOf(httpMethodConstraintERSValue.asEnum()));
}
AnnotationValue httpMethodConstraintTGValue = httpMethodConstraint.value("transportGuarantee");
if (httpMethodConstraintTGValue != null) {
methodConstraint.setTransportGuarantee(TransportGuaranteeType.valueOf(httpMethodConstraintTGValue.asEnum()));
}
AnnotationValue rolesAllowedValue = httpMethodConstraint.value("rolesAllowed");
rolesAllowed = new ArrayList<String>();
if (rolesAllowedValue != null) {
for (String role : rolesAllowedValue.asStringArray()) {
rolesAllowed.add(role);
}
}
methodConstraint.setRolesAllowed(rolesAllowed);
methodConstraints.add(methodConstraint);
}
servletSecurity.setHttpMethodConstraints(methodConstraints);
}
}
annotationMD.setServletSecurity(servletSecurity);
}
}
return metaData;
}
use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class WarStructureDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
final ResourceRoot deploymentResourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile deploymentRoot = deploymentResourceRoot.getRoot();
if (deploymentRoot == null) {
return;
}
// set the child first behaviour
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
if (moduleSpecification == null) {
return;
}
moduleSpecification.setPrivateModule(true);
// other sub deployments should not have access to classes in the war module
PrivateSubDeploymentMarker.mark(deploymentUnit);
// OSGi WebApp deployments (WAB) may use the deployment root if they don't use WEB-INF/classes already
if (!deploymentUnit.hasAttachment(Attachments.OSGI_MANIFEST) || deploymentRoot.getChild(WEB_INF_CLASSES).exists()) {
// we do not want to index the resource root, only WEB-INF/classes and WEB-INF/lib
deploymentResourceRoot.putAttachment(Attachments.INDEX_RESOURCE_ROOT, false);
// Make sure the root does not end up in the module, only META-INF
deploymentResourceRoot.getExportFilters().add(new FilterSpecification(PathFilters.getMetaInfFilter(), true));
deploymentResourceRoot.getExportFilters().add(new FilterSpecification(PathFilters.getMetaInfSubdirectoriesFilter(), true));
deploymentResourceRoot.getExportFilters().add(new FilterSpecification(PathFilters.acceptAll(), false));
ModuleRootMarker.mark(deploymentResourceRoot, true);
}
// TODO: This needs to be ported to add additional resource roots the standard way
final MountHandle mountHandle = deploymentResourceRoot.getMountHandle();
try {
// add standard resource roots, this should eventually replace ClassPathEntry
final List<ResourceRoot> resourceRoots = createResourceRoots(deploymentRoot, deploymentUnit);
for (ResourceRoot root : resourceRoots) {
deploymentUnit.addToAttachmentList(Attachments.RESOURCE_ROOTS, root);
}
} catch (Exception e) {
throw new DeploymentUnitProcessingException(e);
}
// Add the war metadata
final WarMetaData warMetaData = new WarMetaData();
deploymentUnit.putAttachment(WarMetaData.ATTACHMENT_KEY, warMetaData);
String deploymentName;
if (deploymentUnit.getParent() == null) {
deploymentName = deploymentUnit.getName();
} else {
deploymentName = deploymentUnit.getParent().getName() + "." + deploymentUnit.getName();
}
PathManager pathManager = deploymentUnit.getAttachment(Attachments.PATH_MANAGER);
File tempDir = new File(pathManager.getPathEntry(TEMP_DIR).resolvePath(), deploymentName);
tempDir.mkdirs();
warMetaData.setTempDir(tempDir);
moduleSpecification.addPermissionFactory(new ImmediatePermissionFactory(new FilePermission(tempDir.getAbsolutePath() + File.separatorChar + "-", "read,write,delete")));
// Add the shared TLDs metadata
final TldsMetaData tldsMetaData = new TldsMetaData();
tldsMetaData.setSharedTlds(sharedTldsMetaData);
deploymentUnit.putAttachment(TldsMetaData.ATTACHMENT_KEY, tldsMetaData);
processExternalMounts(deploymentUnit, deploymentRoot);
}
use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class WebFragmentParsingDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!DeploymentTypeMarker.isType(DeploymentType.WAR, deploymentUnit)) {
// Skip non web deployments
return;
}
WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
assert warMetaData != null;
Map<String, WebFragmentMetaData> webFragments = warMetaData.getWebFragmentsMetaData();
if (webFragments == null) {
webFragments = new HashMap<String, WebFragmentMetaData>();
warMetaData.setWebFragmentsMetaData(webFragments);
}
List<ResourceRoot> resourceRoots = deploymentUnit.getAttachmentList(Attachments.RESOURCE_ROOTS);
for (ResourceRoot resourceRoot : resourceRoots) {
if (resourceRoot.getRoot().getName().toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
VirtualFile webFragment = resourceRoot.getRoot().getChild(WEB_FRAGMENT_XML);
if (webFragment.exists() && webFragment.isFile()) {
InputStream is = null;
try {
is = webFragment.openStream();
final XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setXMLResolver(NoopXMLResolver.create());
XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is);
WebFragmentMetaData webFragmentMetaData = WebFragmentMetaDataParser.parse(xmlReader, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
webFragments.put(resourceRoot.getRootName(), webFragmentMetaData);
/*Log message to inform that distributable is not set in web-fragment.xml while it is set in web.xml*/
if (warMetaData.getWebMetaData() != null && warMetaData.getWebMetaData().getDistributable() != null && webFragmentMetaData.getDistributable() == null)
UndertowLogger.ROOT_LOGGER.distributableDisabledInFragmentXml(deploymentUnit.getName(), resourceRoot.getRootName());
} catch (XMLStreamException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(webFragment.toString(), e.getLocation().getLineNumber(), e.getLocation().getColumnNumber()));
} catch (IOException e) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failToParseXMLDescriptor(webFragment.toString()), e);
} finally {
try {
if (is != null) {
is.close();
}
} catch (IOException e) {
// Ignore
}
}
}
}
}
}
use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class UndertowDeploymentProcessor method processDeployment.
private void processDeployment(final WarMetaData warMetaData, final DeploymentUnit deploymentUnit, final ServiceTarget serviceTarget, final String deploymentName, final String hostName, final String serverInstanceName) throws DeploymentUnitProcessingException {
ResourceRoot deploymentResourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
final VirtualFile deploymentRoot = deploymentResourceRoot.getRoot();
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (module == null) {
throw new DeploymentUnitProcessingException(UndertowLogger.ROOT_LOGGER.failedToResolveModule(deploymentUnit));
}
final JBossWebMetaData metaData = warMetaData.getMergedJBossWebMetaData();
final List<SetupAction> setupActions = deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.WEB_SETUP_ACTIONS);
ScisMetaData scisMetaData = deploymentUnit.getAttachment(ScisMetaData.ATTACHMENT_KEY);
final Set<ServiceName> dependentComponents = new HashSet<>();
// see AS7-2077
// basically we want to ignore components that have failed for whatever reason
// if they are important they will be picked up when the web deployment actually starts
final List<ServiceName> components = deploymentUnit.getAttachmentList(WebComponentDescription.WEB_COMPONENTS);
final Set<ServiceName> failed = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.FAILED_COMPONENTS);
for (final ServiceName component : components) {
if (!failed.contains(component)) {
dependentComponents.add(component);
}
}
String servletContainerName = metaData.getServletContainerName();
if (servletContainerName == null) {
servletContainerName = defaultContainer;
}
boolean componentRegistryExists = true;
ComponentRegistry componentRegistry = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.COMPONENT_REGISTRY);
if (componentRegistry == null) {
componentRegistryExists = false;
//we do this to avoid lots of other null checks
//this will only happen if the EE subsystem is not installed
componentRegistry = new ComponentRegistry(null);
}
final WebInjectionContainer injectionContainer = new WebInjectionContainer(module.getClassLoader(), componentRegistry);
String jaccContextId = metaData.getJaccContextID();
if (jaccContextId == null) {
jaccContextId = deploymentUnit.getName();
}
if (deploymentUnit.getParent() != null) {
jaccContextId = deploymentUnit.getParent().getName() + "!" + jaccContextId;
}
final String pathName = pathNameOfDeployment(deploymentUnit, metaData);
boolean securityEnabled = deploymentUnit.hasAttachment(SecurityAttachments.SECURITY_ENABLED);
String metaDataSecurityDomain = metaData.getSecurityDomain();
if (metaDataSecurityDomain == null) {
metaDataSecurityDomain = getJBossAppSecurityDomain(deploymentUnit);
}
if (metaDataSecurityDomain != null) {
metaDataSecurityDomain = metaDataSecurityDomain.trim();
}
final String securityDomain;
if (securityEnabled) {
securityDomain = metaDataSecurityDomain == null ? defaultSecurityDomain : SecurityUtil.unprefixSecurityDomain(metaDataSecurityDomain);
} else {
securityDomain = null;
}
final Set<ServiceName> additionalDependencies = new HashSet<>();
for (final SetupAction setupAction : setupActions) {
Set<ServiceName> dependencies = setupAction.dependencies();
if (dependencies != null) {
additionalDependencies.addAll(dependencies);
}
}
SharedSessionManagerConfig sharedSessionManagerConfig = deploymentUnit.getParent() != null ? deploymentUnit.getParent().getAttachment(UndertowAttachments.SHARED_SESSION_MANAGER_CONFIG) : null;
if (!deploymentResourceRoot.isUsePhysicalCodeSource()) {
try {
deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(Constants.CODE_SOURCE_ATTRIBUTE_NAME, deploymentRoot.toURL()));
} catch (MalformedURLException e) {
throw new DeploymentUnitProcessingException(e);
}
}
deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(Constants.PERMISSION_COLLECTION_ATTRIBUTE_NAME, deploymentUnit.getAttachment(Attachments.MODULE_PERMISSIONS)));
additionalDependencies.addAll(warMetaData.getAdditionalDependencies());
final ServiceName hostServiceName = UndertowService.virtualHostName(serverInstanceName, hostName);
final ServiceName deploymentServiceName = UndertowService.deploymentServiceName(serverInstanceName, hostName, pathName);
TldsMetaData tldsMetaData = deploymentUnit.getAttachment(TldsMetaData.ATTACHMENT_KEY);
UndertowDeploymentInfoService undertowDeploymentInfoService = UndertowDeploymentInfoService.builder().setAttributes(deploymentUnit.getAttachmentList(ServletContextAttribute.ATTACHMENT_KEY)).setContextPath(pathName).setDeploymentName(//todo: is this deployment name concept really applicable?
deploymentName).setDeploymentRoot(deploymentRoot).setMergedMetaData(warMetaData.getMergedJBossWebMetaData()).setModule(module).setScisMetaData(scisMetaData).setJaccContextId(jaccContextId).setSecurityDomain(securityDomain).setSharedTlds(tldsMetaData == null ? Collections.<TldMetaData>emptyList() : tldsMetaData.getSharedTlds(deploymentUnit)).setTldsMetaData(tldsMetaData).setSetupActions(setupActions).setSharedSessionManagerConfig(sharedSessionManagerConfig).setOverlays(warMetaData.getOverlays()).setExpressionFactoryWrappers(deploymentUnit.getAttachmentList(ExpressionFactoryWrapper.ATTACHMENT_KEY)).setPredicatedHandlers(deploymentUnit.getAttachment(UndertowHandlersDeploymentProcessor.PREDICATED_HANDLERS)).setInitialHandlerChainWrappers(deploymentUnit.getAttachmentList(UndertowAttachments.UNDERTOW_INITIAL_HANDLER_CHAIN_WRAPPERS)).setInnerHandlerChainWrappers(deploymentUnit.getAttachmentList(UndertowAttachments.UNDERTOW_INNER_HANDLER_CHAIN_WRAPPERS)).setOuterHandlerChainWrappers(deploymentUnit.getAttachmentList(UndertowAttachments.UNDERTOW_OUTER_HANDLER_CHAIN_WRAPPERS)).setThreadSetupActions(deploymentUnit.getAttachmentList(UndertowAttachments.UNDERTOW_THREAD_SETUP_ACTIONS)).setServletExtensions(deploymentUnit.getAttachmentList(UndertowAttachments.UNDERTOW_SERVLET_EXTENSIONS)).setExplodedDeployment(ExplodedDeploymentMarker.isExplodedDeployment(deploymentUnit)).setWebSocketDeploymentInfo(deploymentUnit.getAttachment(UndertowAttachments.WEB_SOCKET_DEPLOYMENT_INFO)).setTempDir(warMetaData.getTempDir()).setExternalResources(deploymentUnit.getAttachmentList(UndertowAttachments.EXTERNAL_RESOURCES)).setAllowSuspendedRequests(deploymentUnit.getAttachmentList(UndertowAttachments.ALLOW_REQUEST_WHEN_SUSPENDED)).createUndertowDeploymentInfoService();
final ServiceName deploymentInfoServiceName = deploymentServiceName.append(UndertowDeploymentInfoService.SERVICE_NAME);
ServiceBuilder<DeploymentInfo> infoBuilder = serviceTarget.addService(deploymentInfoServiceName, undertowDeploymentInfoService).addDependency(UndertowService.SERVLET_CONTAINER.append(servletContainerName), ServletContainerService.class, undertowDeploymentInfoService.getContainer()).addDependency(UndertowService.UNDERTOW, UndertowService.class, undertowDeploymentInfoService.getUndertowService()).addDependency(hostServiceName, Host.class, undertowDeploymentInfoService.getHost()).addDependency(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, undertowDeploymentInfoService.getServerEnvironmentInjectedValue()).addDependency(SuspendController.SERVICE_NAME, SuspendController.class, undertowDeploymentInfoService.getSuspendControllerInjectedValue()).addDependencies(additionalDependencies);
if (securityDomain != null) {
if (knownSecurityDomain.test(securityDomain)) {
infoBuilder.addDependency(deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT).getCapabilityServiceName(ApplicationSecurityDomainDefinition.APPLICATION_SECURITY_DOMAIN_CAPABILITY, securityDomain), BiFunction.class, undertowDeploymentInfoService.getSecurityFunctionInjector());
} else {
infoBuilder.addDependency(SecurityDomainService.SERVICE_NAME.append(securityDomain), SecurityDomainContext.class, undertowDeploymentInfoService.getSecurityDomainContextValue());
}
}
if (RequestControllerActivationMarker.isRequestControllerEnabled(deploymentUnit)) {
String topLevelName;
if (deploymentUnit.getParent() == null) {
topLevelName = deploymentUnit.getName();
} else {
topLevelName = deploymentUnit.getParent().getName();
}
infoBuilder.addDependency(ControlPointService.serviceName(topLevelName, UndertowExtension.SUBSYSTEM_NAME), ControlPoint.class, undertowDeploymentInfoService.getControlPointInjectedValue());
}
final Set<String> seenExecutors = new HashSet<String>();
if (metaData.getExecutorName() != null) {
final InjectedValue<Executor> executor = new InjectedValue<Executor>();
infoBuilder.addDependency(IOServices.WORKER.append(metaData.getExecutorName()), Executor.class, executor);
undertowDeploymentInfoService.addInjectedExecutor(metaData.getExecutorName(), executor);
seenExecutors.add(metaData.getExecutorName());
}
if (metaData.getServlets() != null) {
for (JBossServletMetaData servlet : metaData.getServlets()) {
if (servlet.getExecutorName() != null && !seenExecutors.contains(servlet.getExecutorName())) {
final InjectedValue<Executor> executor = new InjectedValue<Executor>();
infoBuilder.addDependency(IOServices.WORKER.append(servlet.getExecutorName()), Executor.class, executor);
undertowDeploymentInfoService.addInjectedExecutor(servlet.getExecutorName(), executor);
seenExecutors.add(servlet.getExecutorName());
}
}
}
if (componentRegistryExists) {
infoBuilder.addDependency(ComponentRegistry.serviceName(deploymentUnit), ComponentRegistry.class, undertowDeploymentInfoService.getComponentRegistryInjectedValue());
} else {
undertowDeploymentInfoService.getComponentRegistryInjectedValue().setValue(new ImmediateValue<>(componentRegistry));
}
if (sharedSessionManagerConfig != null) {
infoBuilder.addDependency(deploymentUnit.getParent().getServiceName().append(SharedSessionManagerConfig.SHARED_SESSION_MANAGER_SERVICE_NAME), SessionManagerFactory.class, undertowDeploymentInfoService.getSessionManagerFactoryInjector());
infoBuilder.addDependency(deploymentUnit.getParent().getServiceName().append(SharedSessionManagerConfig.SHARED_SESSION_IDENTIFIER_CODEC_SERVICE_NAME), SessionIdentifierCodec.class, undertowDeploymentInfoService.getSessionIdentifierCodecInjector());
} else {
CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
ServiceName sessionManagerFactoryServiceName = installSessionManagerFactory(support, serviceTarget, deploymentServiceName, deploymentName, module, metaData, deploymentUnit.getAttachment(UndertowAttachments.SERVLET_CONTAINER_SERVICE));
infoBuilder.addDependency(sessionManagerFactoryServiceName, SessionManagerFactory.class, undertowDeploymentInfoService.getSessionManagerFactoryInjector());
ServiceName sessionIdentifierCodecServiceName = installSessionIdentifierCodec(serviceTarget, deploymentServiceName, deploymentName, metaData);
infoBuilder.addDependency(sessionIdentifierCodecServiceName, SessionIdentifierCodec.class, undertowDeploymentInfoService.getSessionIdentifierCodecInjector());
}
infoBuilder.install();
final boolean isWebappBundle = deploymentUnit.hasAttachment(Attachments.OSGI_MANIFEST);
final UndertowDeploymentService service = new UndertowDeploymentService(injectionContainer, !isWebappBundle);
final ServiceBuilder<UndertowDeploymentService> builder = serviceTarget.addService(deploymentServiceName, service).addDependencies(dependentComponents).addDependency(UndertowService.SERVLET_CONTAINER.append(defaultContainer), ServletContainerService.class, service.getContainer()).addDependency(hostServiceName, Host.class, service.getHost()).addDependencies(deploymentUnit.getAttachmentList(Attachments.WEB_DEPENDENCIES)).addDependency(deploymentInfoServiceName, DeploymentInfo.class, service.getDeploymentInfoInjectedValue());
// inject the server executor which can be used by the WebDeploymentService for blocking tasks in start/stop
// of that service
Services.addServerExecutorDependency(builder, service.getServerExecutorInjector(), false);
deploymentUnit.addToAttachmentList(Attachments.DEPLOYMENT_COMPLETE_SERVICES, deploymentServiceName);
// adding JACC service
if (securityEnabled) {
AbstractSecurityDeployer<WarMetaData> deployer = new WarJACCDeployer();
JaccService<WarMetaData> jaccService = deployer.deploy(deploymentUnit, jaccContextId);
if (jaccService != null) {
final ServiceName jaccServiceName = deploymentUnit.getServiceName().append(JaccService.SERVICE_NAME);
ServiceBuilder<?> jaccBuilder = serviceTarget.addService(jaccServiceName, jaccService);
if (deploymentUnit.getParent() != null) {
// add dependency to parent policy
final DeploymentUnit parentDU = deploymentUnit.getParent();
jaccBuilder.addDependency(parentDU.getServiceName().append(JaccService.SERVICE_NAME), PolicyConfiguration.class, jaccService.getParentPolicyInjector());
}
// add dependency to web deployment service
jaccBuilder.addDependency(deploymentServiceName);
jaccBuilder.setInitialMode(Mode.PASSIVE).install();
}
}
// OSGi web applications are activated in {@link WebContextActivationProcessor} according to bundle lifecycle changes
if (isWebappBundle) {
UndertowDeploymentService.ContextActivatorImpl activator = new UndertowDeploymentService.ContextActivatorImpl(builder.install());
deploymentUnit.putAttachment(ContextActivator.ATTACHMENT_KEY, activator);
deploymentUnit.addToAttachmentList(Attachments.BUNDLE_ACTIVE_DEPENDENCIES, deploymentServiceName);
} else {
builder.install();
}
// Process the web related mgmt information
final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
final ModelNode node = deploymentResourceSupport.getDeploymentSubsystemModel(UndertowExtension.SUBSYSTEM_NAME);
node.get(DeploymentDefinition.CONTEXT_ROOT.getName()).set("".equals(pathName) ? "/" : pathName);
node.get(DeploymentDefinition.VIRTUAL_HOST.getName()).set(hostName);
node.get(DeploymentDefinition.SERVER.getName()).set(serverInstanceName);
processManagement(deploymentUnit, metaData);
}
Aggregations