Search in sources :

Example 1 with ApplicationClientMetaData

use of org.jboss.metadata.appclient.spec.ApplicationClientMetaData in project wildfly by wildfly.

the class ApplicationClientParsingDeploymentProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!DeploymentTypeMarker.isType(DeploymentType.APPLICATION_CLIENT, deploymentUnit)) {
        return;
    }
    final ApplicationClientMetaData appClientMD = parseAppClient(deploymentUnit, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
    final JBossClientMetaData jbossClientMD = parseJBossClient(deploymentUnit, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
    final JBossClientMetaData merged;
    if (appClientMD == null && jbossClientMD == null) {
        return;
    } else if (appClientMD == null) {
        merged = jbossClientMD;
    } else {
        merged = new JBossClientMetaData();
        merged.setEnvironmentRefsGroupMetaData(new AppClientEnvironmentRefsGroupMetaData());
        merged.merge(jbossClientMD, appClientMD);
    }
    if (merged.isMetadataComplete()) {
        MetadataCompleteMarker.setMetadataComplete(deploymentUnit, true);
    }
    deploymentUnit.putAttachment(AppClientAttachments.APPLICATION_CLIENT_META_DATA, merged);
    final DeploymentDescriptorEnvironment environment = new DeploymentDescriptorEnvironment("java:module/env/", merged.getEnvironmentRefsGroupMetaData());
    deploymentUnit.putAttachment(org.jboss.as.ee.component.Attachments.MODULE_DEPLOYMENT_DESCRIPTOR_ENVIRONMENT, environment);
    //override module name if applicable
    if (merged.getModuleName() != null && !merged.getModuleName().isEmpty()) {
        final EEModuleDescription description = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        description.setModuleName(merged.getModuleName());
    }
}
Also used : EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) DeploymentDescriptorEnvironment(org.jboss.as.ee.component.DeploymentDescriptorEnvironment) ApplicationClientMetaData(org.jboss.metadata.appclient.spec.ApplicationClientMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) JBossClientMetaData(org.jboss.metadata.appclient.jboss.JBossClientMetaData) AppClientEnvironmentRefsGroupMetaData(org.jboss.metadata.appclient.spec.AppClientEnvironmentRefsGroupMetaData)

Example 2 with ApplicationClientMetaData

use of org.jboss.metadata.appclient.spec.ApplicationClientMetaData in project wildfly by wildfly.

the class ApplicationClientParsingDeploymentProcessor method parseAppClient.

private ApplicationClientMetaData parseAppClient(DeploymentUnit deploymentUnit, final PropertyReplacer propertyReplacer) throws DeploymentUnitProcessingException {
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_CLIENT_DEPLOYMENT_DESCRIPTOR);
    // Locate the descriptor
    final VirtualFile descriptor;
    if (alternateDescriptor != null) {
        descriptor = alternateDescriptor;
    } else {
        descriptor = deploymentRoot.getRoot().getChild(APP_XML);
    }
    if (descriptor.exists()) {
        InputStream is = null;
        try {
            is = descriptor.openStream();
            ApplicationClientMetaData data = new ApplicationClientMetaDataParser().parse(getXMLStreamReader(is), propertyReplacer);
            return data;
        } catch (XMLStreamException e) {
            throw AppClientLogger.ROOT_LOGGER.failedToParseXml(e, descriptor, e.getLocation().getLineNumber(), e.getLocation().getColumnNumber());
        } catch (IOException e) {
            throw new DeploymentUnitProcessingException("Failed to parse " + descriptor, e);
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (IOException e) {
            // Ignore
            }
        }
    } else {
        return null;
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) ApplicationClientMetaData(org.jboss.metadata.appclient.spec.ApplicationClientMetaData) IOException(java.io.IOException) ApplicationClientMetaDataParser(org.jboss.metadata.appclient.parser.spec.ApplicationClientMetaDataParser)

Example 3 with ApplicationClientMetaData

use of org.jboss.metadata.appclient.spec.ApplicationClientMetaData 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();
}
Also used : DefaultApplicationClientCallbackHandler(org.jboss.as.appclient.service.DefaultApplicationClientCallbackHandler) CallbackHandler(javax.security.auth.callback.CallbackHandler) Properties(java.util.Properties) URL(java.net.URL) RealmCallbackWrapper(org.jboss.as.appclient.service.RealmCallbackWrapper) ApplicationClientComponentDescription(org.jboss.as.appclient.component.ApplicationClientComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) Component(org.jboss.as.ee.component.Component) InputStream(java.io.InputStream) DefaultApplicationClientCallbackHandler(org.jboss.as.appclient.service.DefaultApplicationClientCallbackHandler) ClassReflectionIndex(org.jboss.as.server.deployment.reflect.ClassReflectionIndex) SetupAction(org.jboss.as.server.deployment.SetupAction) Method(java.lang.reflect.Method) IOException(java.io.IOException) ApplicationClientStartService(org.jboss.as.appclient.service.ApplicationClientStartService) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) IOException(java.io.IOException) ApplicationClientMetaData(org.jboss.metadata.appclient.spec.ApplicationClientMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) File(java.io.File)

Aggregations

ApplicationClientMetaData (org.jboss.metadata.appclient.spec.ApplicationClientMetaData)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 File (java.io.File)1 Method (java.lang.reflect.Method)1 URL (java.net.URL)1 Properties (java.util.Properties)1 CallbackHandler (javax.security.auth.callback.CallbackHandler)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ApplicationClientComponentDescription (org.jboss.as.appclient.component.ApplicationClientComponentDescription)1 ApplicationClientStartService (org.jboss.as.appclient.service.ApplicationClientStartService)1 DefaultApplicationClientCallbackHandler (org.jboss.as.appclient.service.DefaultApplicationClientCallbackHandler)1 RealmCallbackWrapper (org.jboss.as.appclient.service.RealmCallbackWrapper)1 Component (org.jboss.as.ee.component.Component)1 DeploymentDescriptorEnvironment (org.jboss.as.ee.component.DeploymentDescriptorEnvironment)1 SetupAction (org.jboss.as.server.deployment.SetupAction)1 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)1