After the successful installation of the OmniFlow Server and all the pre-requisite steps, the user has to send the request to the server.
The request is send to the OmniFlow Server in XML format through a socket connection to the OmniFlow Server Port.
For communicating with the OmniFlow Server the following XML format is used. This section explains all the mandatory tags which have to be sent for each call. The tags can further increase as per the requirement.
<? Xml Version="1.0"? >
<WMConnect_Input>
<Option>WMConnect</Option>
<EngineName></EngineName>
<SessionId></SessionId>
</WMConnect_Input>
Tag |
Description |
<Option>...</Option> |
This tag includes the case sensitive call name. |
<EngineName></EngineName> |
It is the cabinet or database name on which the operations are made. |
<SessionId></SessionId> |
It is the current session id of the logged in user. |
<?Xml Version="1.0"?>
<WMConnect_Output>
<Option>WMConnect</Option>
<Exception>
<MainCode>18</MainCode>
<SubErrorCode>0</SubErrorCode>
<TypeOfError>TEMPORARY</TypeOfError>
<Subject>No more records. </Subject>
<Description>null</Description>
</Exception>
</WMConnect_ Output >
Tag |
Description |
<Option>...</Option> |
This tag includes the case sensitive call name. |
<MainCode>...</MainCode> |
This tag includes the error code specified by WAPI. |
SubErrorCode>..</SubErrorCode> |
This tag includes the error code occurred during calling. |
<TypeOfError>...</TypeOfError> |
This tag includes the type of errors. It can be Temporary or Permanent. |
<Subject>..</Subject> |
This tags includes the error description. |
These are the following steps to run the sample code:
1. The following sample code is provided for the test driver to access the exposed API calls. This code allows you to connect to the existing OmniFlow Server and then disconnect from it.
import java.io.*; import java.net.*; public class TestDriver { WFSDataOutputStream wfout; WFSDataInputStream wfin;
public static void main(String[] args) { TestDriver tester = new TestDriver(); int sessionId; try { System.out.println("Omniflow Server IP:"); BufferedReader inBuf = new BufferedReader(new InputStreamReader(System.in)); String str_srvrIP = inBuf.readLine(); System.out.println("Omniflow Server Port:"); String str_srvrPort = inBuf.readLine(); int m_srvrPort = Integer.parseInt(str_srvrPort); boolean success = tester.connectToServer( str_srvrIP , m_srvrPort); if (success) { System.out.println("Omniflow Server Connection successful"); System.out.println("Workflow Engine:"); String str_engine = inBuf.readLine(); System.out.println("Username:"); String str_userName = inBuf.readLine(); System.out.println("Password:"); String str_password = inBuf.readLine();
String str_inxml = "<? Xml Version=\"1.0\"? >\n" +"<WMConnect_Input>\n" +"<Option>WMConnect</Option>\n" +"<EngineName>"+str_engine+"</EngineName>\n" +"<Particpant>\n" +"<Name>"+str_userName+"</Name>\n" +"<Password>"+str_password+"</Password>\n" +"<Scope>USER</Scope>\n" +"<ParticipantType>U</ParticipantType>\n" +"</Participant>\n" +"</WMConnect_Input>"; System.out.println("Input XML for WMConnect."); System.out.println(str_inxml); String str_outxml = tester.execute(str_inxml); System.out.println("****************************************************"); String str_temp = tester.parseXML(str_outxml, "MainCode"); int mainCode = Integer.parseInt(str_temp); if (mainCode == 0) { str_temp = tester.parseXML(str_outxml, "SessionID"); sessionId = Integer.parseInt(str_temp); System.out.println("WMConnect successful. Your SessionID is "+sessionId); System.out.println(str_outxml); System.out.println("****************************************************");
System.out.println("****************************************************"); System.out.println(str_inxml); System.out.println("****************************************************"); str_outxml = tester.execute(str_inxml); System.out.println("OutputXML "); System.out.println(str_outxml);
System.out.println("****************************************************");
str_inxml = "<? Xml Version=\"1.0\"?>" +"<WMDisConnect_Input>" +"<Option>WMDisConnect</Option>" +"<EngineName>"+str_engine+"</EngineName>" +"<SessionID>"+sessionId+"</SessionID>" +"</WMDisConnect_Input>";
str_outxml = tester.execute(str_inxml); System.out.println("Input XML for WMDisConnect."); System.out.println(str_inxml); System.out.println("****************************************************"); System.out.println("OutputXML for WMDisConnect "); System.out.println(str_outxml);
System.out.println("****************************************************"); }else{ System.out.println("WMConnect failed. For Details please see the following xml."); System.out.println(str_outxml); System.out.println("****************************************************"); } } }catch(IOException e){ System.out.println("Error : "+e.toString()); }catch(NumberFormatException e){ System.out.println("Invalid value for Server Port: "+e.toString()); } } String parseXML(String inXml , String tag ) { String parseXml = inXml.toUpperCase(); int startIndex = 0; int endIndex = 0;
startIndex = parseXml.indexOf("<"+tag.toUpperCase()+">"); endIndex = parseXml.indexOf("</"+tag.toUpperCase()+">"); if (startIndex > 0 && endIndex > 0) return inXml.substring(startIndex+tag.length()+2 , endIndex ); else return null; } boolean connectToServer( String ip , int port){ try { String str_srvrIP = ip; int m_srvrPort = port; Socket s = new Socket (str_srvrIP , m_srvrPort); wfout = new WFSDataOutputStream ( s.getOutputStream()); wfin = new WFSDataInputStream ( s.getInputStream() ); }catch(UnknownHostException e){ System.out.println("Unknown Host"); return false; }catch(IOException e){ System.out.println("Connect Failed"); return false; } return true; } String execute( String inXml ) { try { wfout.writeObject(inXml); return wfin.readObject(); }catch(IOException e){ System.out.println("Error : "+e.toString()); return ""; } } } class WFSDataInputStream { private DataInputStream obj_din; public WFSDataInputStream(InputStream in) { obj_din = new DataInputStream(in); } public WFSDataInputStream(InputStream in, boolean flush) { obj_din = new DataInputStream(in); } public String readObject() throws IOException { int dataRead = obj_din.readInt(); byte[] input_buffer = new byte[dataRead]; if (dataRead > 0){ int bytes_received = -1; int off = 0; do{ bytes_received = obj_din.read(input_buffer,off,dataRead); if(bytes_received == -1) break; off += bytes_received; dataRead -= bytes_received; } while (dataRead > 0); } return new String(input_buffer, "8859_1"); }
public void close() throws IOException { obj_din.close(); } protected void finalize() throws Throwable { if(obj_din != null) { try { obj_din.close(); }catch(Exception ignored) {} obj_din = null; } } private int readInt()throws IOException { return obj_din.readInt(); } private void read(byte[] bytebuffer, int startPos, int len)throws IOException { obj_din.read(bytebuffer, startPos, len); } } class WFSDataOutputStream { private DataOutputStream obj_dout; private boolean b_autoflush; public WFSDataOutputStream(OutputStream out) { obj_dout = new DataOutputStream(out); b_autoflush = true; } public WFSDataOutputStream(OutputStream out, boolean flush) { obj_dout = new DataOutputStream(out); b_autoflush = flush; } public void writeObject(String str_response) throws IOException { int buffer_length = str_response.length(); byte[] output_buffer = new byte[buffer_length]; output_buffer = str_response.getBytes("8859_1"); obj_dout.writeInt(buffer_length); obj_dout.write(output_buffer , 0, buffer_length); if(b_autoflush){ flush(); } } public void flush() throws IOException { obj_dout.flush(); } public void close() throws IOException { obj_dout.flush(); obj_dout.close(); }
protected void finalize() throws Throwable { if(obj_dout != null) { try { obj_dout.close(); }catch(Exception ignored) {} obj_dout = null; } } }
|
2. There is a highlighted portion in the sample code.
str_inxml = "<? Xml Version=\"1.0\"?>\n" +"<WFGetExternalInterfaceList_Input>" +"<Option>WFGetExternalInterfaceList</Option>\n" +"<EngineName>"+str_engine+"</EngineName>\n" +"<SessionID>"+sessionId+"</SessionID>\n" +"<ProcessDefinitionId>3</ProcessDefinitionId>\n" +"</WFGetExternalInterfaceList_Input>"; |
This is the sample XMLInput for WFGetExternalInterfaceList_Input call.
For accessing any other call you just need to replace this section with the sample code given along with each call.
3. Save the test driver code as "TestDriver.java" file.
4. Compile the code and then try to execute it on the existing database.
Note:This sample code is the JAVA based implementation for accessing the API's. You can build your own socket connection code and call the API's |
Copy the Test Driver Code and save it as "TestDriver.java" file. Compile it to create class file named "TestDriver".
Try to connect with the existing OmniFlow server.
You can pass the Input XML for the specific call in order to retrieve the output from the OmniFlow Server.