简体   繁体   English

使用 XML 的 CORBA 消息传递 — 如何

[英]CORBA messaging using XML — how to

I would like to interact with an existing ORB using a Java client and jacorb.我想使用 Java 客户端和 jacorb 与现有 ORB 交互。 The idl is very simple and just specifies an XmlDocument: idl 非常简单,只指定一个 XmlDocument:

// xml.idl
module messaging
{
        interface Xml
        {
                typedef sequence <octet>  XmlDocument;
                void process_request ( inout XmlDocument document );
        };
};

I would like to validate certain objects using sysValidateRequest.xsd:我想使用 sysValidateRequest.xsd 验证某些对象:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:pt="http://www.example.com/sys4/services" targetNamespace="http://www.example.com/sys4/services" elementFormDefault="qualified" attributeFormDefault="unqualified">
            <xs:include schemaLocation="./sys_types.xsd"/>
            <xs:element name="sysValidateRequest">
                        <xs:annotation>
                                    <xs:documentation>validate sysObject</xs:documentation>
                        </xs:annotation>
                        <xs:complexType>
                                    <xs:sequence>
                                                <xs:element name="sysIdentifier" type="pt:sysIdentifierType" maxOccurs="unbounded">
                                                            <xs:annotation>
                                                                     <xs:documentation>sys object identifiers</xs:documentation>
                                                            </xs:annotation>
                                                </xs:element>
                                    </xs:sequence>
                                    <xs:attribute name="sid" type="pt:sysSessionIDType" use="required">
                                                <xs:annotation>
                                                            <xs:documentation>The session identifier which is unique to the session and the user who is logged in.</xs:documentation>
                                                </xs:annotation>
                                    </xs:attribute>
                                    <xs:attribute name="tid" type="pt:sysTransactionIdType" use="optional">
                                                <xs:annotation>
                                                            <xs:documentation>If an transaction id is sent with an request it will be sent back in an response.</xs:documentation>
                                                </xs:annotation>
                                    </xs:attribute>
                        </xs:complexType>
            </xs:element>
</xs:schema>

and sysValidateRespone.xsd和 sysValidateRespone.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:pt="http://www.example.com/sys4/services" targetNamespace="http://www.example.com/sys4/services" elementFormDefault="qualified" attributeFormDefault="unqualified">
            <xs:include schemaLocation="./sys_types.xsd"/>
            <xs:element name="sysGetKeysResponse">
                        <xs:annotation>
                                    <xs:documentation>info for key(s) for object in given registration</xs:documentation>
                        </xs:annotation>
                        <xs:complexType>
                                    <xs:choice>
                                                <xs:element name="context" type="pt:keySetWithKindType" maxOccurs="unbounded">
                                                            <xs:annotation>
                                                                        <xs:documentation>the given context of the retrieved keys</xs:documentation>
                                                            </xs:annotation>
                                                </xs:element>
                                                <xs:element name="sysException" type="pt:exceptionType">
                                                            <xs:annotation>
                                                                        <xs:documentation>On error, the exception structure with detailed error information is returned.</xs:documentation>
                                                            </xs:annotation>
                                                </xs:element>
                                    </xs:choice>
                                    <xs:attribute name="tid" type="pt:sysTransactionIdType" use="optional">
                                                <xs:annotation>
                                                            <xs:documentation>If an transaction id is sent with an request it will be sent back in an response.</xs:documentation>
                                                </xs:annotation>
                                    </xs:attribute>
                        </xs:complexType>
            </xs:element>
</xs:schema>

I generated java classes using我使用生成 java 类

idlj  -fall  xml.idl

and got the following classes并获得了以下课程

- XmlPackage
-- XmlDocumentHolder.java
-- XmlDocumentHelper.java
- XmlHelper.java
- _XmlStub.java
- XmlPOA.java
- XmlOperations.java
- Xml.java
- XmlHolder.java

I followed a couple of tutorials and what I now have is:我遵循了几个教程,现在我拥有的是:

import messaging.Xml;
import messaging.XmlHelper;
import messaging.XmlPackage.XmlDocumentHolder;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.omg.CORBA.ORB;

@SpringBootApplication
// @Service
public class sysImportApplication {

            //@Autowired
            //private ApplicationContext ctx;

            public static void main(String[] args) {
                        SpringApplication.run(sysImportApplication.class, args);

                        // Initialize the ORB
                        ORB orb = ORB.init(args, null);
                        org.omg.CORBA.Object ref = null;

                        // The object name passed in on the command line
                        String name = "corbaloc:iiop:sysHost01:50000/StandardImplName/sys/sys";

                        System.out.println("Attempting to lookup " + name);
                        ref = orb.string_to_object(name);

                        // System.out.println(orb.list_initial_services());
                        Xml xml = XmlHelper.narrow(ref);

                        // how to send XmlDocument now?
                        // and get response?

                        // XmlDocumentHolder h = new XmlDocumentHolder();
                        // xml.process_request(h);
            }
}

I need help how I send the xml document...我需要帮助我如何发送 xml 文档...

I the tutorials, the helper classes usually returns an instance of a remote object, eg在教程中,帮助类通常返回远程 object 的实例,例如

Account a = AccountHelper.narrow(ref)

on which I can call methods, eg我可以在其上调用方法,例如

a.setAmount(100)

Here the an xml is retured:这里返回了 xml:

Xml xml = Account

which has only methods:它只有方法:

xml.process_request(XmlDocumentHolder holder)

and XmlDocumentHolder only accepts byte arrays...和 XmlDocumentHolder 只接受字节 arrays...

Any help is appreciated!任何帮助表示赞赏!

Jan

you got only the function process_request() because it's the only you defined in your IDL file, and it get a holder object because you made your parameter an inout parameter.你只得到了 function process_request()因为它是你在 IDL 文件中定义的唯一一个,它得到一个holder object 因为你将参数设置为inout参数。

If you want to specify some new methods to your object you need to define them in your idl file first: and to not get a holder object in parameter you need to make it only in or out parameter.如果你想为你的 object 指定一些新的方法,你需要首先在你的 idl 文件中定义它们:并且没有在参数中获取holder object,你只需要将其设置为inout参数。 For example:例如:

module messaging
{
        interface Xml
        {
                typedef sequence <octet>  XmlDocument;
                void process_request ( in XmlDocument document ); // this method to process your object and make changes to it
                XmlDocument get_result();// this method to get your new xmldocument

// this methods are like the getters and setters and they are to easy to work with  
        };
};

ps: just an advice to enhance your code use the following method to initialize your orb ps:只是一个建议来增强你的代码使用下面的方法来初始化你的球体

        Properties props = new Properties();
        props.put("org.omg.CORBA.ORBInitialHost","localhost");
        props.put("org.omg.CORBA.ORBInitialPort",
                "4321");
        ORB orb = ORB.init((String[]) null, props);

this way help you to avoid adding args parameters before executing.这种方式可以帮助您避免在执行之前添加 args 参数。

Also you need to create a special project for your server so that you can define your methods and the way they treat your objects.您还需要为您的服务器创建一个特殊的项目,以便您可以定义您的方法以及它们处理对象的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM