如何使用拦截器操纵发送到CORBA中远程对象的参数

时间:2019-03-19 09:56:16

标签: java corba

CORBA的新手,但可以建立从客户端到服务器的远程方法调用。当使用拦截器并尝试加密远程方法的参数时,它将抛出以下内容

Failed to initialise ORB: org.omg.CORBA.NO_RESOURCES:   vmcid: OMG  minor code: 1  completed: No org.omg.CORBA.NO_RESOURCES:   vmcid: OMG  minor code: 1completed: No at com.sun.corba.se.impl.logging.OMGSystemException.piOperationNotSupported1(Unknown Source)
at com.sun.corba.se.impl.logging.OMGSystemException.piOperationNotSupported1(Unknown Source)
at com.sun.corba.se.impl.interceptors.ClientRequestInfoImpl.arguments(Unknown Source)
at orb.CustomClientInterceptor.send_request(CustomClientInterceptor.java:23)

我正在从拦截器中尝试访问参数并按如下所示对其进行加密。

public void send_request( ClientRequestInfo ri )
{
    System.out.println( ri.arguments() );
    System.out.println( "Arguments.." );
    logger( ri, "send_request" );
}

但是甚至无法访问它们,它引发了以上错误。拦截方法很好。您能用一些代码或链接指导我吗?

预先感谢

1 个答案:

答案 0 :(得分:1)

我找到了答案,将来是否有人找到答案。

除非对CORBA对象的调用是DII或DSI调用,否则我们无法在拦截器中操纵参数。因此,首先您需要拨打这两个电话。我是通过DII完成的。代码如下。

                //-ORBInitialPort 1050 -ORBInitialHost localhost
                Properties p = new Properties();
                p.put("org.omg.PortableInterceptor.ORBInitializerClass.orb.InterceptorORBInitializer", "");
                //ORB orb = ORB.init(args, p);

                String[] orbArgs = { "-ORBInitialHost", "localhost", "-ORBInitialPort", "1050" };
                //NO_NEED ORB orb = ORB.init( orbArgs, null );
                orb = ORB.init(orbArgs, p);
                //objRef = orb.resolve_initial_references( "NameService" );
                //ncRef = NamingContextExtHelper.narrow( objRef );

                //DII Additional configs
                org.omg.CORBA.Object ncRef = orb.resolve_initial_references ("NameService"); 
                NamingContext nc = NamingContextHelper.narrow (ncRef); 
                NameComponent nComp = new NameComponent ("ABC", ""); 
                NameComponent [] path = {nComp}; 
                objRef = nc.resolve (path); 

然后进行DII调用,我在这里有一些混合代码,但是您会明白该怎么做

        NVList argList = orb.create_list (valueMap.size()); 
        for (Map.Entry<String, String> entry : valueMap.entrySet()) {
            Any argument = orb.create_any (); 
            argument.insert_string (entry.getValue()); 
            argList.add_value (entry.getKey().toLowerCase(), argument, org.omg.CORBA.ARG_IN.value); 
        }


        //Result
        Any result = orb.create_any (); 
        result.insert_string( null ); 
        NamedValue resultVal = orb.create_named_value ("result", result, org.omg.CORBA.ARG_OUT.value); 

        //Invoking Method
        Request thisReq = objRef._create_request (null, methodName, argList, resultVal); 
        thisReq.invoke (); 

        //Extract Result
        result = thisReq.result().value (); 

现在从拦截器中,您只需过滤DII调用,然后访问如下所示的参数。

public void send_request( ClientRequestInfo ri )
{
    if(ri.operation().equals( "processPayment" ))
    {
        System.out.println( "################# CLIENT SIDE ###############" );
        int count = 0;
        for(Parameter param : ri.arguments())
        {
            System.out.println( "Arg : "+count );
            System.out.println( param.argument.extract_string());
            param.argument.insert_string( EncryptionDecryption.encrypt( param.argument.extract_string() ) );
            count++;
        }
    }
    System.out.println( "Arguments.." );
    logger( ri, "send_request" );
}