/
EagleML Web Service - Create the Java Solution

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.

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)

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

    The result of EagleML object serialization:

Apache cxf Java Sample

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

  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:

  3. This node should be replaced with:

  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.

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:

  2. If you run the application, the following SOAP envelope will be generated:

  3. After the Message Center completes the task, the TSR message will be sent back and our application receives the following tsr message.