use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class BatchDeploymentResourceProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (deploymentUnit.hasAttachment(Attachments.MODULE) && !DeploymentTypeMarker.isType(DeploymentType.EAR, deploymentUnit) && deploymentUnit.hasAttachment(Attachments.DEPLOYMENT_ROOT)) {
BatchLogger.LOGGER.tracef("Processing deployment '%s' for the batch deployment resources.", deploymentUnit.getName());
final DeploymentResourceSupport deploymentResourceSupport = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_RESOURCE_SUPPORT);
// Add the job operator service used interact with a deployments batch job
final WildFlyJobOperator jobOperator = deploymentUnit.getAttachment(BatchAttachments.JOB_OPERATOR);
// Process each job XML file
for (String jobName : jobOperator.getAllJobNames()) {
try {
// Add the job information to the service
BatchLogger.LOGGER.debugf("Added job %s to allowed jobs for deployment %s", jobName, deploymentUnit.getName());
// Register the a resource for each job found
final PathAddress jobAddress = PathAddress.pathAddress(BatchJobResourceDefinition.JOB, jobName);
if (!deploymentResourceSupport.hasDeploymentSubModel(subsystemName, jobAddress)) {
deploymentResourceSupport.registerDeploymentSubResource(subsystemName, jobAddress, new BatchJobExecutionResource(jobOperator, jobName));
}
} catch (Exception e) {
// The deployment shouldn't fail in this case, just the specific resource registration should be skipped
// Log a debug message so the error is not lost
BatchLogger.LOGGER.debugf(e, "Batch jobs as an error occurred will not be registered for runtime views on the deployment (%s).", jobName, deploymentUnit.getName());
}
}
}
}
use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class WSHandlerChainAnnotationProcessor method processHandlerChainAnnotation.
private static void processHandlerChainAnnotation(final ResourceRoot currentResourceRoot, final List<ResourceRoot> resourceRoots, final AnnotationInstance handlerChainAnnotation, final String endpointClass, final WSEndpointHandlersMapping mapping) throws DeploymentUnitProcessingException {
final String handlerChainConfigFile = handlerChainAnnotation.value("file").asString();
InputStream is = null;
try {
is = getInputStream(currentResourceRoot, resourceRoots, handlerChainConfigFile, endpointClass);
final Set<String> endpointHandlers = getHandlers(is);
if (endpointHandlers.size() > 0) {
mapping.registerEndpointHandlers(endpointClass, endpointHandlers);
} else {
WSLogger.ROOT_LOGGER.invalidHandlerChainFile(handlerChainConfigFile);
}
} catch (final IOException e) {
throw new DeploymentUnitProcessingException(e);
} finally {
if (is != null) {
try {
is.close();
} catch (final IOException ignore) {
}
}
}
}
use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class ApplicationClientStartProcessor method deploy.
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final ApplicationClientMetaData appClientData = deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_META_DATA);
final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
//setup the callback handler
final CallbackHandler callbackHandler;
if (appClientData != null && appClientData.getCallbackHandler() != null && !appClientData.getCallbackHandler().isEmpty()) {
try {
final Class<?> callbackClass = ClassLoadingUtils.loadClass(appClientData.getCallbackHandler(), module);
callbackHandler = new RealmCallbackWrapper((CallbackHandler) callbackClass.newInstance());
} catch (ClassNotFoundException e) {
throw AppClientLogger.ROOT_LOGGER.couldNotLoadCallbackClass(appClientData.getCallbackHandler());
} catch (Exception e) {
throw AppClientLogger.ROOT_LOGGER.couldNotCreateCallbackHandler(appClientData.getCallbackHandler());
}
} else {
callbackHandler = new DefaultApplicationClientCallbackHandler();
}
Boolean activate = deploymentUnit.getAttachment(AppClientAttachments.START_APP_CLIENT);
if (activate == null || !activate) {
return;
}
final Class<?> mainClass = deploymentUnit.getAttachment(AppClientAttachments.MAIN_CLASS);
if (mainClass == null) {
throw AppClientLogger.ROOT_LOGGER.cannotStartAppClient(deploymentUnit.getName());
}
final ApplicationClientComponentDescription component = deploymentUnit.getAttachment(AppClientAttachments.APPLICATION_CLIENT_COMPONENT);
Method mainMethod = null;
Class<?> klass = mainClass;
while (klass != Object.class) {
final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(klass);
mainMethod = index.getMethod(void.class, "main", String[].class);
if (mainMethod != null) {
break;
}
klass = klass.getSuperclass();
}
if (mainMethod == null) {
throw AppClientLogger.ROOT_LOGGER.cannotStartAppClient(deploymentUnit.getName(), mainClass);
}
final ApplicationClientStartService startService;
final List<SetupAction> setupActions = deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.OTHER_EE_SETUP_ACTIONS);
if (connectionPropertiesUrl != null) {
try {
final File file = new File(connectionPropertiesUrl);
final URL url;
if (file.exists()) {
url = file.toURI().toURL();
} else {
url = new URL(connectionPropertiesUrl);
}
Properties properties = new Properties();
InputStream stream = null;
try {
stream = url.openStream();
properties.load(stream);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
//ignore
}
}
}
final ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
try {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader());
startService = new ApplicationClientStartService(mainMethod, parameters, moduleDescription.getNamespaceContextSelector(), module.getClassLoader(), setupActions);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
}
} catch (Exception e) {
throw AppClientLogger.ROOT_LOGGER.exceptionLoadingEjbClientPropertiesURL(connectionPropertiesUrl, e);
}
} else {
startService = new ApplicationClientStartService(mainMethod, parameters, moduleDescription.getNamespaceContextSelector(), module.getClassLoader(), setupActions, hostUrl, callbackHandler);
}
phaseContext.getServiceTarget().addService(deploymentUnit.getServiceName().append(ApplicationClientStartService.SERVICE_NAME), startService).addDependency(ApplicationClientDeploymentService.SERVICE_NAME, ApplicationClientDeploymentService.class, startService.getApplicationClientDeploymentServiceInjectedValue()).addDependency(component.getCreateServiceName(), Component.class, startService.getApplicationClientComponent()).install();
}
use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class KernelDeploymentParsingProcessor method parseDescriptors.
/**
* Find and parse -jboss-beans.xml files.
*
* @param unit the deployment unit
* @param root the root
* @throws DeploymentUnitProcessingException
* for any error
*/
protected void parseDescriptors(DeploymentUnit unit, VirtualFile root) throws DeploymentUnitProcessingException {
if (root == null || root.exists() == false)
return;
Collection<VirtualFile> beans;
final String name = root.getName();
if (name.endsWith("jboss-beans.xml")) {
beans = Collections.singleton(root);
} else {
VirtualFileFilter filter = new SuffixMatchFilter("jboss-beans.xml");
beans = new ArrayList<VirtualFile>();
try {
// try plain .jar/META-INF
VirtualFile metainf = root.getChild("META-INF");
if (metainf.exists())
beans.addAll(metainf.getChildren(filter));
// allow for WEB-INF/*-jboss-beans.xml
VirtualFile webinf = root.getChild("WEB-INF");
if (webinf.exists()) {
beans.addAll(webinf.getChildren(filter));
// allow WEB-INF/classes/META-INF
metainf = webinf.getChild("classes/META-INF");
if (metainf.exists())
beans.addAll(metainf.getChildren(filter));
}
} catch (IOException e) {
throw new DeploymentUnitProcessingException(e);
}
}
for (VirtualFile beansXmlFile : beans) parseDescriptor(unit, beansXmlFile);
}
use of org.jboss.as.server.deployment.DeploymentUnitProcessingException in project wildfly by wildfly.
the class DefaultComponentConfigurator method configure.
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(REFLECTION_INDEX);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final boolean metadataComplete = MetadataCompleteMarker.isMetadataComplete(deploymentUnit);
// Module stuff
final Deque<InterceptorFactory> injectors = new ArrayDeque<>();
final Deque<InterceptorFactory> uninjectors = new ArrayDeque<>();
final Deque<InterceptorFactory> destructors = new ArrayDeque<>();
final List<InterceptorFactory> componentUserAroundInvoke = new ArrayList<>();
final List<InterceptorFactory> componentUserAroundTimeout;
final List<InterceptorFactory> userPostConstruct = new ArrayList<>();
final List<InterceptorFactory> userPreDestroy = new ArrayList<>();
final List<InterceptorFactory> componentUserPrePassivate;
final List<InterceptorFactory> componentUserPostActivate;
final Set<MethodIdentifier> timeoutMethods = description.getTimerMethods();
if (description.isTimerServiceRequired()) {
componentUserAroundTimeout = new ArrayList<>();
} else {
componentUserAroundTimeout = null;
}
if (description.isPassivationApplicable()) {
componentUserPrePassivate = new ArrayList<>();
componentUserPostActivate = new ArrayList<>();
} else {
componentUserPrePassivate = null;
componentUserPostActivate = null;
}
destructors.add(new ImmediateInterceptorFactory(new ManagedReferenceReleaseInterceptor(BasicComponentInstance.INSTANCE_KEY)));
new ClassDescriptionTraversal(configuration.getComponentClass(), applicationClasses) {
@Override
public void handle(Class<?> clazz, EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
mergeInjectionsForClass(clazz, configuration.getComponentClass(), classDescription, moduleDescription, deploymentReflectionIndex, description, configuration, context, injectors, BasicComponentInstance.INSTANCE_KEY, uninjectors, metadataComplete);
}
}.run();
new ClassDescriptionTraversal(configuration.getComponentClass(), applicationClasses) {
@Override
public void handle(final Class<?> clazz, EEModuleClassDescription classDescription) throws DeploymentUnitProcessingException {
final InterceptorClassDescription interceptorConfig = InterceptorClassDescription.merge(ComponentDescription.mergeInterceptorConfig(clazz, classDescription, description, metadataComplete), moduleDescription.getInterceptorClassOverride(clazz.getName()));
handleClassMethod(clazz, interceptorConfig.getAroundInvoke(), componentUserAroundInvoke, false, false, configuration);
if (description.isTimerServiceRequired()) {
handleClassMethod(clazz, interceptorConfig.getAroundTimeout(), componentUserAroundTimeout, false, false, configuration);
}
if (!description.isIgnoreLifecycleInterceptors()) {
handleClassMethod(clazz, interceptorConfig.getPostConstruct(), userPostConstruct, true, true, configuration);
handleClassMethod(clazz, interceptorConfig.getPreDestroy(), userPreDestroy, true, true, configuration);
if (description.isPassivationApplicable()) {
handleClassMethod(clazz, interceptorConfig.getPrePassivate(), componentUserPrePassivate, false, true, configuration);
handleClassMethod(clazz, interceptorConfig.getPostActivate(), componentUserPostActivate, false, true, configuration);
}
}
}
private void handleClassMethod(final Class<?> clazz, final MethodIdentifier methodIdentifier, final List<InterceptorFactory> interceptors, boolean changeMethod, boolean lifecycleMethod, ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
if (methodIdentifier != null) {
final Method method = ClassReflectionIndexUtil.findRequiredMethod(deploymentReflectionIndex, clazz, methodIdentifier);
if (isNotOverriden(clazz, method, configuration.getComponentClass(), deploymentReflectionIndex)) {
InterceptorFactory interceptorFactory = new ImmediateInterceptorFactory(new ManagedReferenceLifecycleMethodInterceptor(BasicComponentInstance.INSTANCE_KEY, method, changeMethod, lifecycleMethod));
interceptors.add(interceptorFactory);
if (lifecycleMethod) {
configuration.addLifecycleMethod(method);
}
}
}
}
}.run();
final ClassLoader classLoader = module.getClassLoader();
final InterceptorFactory tcclInterceptor = new ImmediateInterceptorFactory(new ContextClassLoaderInterceptor(classLoader));
if (!injectors.isEmpty()) {
configuration.addPostConstructInterceptors(new ArrayList<>(injectors), InterceptorOrder.ComponentPostConstruct.COMPONENT_RESOURCE_INJECTION_INTERCEPTORS);
}
// Apply post-construct
if (!userPostConstruct.isEmpty()) {
configuration.addPostConstructInterceptors(userPostConstruct, InterceptorOrder.ComponentPostConstruct.COMPONENT_USER_INTERCEPTORS);
}
configuration.addPostConstructInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ComponentPostConstruct.TERMINAL_INTERCEPTOR);
configuration.addPostConstructInterceptor(tcclInterceptor, InterceptorOrder.ComponentPostConstruct.TCCL_INTERCEPTOR);
// Apply pre-destroy
if (!uninjectors.isEmpty()) {
configuration.addPreDestroyInterceptors(new ArrayList<>(uninjectors), InterceptorOrder.ComponentPreDestroy.COMPONENT_UNINJECTION_INTERCEPTORS);
}
if (!destructors.isEmpty()) {
configuration.addPreDestroyInterceptors(new ArrayList<>(destructors), InterceptorOrder.ComponentPreDestroy.COMPONENT_DESTRUCTION_INTERCEPTORS);
}
if (!userPreDestroy.isEmpty()) {
configuration.addPreDestroyInterceptors(userPreDestroy, InterceptorOrder.ComponentPreDestroy.COMPONENT_USER_INTERCEPTORS);
}
configuration.addPreDestroyInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ComponentPreDestroy.TERMINAL_INTERCEPTOR);
configuration.addPreDestroyInterceptor(tcclInterceptor, InterceptorOrder.ComponentPreDestroy.TCCL_INTERCEPTOR);
if (description.isPassivationApplicable()) {
if (!componentUserPrePassivate.isEmpty()) {
configuration.addPrePassivateInterceptors(componentUserPrePassivate, InterceptorOrder.ComponentPassivation.COMPONENT_USER_INTERCEPTORS);
}
configuration.addPrePassivateInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ComponentPassivation.TERMINAL_INTERCEPTOR);
configuration.addPrePassivateInterceptor(tcclInterceptor, InterceptorOrder.ComponentPassivation.TCCL_INTERCEPTOR);
if (!componentUserPostActivate.isEmpty()) {
configuration.addPostActivateInterceptors(componentUserPostActivate, InterceptorOrder.ComponentPassivation.COMPONENT_USER_INTERCEPTORS);
}
configuration.addPostActivateInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ComponentPassivation.TERMINAL_INTERCEPTOR);
configuration.addPostActivateInterceptor(tcclInterceptor, InterceptorOrder.ComponentPassivation.TCCL_INTERCEPTOR);
}
// @AroundInvoke interceptors
if (description.isIntercepted()) {
for (final Method method : configuration.getDefinedComponentMethods()) {
//now add the interceptor that initializes and the interceptor that actually invokes to the end of the interceptor chain
configuration.addComponentInterceptor(method, Interceptors.getInitialInterceptorFactory(), InterceptorOrder.Component.INITIAL_INTERCEPTOR);
configuration.addComponentInterceptor(method, new ImmediateInterceptorFactory(new ManagedReferenceMethodInterceptor(BasicComponentInstance.INSTANCE_KEY, method)), InterceptorOrder.Component.TERMINAL_INTERCEPTOR);
final MethodIdentifier identifier = MethodIdentifier.getIdentifier(method.getReturnType(), method.getName(), method.getParameterTypes());
// first add the default interceptors (if not excluded) to the deque
final boolean requiresTimerChain = description.isTimerServiceRequired() && timeoutMethods.contains(identifier);
if (requiresTimerChain) {
configuration.addComponentInterceptor(method, new UserInterceptorFactory(weaved(componentUserAroundInvoke), weaved(componentUserAroundTimeout)), InterceptorOrder.Component.COMPONENT_USER_INTERCEPTORS);
} else {
configuration.addComponentInterceptors(method, componentUserAroundInvoke, InterceptorOrder.Component.COMPONENT_USER_INTERCEPTORS);
}
}
}
}
Aggregations