/** This program shows how to drive the Internet Business Logic system from a Java client, so that you can add your own user interface, graphics and so on. You can also use this program to make the Internet Business Logic system part of your Service Oriented Architecture. For information on the Internet Business Logic system, including how to drive it using your browser, please point a browser to www.reengineeringllc.com Use of this program, and your derivatives of it, to drive an Internet Business Logic server in shared mode is free, and is subject to the terms and conditions that apply to the demo ID as set out in www.reengineeringllc.com/terms_and_conditions.html . To use this program, please install it on your own machine. Please also install http://www.reengineeringllc.com/stdin.java . Then compile the two programs using commands like "javac stdin.java" and "javac iblClient1.java". (Depending on your setup, you may need to type "javac -cp . " and then the file name.) Next, start the program using "java iblClient1". (Depending on your setup, you may need to type "java -cp . iblClient1") Then, type a number from 1 thru 23 at the '>>' prompt You should see the program posting requests in http, and getting results back in simple xml. You can capture further http requests by running the IBL from your browser, using the ID called 'IBLItest' with the password 'author'. At the foot of each page you will see an http request that you can copy-paste into your own client program. Please direct comments and questions to internet.business.logic@gmail.com . If you would like to share extensions you make to this stub, please let us know, and we will consider placing them on our web site -- with credit to you of course. Version 20080710 Please check www.reengineeringllc.com/iblClient1.java for updates to this program. **/ import java.net.*; import java.io.*; import stdin.*; public class iblClient1 { public static void main(String[] args) { try { int sessionID = doGetSessionID(); int commandNum; while (true) { System.out.println(""); System.out.print(">> "); commandNum=stdin.getInt(); if (commandNum<0) return; doPost(commandNum,sessionID); } } catch (Exception e) { e.printStackTrace(); } } public static int doGetSessionID() { int sid = 0; try { String [] commentary; String [] postToIBLI; commentary = new String[1]; postToIBLI = new String[1]; commentary[0] = "Log in -- Returns a session number"; postToIBLI[0] = "login=login1&uid=IBLItest&user_password=author®_name=®_affiliation=®_phone=®_email=®_uid=®_pw1=®_pw2="; //Create socket String hostname = "www.reengineeringllc.com"; int port = 80; InetAddress addr = InetAddress.getByName(hostname); Socket sock = new Socket(addr, port); //Send header String path = "/cgi-bin/IBLI"; BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(),"iso-8859-1")); // You can use "UTF8" for compatibility with the Microsoft virtual machine. wr.write("POST " + path + " HTTP/1.0\r\n"); wr.write("Host:"+ hostname +"\r\n"); wr.write("Content-Length: " + postToIBLI[0].length() + "\r\n"); wr.write("Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"); wr.write("\r\n"); System.out.println(""); System.out.println("-------- " + commentary[0] + " --------"); System.out.println("POST=\"" + postToIBLI[0] + "\""); //Send data wr.write(postToIBLI[0]); wr.flush(); // Response BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream())); System.out.print("REPLY="); String line; int count; count=0; while((line = rd.readLine()) != null) { count ++; if (count>6) { if (count==7) { try { sid = Integer.parseInt(line); } catch( Exception e ) { System.out.println("exception sid =" + sid); } } else System.out.println(line); } } wr.close(); } catch (Exception e) { e.printStackTrace(); } return(sid); } public static void doPost(int commandNum,int sid) { try { String [] commentary; String [] postToIBLI; commentary = new String[25]; postToIBLI = new String[25]; commentary[0] = "Log in -- Returns a session number"; postToIBLI[0] = "login=login1&uid=IBLItest&user_password=author®_name=®_affiliation=®_phone=®_email=®_uid=®_pw1=®_pw2="; commentary[1] = "Load an agent that is stored in a file on the server and return the question menu"; postToIBLI[1] = "uid=IBLItest&sid="+ sid +"&start=+++&choices=Choose+an+Agent+and+Go+to+its+Question+Menu....&selected_agent=IBLItest1&typed_in_agent_name="; commentary[2] = "Ask a question"; postToIBLI[2] = "i=1&j=7&question=rule+two+has+item+some-x+some-y++&uid=IBLItest&sid="+ sid +"&qmenu=IBLItest1&choices=Select+a+Question+to+Ask&free_english_typed_in="; commentary[3] = "Get an explanation"; postToIBLI[3] = "uid=IBLItest&sid="+ sid +"&answer=IBLItest1&choices=Get+an+Explanation+of+the+Selected+Line&1%3A1=XX&1%3A2=11&expl=2&2%3A1=YY&2%3A2=2.2"; commentary[4] = "Load an Agent from the java client and show the Qmenu"; postToIBLI[4] = "uid=IBLItest&sid="+ sid +"&agent=IBLItest1&choices=Go+to+the+Question+Menu&f1=%0D%0Arule+one+has+item+eg-x+eg-y%0D%0A---------------------------%0D%0Arule+two+has+item+eg-x+eg-y%0D%0A&f2=%0D%0Atable+has+item+eg-x+eg-y%0D%0A---------------------------%0D%0Arule+one+has+item+eg-x+eg-y%0D%0A&p2=%0D%0Atable+has+item+eg-x+eg-y%0D%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0D%0A++++++++++++++++XX+++11%0D%0A++++++++++++++++YY+++2.2%0D%0A"; commentary[5] = "Load an Agent from the java client and show the Agent"; postToIBLI[5] = "uid=IBLItest&sid="+ sid +"&agent=IBLItest1&choices=View+or+Change+the+Agent&p2=%0D%0Atable+has+item+eg-x+eg-y%0D%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0D%0A++++++++++++++++XX+++11%0D%0A++++++++++++++++YY+++2.2%0D%0A"; commentary[6] = "Load an Agent (human-friendlier format) from the java client and show the Agent"; postToIBLI[6] = "uid=IBLItest&sid="+ sid +"&agent=IBLItest1&choices=View or Change the Agent" + "&f=" + "rule one has item eg-x eg-y\\n" + "---------------------------\\n" + "rule two has item eg-x eg-y\\n" + "&f=" + "table has item eg-x eg-y\\n" + "---------------------------\\n" + "rule one has item eg-x eg-y\\n" + "&f=" + "table has item eg-x eg-y\\n" + "%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D\\n" + " XX 11\\n" + " YY 2.2\\n" ; commentary[7] = "Load an Agent (human-friendlier format) from the java client and show the Qmenu"; //AGENT to QMENU (Load an Agent) postToIBLI[7] = "uid=IBLItest&sid="+ sid +"&agent=IBLItest1&choices=Go to the Question Menu" + "&f=" + "rule one has item eg-x eg-y\\n" + "---------------------------\\n" + "rule two has item eg-x eg-y\\n" + "&f=" + "table has item eg-x eg-y\\n" + "---------------------------\\n" + "rule one has item eg-x eg-y\\n" + "&f=" + "table has item eg-x eg-y\\n" + "%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D\\n" + " XX 11\\n" + " YY 2.2\\n" ; commentary[8] = "Show the currently loaded agent, unless locked"; postToIBLI[8] = "i=none&j=none&question=none&uid=IBLItest&sid="+ sid +"&qmenu=IBLItest1&choices=Go+to+View+or+Change+the+Agent&free_english_typed_in="; /** Note: the following does not remove locks for other sids on this uid (if any). To get rid of those, run #0 four times. **/ commentary[9] = "Release lock(s) for the current uid and sid, and show the Start info"; postToIBLI[9] = "uid=IBLItest&sid="+ sid +"&choices=Go+to+the+Start+Page"; commentary[10] = "Give wrong sid and try to load an Agent from the java client and show the Qmenu"; postToIBLI[10] = "uid=IBLItest&sid="+ (sid-10) +"&agent=IBLItest1&choices=Go+to+the+Question+Menu&f1=%0D%0Arule+one+has+item+eg-x+eg-y%0D%0A---------------------------%0D%0Arule+two+has+item+eg-x+eg-y%0D%0A&f2=%0D%0Atable+has+item+eg-x+eg-y%0D%0A---------------------------%0D%0Arule+one+has+item+eg-x+eg-y%0D%0A&p2=%0D%0Atable+has+item+eg-x+eg-y%0D%0A%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0D%0A++++++++++++++++XX+++11%0D%0A++++++++++++++++YY+++2.2%0D%0A"; commentary[11] = "Incremental answer test part 1: Load an agent and return the question menu"; postToIBLI[11] = "uid=IBLItest&sid="+ sid +"&start=+++&choices=Choose+an+Agent+and+Go+to+its+Question+Menu....&selected_agent=IBLItest2&typed_in_agent_name="; commentary[12] = "Incremental answer test part 2: get the first 50 answers"; postToIBLI[12] = "i=0&j=5&question=some-number+is+of+interest++&uid=IBLItest&sid="+ sid +"&qmenu=IBLItest2&choices=Select+a+Question+to+Ask&free_english_typed_in="; commentary[13] = "Incremental answer test part 3: get more answers (run #12 first) repeat #13 as needed"; postToIBLI[13] = "uid=IBLItest&sid="+ sid +"&answer=IBLItest2&choices=Get+Further+Answers&partial_answer=yes&expl=1"; commentary[14] = "Set custom limit on number of answers (run #11 first). Set limit high to test timeout"; postToIBLI[14] = "limit=2000&j=5&question=some-number+is+of+interest++&uid=IBLItest&sid="+ sid +"&qmenu=IBLItest2&choices=Select+a+Question+to+Ask&free_english_typed_in="; commentary[15] = "Test exception during read in from client (run #11 first)"; postToIBLI[15] = "i=0&j=5&question=some-numberPROVOKE+EXCEPTION+&uid=IBLItest&sid="+ sid +"&qmenu=IBLItest2&choices=Select+a+Question+to+Ask&free_english_typed_in="; commentary[16] = "Test a Check page that has no suggestions"; postToIBLI[16] = "uid=IBLItest&sid="+ sid +"&start=+++&choices=Choose+an+Agent+and+Go+to+the+Check+Page&selected_agent=IBLItest2&typed_in_agent_name="; commentary[17] = "Test a Check page that makes a simple suggestion"; postToIBLI[17] = "uid=IBLItest&sid="+ sid +"&start=+++&choices=Choose+an+Agent+and+Go+to+the+Check+Page&selected_agent=IBLItest3&typed_in_agent_name="; commentary[18] = "Test a Check page that makes a suggestion"; postToIBLI[18] = "uid=IBLItest&sid="+ sid +"&start=+++&choices=Choose+an+Agent+and+Go+to+the+Check+Page&selected_agent=CheckTest5&typed_in_agent_name="; commentary[19] = "Test typing in free English to get a reordered qmenu (run #7 first)"; postToIBLI[19] = "i=none&j=none&question=none&uid=IBLItest&sid="+ sid +"&qmenu=IBLItest1&choices=Select+a+Question+to+Ask&free_english_typed_in=rule+item+one"; commentary[20] = "Load RDFQueryLangComparison1 agent and show the question menu"; postToIBLI[20] = "uid=IBLItest&sid="+ sid +"&start=SqlTest1&choices=Choose+an+Agent+and+Go+to+its+Question+Menu....&selected_agent=RDFQueryLangComparison1&typed_in_agent_name="; commentary[21] = "Ask RDFQueryLangComparison1 agent a question"; postToIBLI[21] = "i=1&j=8&question=6.+the+publication+some-title+has+some-number+author%28s%29++&uid=IBLItest&sid="+ sid +"&qmenu=RDFQueryLangComparison1&choices=Select+a+Question+to+Ask&free_english_typed_in="; commentary[22] = "Get an explanation from RDFQueryLangComparison1 agent "; postToIBLI[22] = "uid=IBLItest&sid="+ sid +"&answer=RDFQueryLangComparison1&choices=Get+an+Explanation&expl=1&1%3A1=An+Overview+of+RDF+Query+Languages&1%3A2=4"; commentary[23] = "Release lock(s) for the current uid and sid, and show the Start info"; postToIBLI[23] = "uid=IBLItest&sid="+ sid +"&choices=Go+to+the+Start+Page"; //Create socket String hostname = "www.reengineeringllc.com"; int port = 80; InetAddress addr = InetAddress.getByName(hostname); Socket sock = new Socket(addr, port); //Send header String path = "/cgi-bin/IBLI"; BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream(),"iso-8859-1")); // You can use "UTF8" for compatibility with the Microsoft virtual machine. wr.write("POST " + path + " HTTP/1.0\r\n"); wr.write("Host:"+ hostname +"\r\n"); wr.write("Content-Length: " + postToIBLI[commandNum].length() + "\r\n"); wr.write("Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"); wr.write("\r\n"); System.out.println("-------- " + commentary[commandNum] + " --------"); System.out.println("POST=\"" + postToIBLI[commandNum] + "\""); //Send data wr.write(postToIBLI[commandNum]); wr.flush(); // Response BufferedReader rd = new BufferedReader(new InputStreamReader(sock.getInputStream())); System.out.println("REPLY="); String line; int count; count=0; while((line = rd.readLine()) != null) { count ++; if (count>7) {System.out.println(line);} } wr.close(); } catch (Exception e) { e.printStackTrace(); } } }