Search in sources :

Example 1 with RMIIIOPViolationException

use of org.wildfly.iiop.openjdk.rmi.RMIIIOPViolationException in project wildfly by wildfly.

the class EjbIIOPDeploymentUnitProcessor method processEjb.

private void processEjb(final EJBComponentDescription componentDescription, final DeploymentReflectionIndex deploymentReflectionIndex, final Module module, final ServiceTarget serviceTarget, final IIOPMetaData iiopMetaData) {
    componentDescription.setExposedViaIiop(true);
    // Create bean method mappings for container invoker
    final EJBViewDescription remoteView = componentDescription.getEjbRemoteView();
    final Class<?> remoteClass;
    try {
        remoteClass = ClassLoadingUtils.loadClass(remoteView.getViewClassName(), module);
    } catch (ClassNotFoundException e) {
        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getEJBClassName());
    }
    final EJBViewDescription homeView = componentDescription.getEjbHomeView();
    final Class<?> homeClass;
    try {
        homeClass = ClassLoadingUtils.loadClass(homeView.getViewClassName(), module);
    } catch (ClassNotFoundException e) {
        throw EjbLogger.ROOT_LOGGER.failedToLoadViewClassForComponent(e, componentDescription.getEJBClassName());
    }
    componentDescription.getEjbHomeView().getConfigurators().add(new IIOPInterceptorViewConfigurator());
    componentDescription.getEjbRemoteView().getConfigurators().add(new IIOPInterceptorViewConfigurator());
    final InterfaceAnalysis remoteInterfaceAnalysis;
    try {
        //TODO: change all this to use the deployment reflection index
        remoteInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(remoteClass);
    } catch (RMIIIOPViolationException e) {
        throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(e, componentDescription.getComponentName());
    }
    final Map<String, SkeletonStrategy> beanMethodMap = new HashMap<String, SkeletonStrategy>();
    final AttributeAnalysis[] remoteAttrs = remoteInterfaceAnalysis.getAttributes();
    for (int i = 0; i < remoteAttrs.length; i++) {
        final OperationAnalysis op = remoteAttrs[i].getAccessorAnalysis();
        if (op != null) {
            EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", op.getJavaName(), op.getIDLName());
            //translate to the deployment reflection index method
            //TODO: this needs to be fixed so it just returns the correct method
            final Method method = translateMethod(deploymentReflectionIndex, op);
            beanMethodMap.put(op.getIDLName(), new SkeletonStrategy(method));
            final OperationAnalysis setop = remoteAttrs[i].getMutatorAnalysis();
            if (setop != null) {
                EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", setop.getJavaName(), setop.getIDLName());
                //translate to the deployment reflection index method
                //TODO: this needs to be fixed so it just returns the correct method
                final Method realSetmethod = translateMethod(deploymentReflectionIndex, setop);
                beanMethodMap.put(setop.getIDLName(), new SkeletonStrategy(realSetmethod));
            }
        }
    }
    final OperationAnalysis[] ops = remoteInterfaceAnalysis.getOperations();
    for (int i = 0; i < ops.length; i++) {
        EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", ops[i].getJavaName(), ops[i].getIDLName());
        beanMethodMap.put(ops[i].getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, ops[i])));
    }
    // Initialize repository ids of remote interface
    final String[] beanRepositoryIds = remoteInterfaceAnalysis.getAllTypeIds();
    // Create home method mappings for container invoker
    final InterfaceAnalysis homeInterfaceAnalysis;
    try {
        //TODO: change all this to use the deployment reflection index
        homeInterfaceAnalysis = InterfaceAnalysis.getInterfaceAnalysis(homeClass);
    } catch (RMIIIOPViolationException e) {
        throw EjbLogger.ROOT_LOGGER.failedToAnalyzeRemoteInterface(e, componentDescription.getComponentName());
    }
    final Map<String, SkeletonStrategy> homeMethodMap = new HashMap<String, SkeletonStrategy>();
    final AttributeAnalysis[] attrs = homeInterfaceAnalysis.getAttributes();
    for (int i = 0; i < attrs.length; i++) {
        final OperationAnalysis op = attrs[i].getAccessorAnalysis();
        if (op != null) {
            EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", op.getJavaName(), op.getIDLName());
            homeMethodMap.put(op.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, op)));
            final OperationAnalysis setop = attrs[i].getMutatorAnalysis();
            if (setop != null) {
                EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", setop.getJavaName(), setop.getIDLName());
                homeMethodMap.put(setop.getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, setop)));
            }
        }
    }
    final OperationAnalysis[] homeops = homeInterfaceAnalysis.getOperations();
    for (int i = 0; i < homeops.length; i++) {
        EjbLogger.DEPLOYMENT_LOGGER.debugf("    %s%n                %s", homeops[i].getJavaName(), homeops[i].getIDLName());
        homeMethodMap.put(homeops[i].getIDLName(), new SkeletonStrategy(translateMethod(deploymentReflectionIndex, homeops[i])));
    }
    // Initialize repository ids of home interface
    final String[] homeRepositoryIds = homeInterfaceAnalysis.getAllTypeIds();
    final EjbIIOPService service = new EjbIIOPService(beanMethodMap, beanRepositoryIds, homeMethodMap, homeRepositoryIds, settingsService.isUseQualifiedName(), iiopMetaData, module);
    final ServiceBuilder<EjbIIOPService> builder = serviceTarget.addService(componentDescription.getServiceName().append(EjbIIOPService.SERVICE_NAME), service);
    builder.addDependency(componentDescription.getCreateServiceName(), EJBComponent.class, service.getEjbComponentInjectedValue());
    builder.addDependency(homeView.getServiceName(), ComponentView.class, service.getHomeView());
    builder.addDependency(remoteView.getServiceName(), ComponentView.class, service.getRemoteView());
    builder.addDependency(CorbaORBService.SERVICE_NAME, ORB.class, service.getOrb());
    builder.addDependency(POARegistry.SERVICE_NAME, POARegistry.class, service.getPoaRegistry());
    builder.addDependency(CorbaPOAService.INTERFACE_REPOSITORY_SERVICE_NAME, POA.class, service.getIrPoa());
    builder.addDependency(CorbaNamingService.SERVICE_NAME, NamingContextExt.class, service.getCorbaNamingContext());
    builder.addDependency(IORSecConfigMetaDataService.SERVICE_NAME, IORSecurityConfigMetaData.class, service.getIORSecConfigMetaDataInjectedValue());
    builder.addDependency(Services.JBOSS_SERVICE_MODULE_LOADER, ServiceModuleLoader.class, service.getServiceModuleLoaderInjectedValue());
    builder.addDependency(TxnServices.JBOSS_TXN_ARJUNA_TRANSACTION_MANAGER, TransactionManagerService.class, service.getTransactionManagerInjectedValue());
    builder.install();
}
Also used : EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) HashMap(java.util.HashMap) SkeletonStrategy(org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy) Method(java.lang.reflect.Method) OperationAnalysis(org.wildfly.iiop.openjdk.rmi.OperationAnalysis) InterfaceAnalysis(org.wildfly.iiop.openjdk.rmi.InterfaceAnalysis) AttributeAnalysis(org.wildfly.iiop.openjdk.rmi.AttributeAnalysis) RMIIIOPViolationException(org.wildfly.iiop.openjdk.rmi.RMIIIOPViolationException) EjbIIOPService(org.jboss.as.ejb3.iiop.EjbIIOPService)

