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
Create the Java project application.
Add xsd schema to the project and jaxb library.
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.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:Â
Transform message to EagleML.
JAXBElement<EagleDocument> eagleDocument = objFactory.createEagleML(whTransMessage);
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
Generate classes from the xsd using cxf wsdl2java command:
wsdl2java -d [classes folder path] -verbose -client file:/[path to eaglemlws2-0.wsdl]
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" />
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" />
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.
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:
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);
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>
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>