Search in sources :

Example 16 with Component

use of org.jboss.as.ee.component.Component in project wildfly by wildfly.

the class AbstractInvocationHandler method invokeInternal.

public void invokeInternal(final Endpoint endpoint, final Invocation wsInvocation) throws Exception {
    // prepare for invocation
    onBeforeInvocation(wsInvocation);
    // prepare invocation data
    final ComponentView componentView = getComponentView();
    Component component = componentView.getComponent();
    // in case of @FactoryType annotation we don't need to go into EE interceptors
    final boolean forceTargetBean = (wsInvocation.getInvocationContext().getProperty("forceTargetBean") != null);
    if (forceTargetBean) {
        this.reference = new ManagedReference() {

            public void release() {
            }

            public Object getInstance() {
                return wsInvocation.getInvocationContext().getTargetBean();
            }
        };
        if (component instanceof WSComponent) {
            ((WSComponent) component).setReference(reference);
        }
    }
    final Method method = getComponentViewMethod(wsInvocation.getJavaMethod(), componentView.getViewMethods());
    final InterceptorContext context = new InterceptorContext();
    prepareForInvocation(context, wsInvocation);
    context.setMethod(method);
    context.setParameters(wsInvocation.getArgs());
    context.putPrivateData(Component.class, component);
    context.putPrivateData(ComponentView.class, componentView);
    // pull in any XTS transaction
    LocalTransactionContext.getCurrent().importProviderTransaction();
    context.setTransaction(ContextTransactionManager.getInstance().getTransaction());
    if (forceTargetBean) {
        context.putPrivateData(ManagedReference.class, reference);
    }
    // invoke method
    final Object retObj = componentView.invoke(context);
    // set return value
    wsInvocation.setReturnValue(retObj);
}
Also used : ComponentView(org.jboss.as.ee.component.ComponentView) InterceptorContext(org.jboss.invocation.InterceptorContext) WSComponent(org.jboss.as.webservices.injection.WSComponent) ManagedReference(org.jboss.as.naming.ManagedReference) Method(java.lang.reflect.Method) WSComponent(org.jboss.as.webservices.injection.WSComponent) Component(org.jboss.as.ee.component.Component)

Example 17 with Component

use of org.jboss.as.ee.component.Component 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)

Example 18 with Component

use of org.jboss.as.ee.component.Component in project wildfly by wildfly.

the class EjbIIOPTransactionInterceptor method processInvocation.

@Override
public Object processInvocation(final InterceptorContext invocation) throws Exception {
    // Do we have a foreign transaction context?
    Transaction tx = TxServerInterceptor.getCurrentTransaction();
    if (tx instanceof ForeignTransaction) {
        final EJBComponent component = (EJBComponent) invocation.getPrivateData(Component.class);
        //for timer invocations there is no view, so the methodInf is attached directly
        //to the context. Otherwise we retrieve it from the invoked view
        MethodIntf methodIntf = invocation.getPrivateData(MethodIntf.class);
        if (methodIntf == null) {
            final ComponentView componentView = invocation.getPrivateData(ComponentView.class);
            if (componentView != null) {
                methodIntf = componentView.getPrivateData(MethodIntf.class);
            } else {
                methodIntf = MethodIntf.BEAN;
            }
        }
        final TransactionAttributeType attr = component.getTransactionAttributeType(methodIntf, invocation.getMethod());
        if (attr != TransactionAttributeType.NOT_SUPPORTED && attr != TransactionAttributeType.REQUIRES_NEW) {
            throw EjbLogger.ROOT_LOGGER.transactionPropagationNotSupported();
        }
    }
    return invocation.proceed();
}
Also used : Transaction(javax.transaction.Transaction) ForeignTransaction(org.wildfly.iiop.openjdk.tm.ForeignTransaction) ComponentView(org.jboss.as.ee.component.ComponentView) ForeignTransaction(org.wildfly.iiop.openjdk.tm.ForeignTransaction) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) Component(org.jboss.as.ee.component.Component) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) TransactionAttributeType(javax.ejb.TransactionAttributeType)

Aggregations

Component (org.jboss.as.ee.component.Component)18 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)8 ComponentView (org.jboss.as.ee.component.ComponentView)7 Method (java.lang.reflect.Method)6 InterceptorContext (org.jboss.invocation.InterceptorContext)5 SecurityIdentity (org.wildfly.security.auth.server.SecurityIdentity)5 SecurityDomain (org.wildfly.security.auth.server.SecurityDomain)4 PrivilegedActionException (java.security.PrivilegedActionException)3 MethodIntf (org.jboss.as.ejb3.component.MethodIntf)3 IOException (java.io.IOException)2 TransactionAttributeType (javax.ejb.TransactionAttributeType)2 ComponentClientInstance (org.jboss.as.ee.component.ComponentClientInstance)2 ComponentInstance (org.jboss.as.ee.component.ComponentInstance)2 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)2 InvocationType (org.jboss.as.ee.component.interceptors.InvocationType)2 SessionBeanComponent (org.jboss.as.ejb3.component.session.SessionBeanComponent)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 SessionID (org.jboss.ejb.client.SessionID)2 Interceptor (org.jboss.invocation.Interceptor)2 ServiceName (org.jboss.msc.service.ServiceName)2