EagleML Web Service - Create the Java Solution

This page will walk you thru creating the Java solution.

Click the zip archive below to download the code described on this page.

Steps to Create the Java Solution

  1. Create the Java project application.
  2. Add xsd schema to the project and jaxb library.


  3. To generate classes from the XSD, right click on the eagleml-main-2-0.xsd, then choose Generate and then JAXB Classes.
    A dialog window will be displayed.
  4. Enter the package name and click Finish.

Note

The classes generation takes some time.

Method for EagleML Object Creation

 //WarehouseTransactionMessage
 
             ObjectFactory objFactory = new ObjectFactory();
             WarehouseTransactionMessage whTransMessage = new WarehouseTransactionMessage();
              whTransMessage.setEaglemlVersion("2-0");
              whTransMessage.setEaglemlType(EagleMLMessageTypeEnum.WAREHOUSE_TRANSACTION_MESSAGE);
 
             //messageid
            TransactionMessageHeader transMessageHeader = new TransactionMessageHeader();
            
             MessageId messageId = new MessageId();
             messageId.setMessageIdScheme("1000");        //need some key generator so Message ID will be unique
             transMessageHeader.setMessageId(messageId);
             //sendBy
             MessageAddress  messageAddress = new MessageAddress();
             messageAddress.setValue("MCAP");    //Client, trading desk, MCAP has to be hard-coded
             transMessageHeader.setSentBy(messageAddress);
 
             //creationTimestamp
             Date date2 = new Date();
             XMLGregorianCalendar gcdate2;
             gcdate2 = dateToXMLGregorianCalendar(date2); 
             transMessageHeader.setCreationTimestamp(gcdate2);
             whTransMessage.setHeader(transMessageHeader);
             
             
            wtrade = new WarehouseTrade();
            String TransactionCode = "303";
            switch (Integer.parseInt(TransactionCode)) {
                   case 303 : wtrade.setTransactionCode("BUY");  
                                        break;
                   case 304 : wtrade.setTransactionCode("SELL"); 
                                        break; 
            }
            wtrade.setEntityId("123456");            
 
            //Financial Instrument
 
            InstrumentId instrumentid =  new InstrumentId();
            instrumentid.setValue("ins234");
            wtrade.setCusip(instrumentid);
 
            //Broker
            wtrade.setBrokerCode("valv");
 
            //Dates
 
            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd"); 
            XMLGregorianCalendar gcdate;
            Date date = (Date)formatter.parse("19981123");
            gcdate = dateToXMLGregorianCalendar(date);
            date = (Date)formatter.parse("20101023"); 
            gcdate = dateToXMLGregorianCalendar(date);
            wtrade.setSettlementDate(gcdate);
                //Quantity
            wtrade.setQuantityPre(new BigDecimal("11224333"));
            //Commission Amount
            wtrade.setCommissionAmount(new BigDecimal("4567567455234"));
            //Price
            wtrade.setPrice(new BigDecimal("45645645654655"));
            //Exchange Rate -
            //wtrade.setTradeExchangeRate(new BigDecimal(strLine.substring(147,165).trim()));
            //Traded Currency
            wtrade.setBaseCurrency("USD");
            //Transaction ID
            //wtrade.setTransactionId(strLine.substring(173,187));
    //WAREHOUSE TRANSACTION
 
            WarehouseTransaction whTransaction = new WarehouseTransaction();
            TransactionHeader transHeader = new TransactionHeader();
            transHeader.getObjectType().add(ObjectTypeEnum.WAREHOUSE_TRADE);
            whTransaction.setHeader(transHeader);
            JAXBElement<WarehouseObject> je = objFactory.createWarehouseObject(wtrade);
            whTransaction.setWarehouseObject(je);
            whTransMessage.getWarehouseTransaction().add(whTransaction);

Serialize Object to String

