( String url, String text )
| 77 | } |
| 78 | |
| 79 | static String doBsh( String url, String text ) |
| 80 | { |
| 81 | OutputStream out; |
| 82 | InputStream in; |
| 83 | String host = ""; |
| 84 | String port = ""; |
| 85 | String returnValue = "-1"; |
| 86 | String orgURL = url; |
| 87 | |
| 88 | // Need some format checking here |
| 89 | try { |
| 90 | url = url.substring(6); // remove the bsh:// |
| 91 | // get the index of the : between the host and the port is located |
| 92 | int index = url.indexOf(":"); |
| 93 | host = url.substring(0,index); |
| 94 | port = url.substring(index+1,url.length()); |
| 95 | } catch ( Exception ex ) { |
| 96 | System.err.println("Bad URL: "+orgURL+": "+ex ); |
| 97 | return returnValue; |
| 98 | } |
| 99 | |
| 100 | try { |
| 101 | System.out.println("Connecting to host : " |
| 102 | + host + " at port : " + port); |
| 103 | Socket s = new Socket(host, Integer.parseInt(port) + 1); |
| 104 | |
| 105 | out = s.getOutputStream(); |
| 106 | in = s.getInputStream(); |
| 107 | |
| 108 | sendLine( text, out ); |
| 109 | |
| 110 | BufferedReader bin = new BufferedReader( |
| 111 | new InputStreamReader(in)); |
| 112 | String line; |
| 113 | while ( (line=bin.readLine()) != null ) |
| 114 | System.out.println( line ); |
| 115 | |
| 116 | // Need to scrape a value from the last line? |
| 117 | returnValue="1"; |
| 118 | return returnValue; |
| 119 | } catch(Exception ex) { |
| 120 | System.err.println("Error communicating with server: "+ex); |
| 121 | return returnValue; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | private static void sendLine( String line, OutputStream outPipe ) |
| 126 | throws IOException |
no test coverage detected