CORBA messaging using XML -- how to

304 views Asked by At

I would like to interact with an existing ORB using a Java client and jacorb. The idl is very simple and just specifies an 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:

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

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

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

I the tutorials, the helper classes usually returns an instance of a remote object, e.g.

Account a = AccountHelper.narrow(ref)

on which I can call methods, e.g.

a.setAmount(100)

Here the an xml is retured:

Xml xml = Account

which has only methods:

xml.process_request(XmlDocumentHolder holder)

and XmlDocumentHolder only accepts byte arrays...

Any help is appreciated!

Jan

1

There are 1 answers

0
GUENANOU ABDELKRIM On

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.

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

p.s: just an advice to enhance your code use the following method to initialize your 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);

this way help you to avoid adding args parameters before executing.

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.