Use the following steps to serialize: 

  1. Transform message to EagleML.

    JAXBElement<EagleDocument> eagleDocument = objFactory.createEagleML(whTransMessage);
  2. Marshal object to byte array.

    PrintXMLTrade(eagleDocument)
    public static void PrintXMLTrade(JAXBElement<EagleDocument> ed) {          
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try   {
             JAXBContext context = JAXBContext.newInstance(EagleDocument.class, ObjectFactory.class);
             Marshaller marshaller = context.createMarshaller();
             marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
             marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.eagleinvsys.com/2011/EagleML-2-0 eagleml-main-2-0.xsd");
             marshaller.marshal(ed, baos);
            }
            catch (JAXBException e) {
            e.printStackTrace();
            }
            System.out.println("Trade in XML format:");
            System.out.println("----------------------------------------------------------");
            System.out.println(baos);
    }

    The above code uses the following method to create the date:

    public static XMLGregorianCalendar dateToXMLGregorianCalendar(Date date) {
                            XMLGregorianCalendar _date;                           
                            try {
                                                   GregorianCalendar c = new GregorianCalendar();
                                c.setTime(date);                          
                                                   _date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
                                                   return _date;                                      
                            } catch (DatatypeConfigurationException e) {
                                                   e.printStackTrace();
                            }
                            return null;
    }

    The result of EagleML object serialization:

Apache cxf Java Sample

  1. Generate classes from the xsd using cxf wsdl2java command:

    wsdl2java -d [classes folder path] -verbose -client file:/[path to eaglemlws2-0.wsdl]
  2. In the wsdl, change the path to a schemas’ storage in wsdl. 
    The node marked in yellow below should be changed in the following fragment of the wsdl file:

    <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:eagleml="http://www.eagleinvsys.com/2011/EagleML-2-0" xmlns:tns="http://www.eagleinvsys.com/2011/wsdl/EagleML-2-0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" wsdl:name="eaglemlws" targetNamespace="http://www.eagleinvsys.com/2011/wsdl/EagleML-2-0" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
      <wsdl:documentation>Eagle ML Definitions</wsdl:documentation>
      <wsdl:types>
        <xsd:schema targetNamespace="http://www.eagleinvsys.com/2011/wsdl/EagleML-2-0">
          <xsd:import schemaLocation=" %host%/eaglemlxsd/eagleml-main-2-0.xsd" namespace="http://www.eagleinvsys.com/2011/EagleML-2-0" />
  3. This node should be replaced with:

    <xsd:import schemaLocation="path_to_schemas_storage/eagleml-main-2-0.xsd" namespace="http://www.eagleinvsys.com/2011/EagleML-2-0" />
  4. A path_to_schemas_storage may be an absolute path or a relative one. In the below case, the path shall be specified relatively to the location of wsdl file being used.

  5. Create the java project, add generated classes to the project and add the following code to generate EagleML message.

    WSReferenceTransactionMessage trmessage=new WSReferenceTransactionMessage();
                 ReferenceTransactionMessage rt= new ReferenceTransactionMessage();
                 trmessage.setEagleML(rt);
                 
                 rt.setEaglemlType(EagleMLMessageTypeEnum.REFERENCE_TRANSACTION_MESSAGE);
                 rt.setEaglemlVersion("2-0");
                 TransactionMessageHeader header= new TransactionMessageHeader();
                 MessageId mi= new MessageId();
                 mi.setValue("ID:SMFLOAD02");
                 header.setMessageId(mi);
                 MessageAddress ma=new MessageAddress();
                 ma.setValue("user");
                 header.setSentBy(ma);
                 ma=new MessageAddress();
                 ma.setValue("http://www.eagleinvsys.com/eagle_ml-2-0_default_cm_control_message");
                 header.getSendTo().add(ma);
                 GregorianCalendar c = new GregorianCalendar();
                    c.setTime(new Date());    
                 XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
                 header.setCreationTimestamp(date);         
                 rt.setHeader(header);
                 TaskIdentifier ti=new TaskIdentifier();
                 CorrelationId ci=new CorrelationId();
                 ci.setCorrelationIdScheme("correlationIdScheme");
                 ci.setValue("tmp20150611_002");
                 ti.setCorrelationId(ci);
                 
                 ci=new CorrelationId();
                 ci.setCorrelationIdScheme("businessTaskIdScheme");
                 ci.setValue("SYNC_SMFload");
                 ti.setBusinessTaskId(ci);
                 rt.setTaskIdentifier(ti);
                 ReferenceTransaction rtm=new ReferenceTransaction();
                 TransactionHeader th=new TransactionHeader();
                 rtm.setHeader(th);
                 th.getObjectType().add(ObjectTypeEnum.GENERIC_SMF);
                 GenericSMF cc=new GenericSMF();
                 cc.setSourceName("BASELINE");
                 cc.setUpdateSource("MCADMIN");
                 com.eagleinvsys._2011.eagleml_2_0.ObjectFactory of=new com.eagleinvsys._2011.eagleml_2_0.ObjectFactory();
                 JAXBElement<GenericSMF> je=of.createGenericSMF(cc);              
                 rtm.setReferenceObject(je);
                 
                 rt.getReferenceTransaction().add(rtm);

