| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 
 |  // recupere la reponse du serveur et la transmet au client.
 private boolean transfererReponseServeurAuClient() {
  InputStream  inputStreamServeur = null;
  OutputStream outputStreamClient = null;
  String headerReponseServeur = "";
  String contentReponseServeur = "";
 
  try {
   inputStreamServeur  = socketServeur.getInputStream();
  }
  catch (Exception e) {
   System.out.println("ProxyConnection.transfererReponseServeurAuClient: Erreur ouverture inputStream socket Serveur - " + e.getMessage() + ". FIN PROCESSUS");
   log.addMessage("ProxyConnection.transfererReponseServeurAuClient - Erreur ouverture inputStream socket Serveur", e.getMessage());
   log.addMessage("ProxyConnection.transfererReponseServeurAuClient", "FIN PROCESSUS");
   closeSocket(socketClient);
   return false;
  }
 
  try {
   outputStreamClient = socketClient.getOutputStream();
  }
  catch (Exception e) {
   System.out.println("ProxyConnection.transfererReponseServeurAuClient: Erreur ouverture outputStream socket Client - " + e.getMessage() + ". FIN PROCESSUS");
   log.addMessage("ProxyConnection.transfererReponseServeurAuClient - Erreur ouverture outputStream socket Client", e.getMessage());
   log.addMessage("ProxyConnection.transfererReponseServeurAuClient", "FIN PROCESSUS");
   closeSocket(socketServeur);
   return false;
  }
 
  try {
   byte onebyte[] = new byte[1];
   boolean end = false;
 
   // recuperation du header, byte par byte.
   // on determine la fin avec _CRLF2.
   // on transfert directement les donnees au client.
   while(!end) {
    if(inputStreamServeur.read(onebyte) <= 0) {
     end = true;
     continue;
    }
    else {
     headerReponseServeur += new String(onebyte, "8859_1");
     outputStreamClient.write(onebyte, 0, onebyte.length);
    }
 
    if(headerReponseServeur.endsWith(_CRLF2))
     end = true;
   }
 
   outputStreamClient.flush(); 
 
   System.out.println("ProxyConnection.recupererRequeteServeur: header:\n" + headerReponseServeur);
 
   // recuperation du contenu, byte par byte.
   // on transfert directement les donnees au client.
   // si le contenu est vide, alors une exception silencieuse est levee.
   end = false;
   while(!end) {
    if (inputStreamServeur.read(onebyte) <= 0) {
     end = true;
     continue;
    }
    else {
     contentReponseServeur += new String(onebyte, "8859_1");
     outputStreamClient.write(onebyte, 0, onebyte.length);
     System.out.println("ProxyConnection.recupererRequeteServeur contenu:\n" + contentReponseServeur);
    }
   }
 
   outputStreamClient.flush();
 
   System.out.println("ProxyConnection.recupererRequeteServeur contenu:\n" + contentReponseServeur);
 
   return true;
  }
  catch (Exception e) {
   System.out.println("ProxyConnection.transfererReponseServeurAuClient: " + e.getMessage() + ". FIN PROCESSUS");
   log.addMessage("ProxyConnection.transfererReponseServeurAuClient", e.getMessage());
   log.addMessage("ProxyConnection.transfererReponseServeurAuClient", "FIN PROCESSUS");
   closeSocket(socketClient);
   closeSocket(socketServeur);
   return false;
  }
 } | 
Partager