Conosce il BtServer e la classe stub del WS. Riceve il BtServer come parametro nel suo costruttore perchè in caso di errore di IO durante la comunicazione col client la connessione viene rimossa. Questa classe è strettamente legata all'implementazione del WS, in particolare ai metodi che esso espone. Attualmente sono solo 3 i possibili metodi che si possono invocare:
Definizione alla linea 36 del file ConnectionProcessor.java.
Membri pubblici | |
ConnectionProcessor (StreamConnection connection, BtServer server, String serviceURL) | |
void | run () |
Membri privati | |
String | getRequest (DataInputStream input, String endOfRequestMarker) throws IOException |
String | getRequestContent (String request, String beginMarker, String endMarker) |
Attributi privati | |
StreamConnection | connection = null |
int | sessionId |
BtServer | server |
JAEBIWSSEI | service |
|
Definizione alla linea 47 del file ConnectionProcessor.java. Riferimenti service. 00047 { 00048 this.connection = connection; 00049 this.server = server; 00050 this.service = service = new JAEBIWSSEI_Stub(); 00051 00052 // Initialize the stub/service. 00053 ((JAEBIWSSEI_Stub)service)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, 00054 serviceURL); 00055 new Thread(this).start(); 00056 }
|
|
Definizione alla linea 65 del file ConnectionProcessor.java. Referenziato da run(). 00065 { 00066 String temp; 00067 boolean isEnded = false; 00068 int byteReaded; 00069 byte buffer[] = new byte[endOfRequestMarker.length()]; 00070 String received = ""; 00071 00072 do{ 00073 byteReaded = input.read(buffer); 00074 temp = new String(buffer); 00075 00076 received += temp.substring(0, byteReaded); 00077 00078 // System.out.println("ConnectionProcessor:: " + received); 00079 00080 00081 /* 00082 * quando è stata ricevuta la stringa che marca la fine della 00083 * request (endOfRequestMarker) non devo fare più alcuna read 00084 */ 00085 if (received.length()>= endOfRequestMarker.length() ){ 00086 int startIndex = received.length()- endOfRequestMarker.length(); 00087 if (received.substring(startIndex, received.length()).equalsIgnoreCase(endOfRequestMarker)) 00088 isEnded = true; 00089 } 00090 } 00091 while( !isEnded); 00092 00093 return received; 00094 }
|
|
Definizione alla linea 97 del file ConnectionProcessor.java. Referenziato da run(). 00097 { 00098 StringBuffer out = new StringBuffer(request); 00099 out.delete(0, beginMarker.length()); 00100 out.delete(out.length()-endMarker.length(), out.length()); 00101 return out.toString(); 00102 }
|
|
è avvenuto un errore durante la comunicazione: l'unica azione da intraprendere è la rimozione della connessione è avvenuto un errore durante la comunicazione: l'unica azione da intraprendere è la rimozione della connessione Definizione alla linea 105 del file ConnectionProcessor.java. Riferimenti connection, org.jaebi.midlet.WSClient.JAEBIWSSEI.executeRequest(), getRequest(), getRequestContent(), org.jaebi.midlet.WSClient.JAEBIWSSEI.login(), org.jaebi.midlet.WSClient.JAEBIWSSEI.logout(), org.jaebi.midlet.bt.BtServer.removeConnection(), server, service, e sessionId. 00105 { 00106 boolean logout = false; 00107 DataInputStream streamFromClient = null; 00108 DataOutputStream streamToClient = null; 00109 00110 try{ 00111 streamFromClient = this.connection.openDataInputStream(); 00112 streamToClient = this.connection.openDataOutputStream(); 00113 } catch(IOException e){ 00118 00119 //TODO debug 00120 System.out.println("errore"); 00121 00122 e.printStackTrace(); 00123 //se avviene l'eccezione ci sono errori sulla connessione:bisogna rimuoverla 00124 server.removeConnection(this.connection); 00125 return; 00126 } 00127 00128 StreamConnection conn = this.connection; 00129 int i = 0; 00130 do{ 00131 System.out.println("ConnectionProcessor::run è la " + ++i + "volta"); 00132 try{ 00133 00134 byte buffer[] = new byte[8]; 00135 00136 String request =""; 00137 String response =""; 00138 String responseBeginMarker = ""; 00139 String responseEndMarker = ""; 00140 00141 int result = -1; 00142 int loginBeginMarkerLength = 7; 00143 int logoutBeginMarkerLength = 8; 00144 00145 //flag se indica se il metodo da invocare è executeRequest 00146 boolean executeRequest = true; 00147 00148 /******************************************************************* 00149 * Leggo i prmi 8 caratteri che ha inviato il client per capire 00150 * qual'è la richiesta che si desidera inoltrare al WS, ossia, quale 00151 * dei suoi metodi invocare. 00152 ******************************************************************* 00153 */ 00154 streamFromClient.read(buffer); 00155 request = new String(buffer); 00156 00157 00158 /* 00159 ******************************************************************* 00160 * bisogna invocare login()? 00161 ******************************************************************* 00162 */ 00163 if (request.substring(0,loginBeginMarkerLength).equals("[login]")){ 00164 00165 responseBeginMarker = "[login_response]"; 00166 responseEndMarker = "[/login_response]"; 00167 00168 request += getRequest(streamFromClient, "[/login]"); 00169 00170 String requestContent = getRequestContent(request, "[login]", "[/login]"); 00171 00172 String nickName = requestContent.substring(0, requestContent.indexOf(" ")); 00173 String userType = "Midlet"; 00174 00175 response = "error"; 00176 00177 try{ 00178 result = service.login(nickName, userType); 00179 if (result != -1){ 00180 this.sessionId = result; 00181 response="ok"; 00182 } 00183 00184 00185 //TODO debug 00186 System.out.println("ConnectionProcessor::run sessid "+ result); 00187 00188 00189 } catch (RemoteException e){ 00190 response = "error"; 00191 } 00192 00193 response = responseBeginMarker + response + responseEndMarker; 00194 streamToClient.write(response.getBytes()); 00195 00196 executeRequest = false; 00197 00198 } 00199 00200 00201 /* 00202 ****************************************************************** 00203 * bisogna invocare logout()? 00204 ****************************************************************** 00205 */ 00206 if (request.substring(0,logoutBeginMarkerLength).equals("[logout]")){ 00207 request += getRequest(streamFromClient, "[/logout]"); 00208 00209 executeRequest = false; 00210 service.logout(sessionId); 00211 //TODO devo mandare un response al client 00212 logout = true; 00213 00214 } 00215 00216 00217 /* 00218 ******************************************************************* 00219 * bisogna invocare xrequest()? 00220 ******************************************************************* 00221 */ 00222 if(executeRequest){ 00223 request += getRequest(streamFromClient, "</xrequest>"); 00224 //TODO debug 00225 System.out.println("ConnectionProcessor:: run xrequest:" + request); 00226 response = service.executeRequest(this.sessionId, request); 00227 00228 //TODO debug 00229 System.out.println("ConnectionProcessor:: run xresponse:" + response); 00230 streamToClient.write(response.getBytes()); 00231 00232 //TODO devo controllare se oltre i marker non c'è nient'altro? 00233 00234 } 00235 00236 } 00237 00238 catch(IOException e){ 00243 00244 //TODO debug 00245 System.out.println("errore"); 00246 00247 e.printStackTrace(); 00248 //se avviene l'eccezione ci sono errori sulla connessione:bisogna rimuoverla 00249 server.removeConnection(this.connection); 00250 } 00251 } 00252 while (!logout); 00253 00254 }
Questo è il grafo delle chiamate per questa funzione: ![]() |
|
Definizione alla linea 38 del file ConnectionProcessor.java. Referenziato da run(). |
|
Definizione alla linea 42 del file ConnectionProcessor.java. Referenziato da run(). |
|
Definizione alla linea 44 del file ConnectionProcessor.java. Referenziato da ConnectionProcessor(), e run(). |
|
Definizione alla linea 40 del file ConnectionProcessor.java. Referenziato da run(). |