The serialization to xml string is the same as for the jaxb sample.

Send Message

To send the message, follow these steps:

  1. Add the following code:

    EagleMLWebService ew= new EagleMLWebService();
    EagleMLPortType port =ew.getEagleMLPort();
    BindingProvider bp = (BindingProvider) port; 
    String endpointURL = "https://[region_name].eagleaccess.com/EagleMLWebService20"; 
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                       endpointURL);
    bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY,"****");
    bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY,"****");
    WSTaskStatusResponse tsr= port.loadReference(trmessage);
  2. If you run the application, the following SOAP envelope will be generated:

    <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
    <ns3:referenceTransactionMessage xmlns:ns2="http://www.eagleinvsys.com/2011/EagleML-2-0" xmlns:ns3="http://www.eagleinvsys.com/2011/wsdl/EagleML-2-0">
    <EagleML eaglemlType="ReferenceTransactionMessage" eaglemlVersion="2-0">
    <ns2:header>
    <ns2:messageId>ID:SMFLOAD02</ns2:messageId>
    <ns2:sentBy>user</ns2:sentBy>
    <ns2:sendTo>http://www.eagleinvsys.com/eagle_ml-2-0_default_cm_control_message</ns2:sendTo>
    <ns2:creationTimestamp>2015-06-22T22:18:35.770+03:00</ns2:creationTimestamp>
    </ns2:header>
    <ns2:taskIdentifier>
    <ns2:correlationId correlationIdScheme="correlationIdScheme">tmp20150611_002</ns2:correlationId>
    <ns2:businessTaskId correlationIdScheme="businessTaskIdScheme">SYNC_SMFload</ns2:businessTaskId>
    </ns2:taskIdentifier>
    <synchronousExecution>yes</synchronousExecution>
    <ns2:referenceTransaction>
    <ns2:header>
    <ns2:objectType>GenericSMF</ns2:objectType>
    </ns2:header>
    <ns2:genericSMF>
    <ns2:sourceName>BASELINE</ns2:sourceName>
    <ns2:updateSource>MCADMIN</ns2:updateSource>
    …
    </ns2:genericSMF>
    </ns2:referenceTransaction>
    </EagleML>
    </ns3:referenceTransactionMessage>
    </S:Body>
    </S:Envelope>
  3. After the Message Center completes the task, the TSR message will be sent back and our application receives the following tsr message.

    <ns3:taskStatusResponse xmlns:ns3="http://www.eagleinvsys.com/2011/wsdl/EagleML-
    2-0">
    <EagleML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" eaglemlType="TaskStatusResponse" eaglemlVersion="2-0" xsi:schemaLocation="http://www.eagleinvsys.com/2011/EagleML-2-0 eagleml-main-2-0.xsd" xsi:type="eag1:TaskStatusResponse">
    <eag1:header xmlns:eag1="http://www.eagleinvsys.com/2011/EagleML-2-0">
    <eag1:messageId>1E87G1U41XVATM3N</eag1:messageId>
    <eag1:sentBy>http://www.eagleinvsys.com/</eag1:sentBy>
    <eag1:sendTo>http://mmm.com/mmm</eag1:sendTo>
    <eag1:creationTimestamp>2015-06-23T08:07:05-05:00</eag1:creationTimestamp>
    </eag1:header>
    <eag1:statusItem xmlns:eag1="http://www.eagleinvsys.com/2011/EagleML-2-0">
    <eag1:taskIdentifier>
    <eag1:correlationId correlationIdScheme="correlationIdScheme">26DAE401E60DB269</eag1:correlationId>
    <eag1:businessTaskId correlationIdScheme="businessTaskIdScheme">ASYNC_SMFIST_EXTRACT</eag1:businessTaskId>
    </eag1:taskIdentifier>
    <eag1:status>FAILED</eag1:status>
    <eag1:severityCode>1</eag1:severityCode>
    <eag1:reason>
    <eag1:reasonTypeEnum>ERROR</eag1:reasonTypeEnum>
    <eag1:reasonCode>1</eag1:reasonCode>
    <eag1:description>Data query is not executed. ErrorCode\5C3A -2. ErrorMessage\5C3A Error executing the request\5C3ACannot create a row of size 8437 which is greater than the allowable maximum row size of 8060.</eag1:description>
    </eag1:reason>
    </eag1:statusItem>
    </EagleML>
    </ns3:taskStatusResponse>