Technical Overview Emif Connector Copyright 1991. Synchro Sistemas de Informação Ltda Technical Overview Emif Connector 1
Index 1. Revision... 3 2. Scope... 4 3. Target Audience... 4 4. Technical Overview... 4 4.1. Process Model... 5 4.2. Communication Protocol... 6 4.3. Available Services... 6 4.3.1. Order Calculation... 6 4.3.1.1. List of Calculations Commands... 7 4.3.1.2. Sample XML s... 7 4.3.2. Component Availability Test... 8 4.3.2.1. Request XML... 8 4.3.2.2. Response XML... 8 4.4. Logging... 9 Copyright 1991. Synchro Sistemas de Informação Ltda Technical Overview Emif Connector 2
1. Revision Revision Date Document Version Executor Subject 08/10/2010 1.0 Alexandre A. souza Document Creation 08/10/2012 1.1 Alexandre A. Souza 11/03/2013 1.2 Alexandre A. Souza New Service inclusion. (Component Availability Test) New Service inclusion (CALCULATE2) Copyright 1991. Synchro Sistemas de Informação Ltda Technical Overview Emif Connector 3
2. Scope The scope of this document is to provide a technical overview of the product Emif Connector. 3. Target Audience Technicians and software architects. 4. Technical Overview The Emif Connector is a java-based project that works as a server in a specific computer. Basically the connector waits until receiving a request (XML) from the client trough HTTP or sockets TCP/IP protocols, processes the request and then returns the response to the client. The Emif Connector server runs on a specific computer and has a socket that is bound to a specific port number. The server just waits, listening to the socket for a client to make a connection request. On the client-side: The client knows the hostname of the machine on which the server is running and the port number on which the server is listening. To make a connection request, the client tries to rendezvous with the server on the server's machine and port. The client also needs to identify itself to the server so it binds to a local port number that it will use during this connection. This is usually assigned by the system. If everything goes well, the server accepts the connection. Upon acceptance, the server gets a new socket bound to the same local port and also has its remote endpoint set to the address and port of the client. It needs a new socket so that it can continue to listen to the original socket for new connection requests while tending to the needs of the connected client. On the client side, if the connection is accepted, a socket is successfully created and the client can use the socket to communicate with the server and send the XML files. Copyright 1991. Synchro Sistemas de Informação Ltda Technical Overview Emif Connector 4
4.1. Process Model 1. After successfully connect to the socket server the customer application sends a request ( a XML file) trough a HTTP/Socket protocol; 2. The connector will receive the XML and it will parse it to define witch action it should take; 3. After decided witch action to take, the connector process the requested service; 4. After processing the requested service the connector sends a response back (also XML file) to the requester; 5. If an error occurs during the XML parse the connector sends a response (XML message) with the description of the error. Copyright 1991. Synchro Sistemas de Informação Ltda Technical Overview Emif Connector 5
4.2. Communication Protocol The Communication between the Emif Connector and the client is done trough sockets TCP/IP/HTTP protocol. Example of implementation: Language Functionality Code Example Visual Basic WinSocket Winsock1.RemoteHost = 172.25.3.21 Winsock1.RemotePort = 8080 Winsock1.Connect Winsock1.SendData <? Xml version=1.0. (etc) Java Java.net.Socket Socket s = new Socket( 172.25.3.21, 8080); OutputStreamWriter o = new OutputStreamWriter(s.getOutputStream()); o.write( <? Xml version=1.0. (etc) ); 4.3. Available Services 4.3.1. Order Calculation The Emif Connector has a set of predefined services that the customer can request. The customer will define witch service should be processed in an attribute tag in the request XML file. Example 1: <?xml version='1.0' encoding='utf-8'?> <ORDERS> <ORDER CMD="update"> <DOF_IMPORT_NUMERO>NFE120</DOF_IMPORT_NUMERO> <INFORMANTE_EST_CODIGO>07671092000180</INFORMANTE_EST_CODIGO> <SERIE_SUBSERIE>1</SERIE_SUBSERIE> </ORDER> </ORDERS> In the XML above the value of the attribute CMD determines that the connector should process an UPDATE of the Order (Nota Fiscal). Example 2: <?xml version='1.0' encoding='utf-8'?> <ORDERS> <ORDER CMD="select"> <DOF_IMPORT_NUMERO>TESTE0011</DOF_IMPORT_NUMERO> <INFORMANTE_EST_CODIGO>SYNCHRO</INFORMANTE_EST_CODIGO> <SERIE_SUBSERIE/> </ORDER> </ORDERS> In the XML above the value of the attribute CMD determines that the connector should SELECT an Order (Nota Fiscal) from the database using the unique identifiers Copyright 1991. Synchro Sistemas de Informação Ltda Technical Overview Emif Connector 6
DOF_IMPORT_NUMERO and INFORMANTE_EST_CODIGO and retrieve the value of the field SERIE_SUBSERIE. In this case the response of the server to the requester will be: <?xml version="1.0" encoding="utf-8"?> <ORDERS> <ORDER> <DOF_IMPORT_NUMERO>NFE120</DOF_IMPORT_NUMERO> <INFORMANTE_EST_CODIGO>07671092000180</INFORMANTE_EST_CODIGO> <SERIE_SUBSERIE>1</SERIE_SUBSERIE> </ORDER> </ORDERS> The result of the select is the value 1 in the tag SERIE_SUBSERIE. 4.3.1.1. List of Calculations Commands CMD Value Description Response INSERT Insert a Nota Fiscal record into S the database UPDATE Update a Nota Fiscal of the S database (using the unique identifiers given in the XML) DELETE Delete a Nota Fiscal of the S database (using the unique identifiers given in the XML) PRINT Print the Nota Fiscal S/A REPRINT Reprint the Nota Fiscal S/A CALCULATE Calculate the Nota Fiscal S INSERTORUPDATE The connector tries to insert S the Nota Fiscal in the database, if a Oracle Unique Key error occurs the connector will update the record. CANCEL Cancel the Nota Fiscal S CALCULATE2 Tax Calculation Simulation S S = Synchronous A = Asynchronous Almost all the services are synchronous, except the PRINT and REPRINT services. For these services there is a configurable option to enable the Asynchronous response. These services can be asynchronous because a print/reprint service can take even minutes to be completed and the connection can be lost before the Emif Connector responses the confirmation message. When the Asynchronous option is enabled, the Emif Connector sends a confirmation message even before the service is finished. After sending the instant confirmation message the connector starts monitoring the database to identify whether the print/reprint service is finished. Once the service is finished the Emif Conector will connect to the customer application and send a confirmation message of the print/reprint request. 4.3.1.2. Sample XML s Copyright 1991. Synchro Sistemas de Informação Ltda Technical Overview Emif Connector 7
See file Sample_XMLS.txt. Sample_XMLs.txt 4.3.2. Component Availability Test This service was created to check if the component is up and running and also check the database connection. If the component is down (not working) there will be no communication and due to this there will be no response. 4.3.2.1. Request XML The example below is the request XML. <?xml version='1.0' encoding='utf-8'?> <ISALIVE> <SERVER/> <DBCONNECTION/> </ISALIVE> 4.3.2.2. Response XML The example below is a response XML in case of a successfully test, <?xml version="1.0" encoding="utf-8"?> <ISALIVE> <SERVER> <STATUS>TRUE</STATUS> </SERVER> <DBCONNECTION> <STATUS>TRUE</STATUS> </DBCONNECTION> </ISALIVE> Copyright 1991. Synchro Sistemas de Informação Ltda Technical Overview Emif Connector 8
In case of an error, there will be additional tags, like the example below. <?xml version="1.0" encoding="utf-8"?> <ISALIVE> <SERVER> <STATUS>TRUE</STATUS> </SERVER> <DBCONNECTION> <STATUS>FALSE</STATUS> <ERROR>NOT CONNECTED - Please check Etax.log for more details.</error> </DBCONNECTION> </ISALIVE> The Etax.log is the component log, and should always be checked in case of errors. 4.4. Logging The Emif Connector will create detailed Logs files of all process. The logs can be activated/deactivated according to its criticality. There is also the option to send an email. For example it s possible to send an email for the critical errors and to create log files for the warnings. The log level and email configuration are done manually in a xml file called logconfig.xml. Copyright 1991. Synchro Sistemas de Informação Ltda Technical Overview Emif Connector 9