Example 2 with RMIIIOPViolationException

use of org.wildfly.iiop.openjdk.rmi.RMIIIOPViolationException in project wildfly by wildfly.

the class IIOPStubCompiler method generateMethodCode.

/**
     * Generates the code of a given method within a stub class.
     *
     * @param asm           the <code>ProxyAssembler</code> used to assemble
     *                      the method code
     * @param superclass    the superclass of the stub class within which the
     *                      method will be generated
     * @param m             a <code>Method</code> instance describing the
     *                      method declaration by an RMI/IDL interface
     * @param idlName       a string with the method name mapped to IDL
     * @param strategyField a string with the name of the strategy field that
     *                      will be associated with the generated method
     * @param initMethod    a string with the name of the static initialization
     *                      method that will be associated with the generated
     *                      method.
     */
private static void generateMethodCode(ClassFile asm, Class<?> superclass, Method m, String idlName, String strategyField, String initMethod) {
    Class<?> returnType = m.getReturnType();
    Class<?>[] paramTypes = m.getParameterTypes();
    Class<?>[] exceptions = m.getExceptionTypes();
    // Generate a static field with the StubStrategy for the method
    asm.addField(Modifier.PRIVATE + Modifier.STATIC, strategyField, StubStrategy.class);
    // Generate the method code
    final CodeAttribute ca = asm.addMethod(m).getCodeAttribute();
    // The method code issues a call
    // super.invoke*(idlName, strategyField, args)
    ca.aload(0);
    ca.ldc(idlName);
    ca.getstatic(asm.getName(), strategyField, StubStrategy.class);
    // Push args
    if (paramTypes.length == 0) {
        ca.iconst(0);
        ca.anewarray(Object.class.getName());
    //asm.pushField(Util.class, "NOARGS");
    } else {
        ca.iconst(paramTypes.length);
        ca.anewarray(Object.class.getName());
        int index = 1;
        for (int j = 0; j < paramTypes.length; j++) {
            Class<?> type = paramTypes[j];
            ca.dup();
            ca.iconst(j);
            if (!type.isPrimitive()) {
                // object or array
                ca.aload(index);
            } else if (type.equals(double.class)) {
                ca.dload(index);
                Boxing.boxDouble(ca);
                index++;
            } else if (type.equals(long.class)) {
                ca.lload(index);
                Boxing.boxLong(ca);
                index++;
            } else if (type.equals(float.class)) {
                ca.fload(index);
                Boxing.boxFloat(ca);
            } else {
                ca.iload(index);
                Boxing.boxIfNessesary(ca, DescriptorUtils.makeDescriptor(type));
            }
            index++;
            ca.aastore();
        }
    }
    // Generate the call to an invoke* method ot the superclass
    String invoke = "invoke";
    String ret = "Ljava/lang/Object;";
    if (returnType.isPrimitive() && returnType != Void.TYPE) {
        String typeName = returnType.getName();
        invoke += (Character.toUpperCase(typeName.charAt(0)) + typeName.substring(1));
        ret = DescriptorUtils.makeDescriptor(returnType);
    }
    ca.invokevirtual(superclass.getName(), invoke, "(Ljava/lang/String;Lorg/wildfly/iiop/openjdk/rmi/marshal/strategy/StubStrategy;[Ljava/lang/Object;)" + ret);
    if (!returnType.isPrimitive() && returnType != Object.class) {
        ca.checkcast(returnType);
    }
    ca.returnInstruction();
    // Generate a static method that initializes the method's strategy field
    final CodeAttribute init = asm.addMethod(Modifier.PRIVATE + Modifier.STATIC, initMethod, "V").getCodeAttribute();
    int i;
    int len;
    // Push first argument for StubStrategy constructor:
    // array with abbreviated names of the param marshallers
    len = paramTypes.length;
    init.iconst(len);
    init.anewarray(String.class.getName());
    for (i = 0; i < len; i++) {
        init.dup();
        init.iconst(i);
        init.ldc(CDRStream.abbrevFor(paramTypes[i]));
        init.aastore();
    }
    // Push second argument for StubStrategy constructor:
    // array with exception repository ids
    len = exceptions.length;
    int n = 0;
    for (i = 0; i < len; i++) {
        if (!RemoteException.class.isAssignableFrom(exceptions[i])) {
            n++;
        }
    }
    init.iconst(n);
    init.anewarray(String.class.getName());
    try {
        int j = 0;
        for (i = 0; i < len; i++) {
            if (!RemoteException.class.isAssignableFrom(exceptions[i])) {
                init.dup();
                init.iconst(j);
                init.ldc(ExceptionAnalysis.getExceptionAnalysis(exceptions[i]).getExceptionRepositoryId());
                init.aastore();
                j++;
            }
        }
    } catch (RMIIIOPViolationException e) {
        throw EjbLogger.ROOT_LOGGER.exceptionRepositoryNotFound(exceptions[i].getName(), e.getLocalizedMessage());
    }
    // Push third argument for StubStrategy constructor:
    // array with exception class names
    init.iconst(n);
    init.anewarray(String.class.getName());
    int j = 0;
    for (i = 0; i < len; i++) {
        if (!RemoteException.class.isAssignableFrom(exceptions[i])) {
            init.dup();
            init.iconst(j);
            init.ldc(exceptions[i].getName());
            init.aastore();
            j++;
        }
    }
    // Push fourth argument for StubStrategy constructor:
    // abbreviated name of the return value marshaller
    init.ldc(CDRStream.abbrevFor(returnType));
    // Push fifth argument for StubStrategy constructor:
    // null (no ClassLoader specified)
    init.aconstNull();
    // Constructs the StubStrategy
    init.invokestatic(StubStrategy.class.getName(), "forMethod", "([Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;Ljava/lang/ClassLoader;)Lorg/wildfly/iiop/openjdk/rmi/marshal/strategy/StubStrategy;");
    // Set the strategy field of this stub class
    init.putstatic(asm.getName(), strategyField, StubStrategy.class);
    init.returnInstruction();
}
Also used : CodeAttribute(org.jboss.classfilewriter.code.CodeAttribute) StubStrategy(org.wildfly.iiop.openjdk.rmi.marshal.strategy.StubStrategy) RMIIIOPViolationException(org.wildfly.iiop.openjdk.rmi.RMIIIOPViolationException) RemoteException(java.rmi.RemoteException)

Aggregations

RMIIIOPViolationException (org.wildfly.iiop.openjdk.rmi.RMIIIOPViolationException)2 Method (java.lang.reflect.Method)1 RemoteException (java.rmi.RemoteException)1 HashMap (java.util.HashMap)1 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)1 EjbIIOPService (org.jboss.as.ejb3.iiop.EjbIIOPService)1 CodeAttribute (org.jboss.classfilewriter.code.CodeAttribute)1 AttributeAnalysis (org.wildfly.iiop.openjdk.rmi.AttributeAnalysis)1 InterfaceAnalysis (org.wildfly.iiop.openjdk.rmi.InterfaceAnalysis)1 OperationAnalysis (org.wildfly.iiop.openjdk.rmi.OperationAnalysis)1 SkeletonStrategy (org.wildfly.iiop.openjdk.rmi.marshal.strategy.SkeletonStrategy)1 StubStrategy (org.wildfly.iiop.openjdk.rmi.marshal.strategy.StubStrategy)1