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



我想使用 Java 客户机和 jacorb 与现有的 ORB 进行交互。 idl 非常简单,只指定一个 XmlDocument:

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

我想使用 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>

和 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>

我使用

idlj  -fall  xml.idl

并获得了以下课程

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

我遵循了几个教程,我现在拥有的是:

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);
}
}

我需要帮助如何发送 xml 文档...

在教程中,辅助类通常返回远程对象的实例,例如

Account a = AccountHelper.narrow(ref)

我可以调用方法,例如

a.setAmount(100)

在这里,一个 xml 被重新定义:

Xml xml = Account

其中只有方法:

xml.process_request(XmlDocumentHolder holder)

和 XmlDocumentHolder 只接受字节数组...

任何帮助不胜感激!

一月

你只得到了process_request()函数,因为它是你在 IDL 文件中定义的唯一函数, 它得到一个holder对象,因为你将参数设置为inout参数。

如果要为对象指定一些新方法,则需要先在idl文件中定义它们:并且要在参数中不获取holder对象,则需要将其仅inout参数。例如:

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  
};
};

附言: 只是增强代码的建议使用以下方法来初始化您的 ORB

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);

这种方式可帮助您避免在执行之前添加 args 参数。

此外,您还需要为服务器创建一个特殊项目,以便您可以定义您的方法以及它们处理对象的方式。

相关内容

  • 没有找到相关文章

最新更新