Ciao a tutti spero possiate aiutarmi in questo problema
ho implementato un proxy che si interpone fra un server(apache tomcat) e diversi client.
Il proxy riceve le richieste Http e le inoltra al server.successivamente riceve le risposte http dal server.
Ho bisogno di memorizzare 2 istanti,
istante t1 --> istante in cui il proxy inizia ad inoltrare la richiesta Http verso il server.
istante t2 --> istante in cui il proxy riceve la risposta Http dal server.
per essere piu chiaro vi posto il codice che utilizzo per inoltrare le richieste.
IL CODICE FUNZIONA, IL PROBLEMA E' INDIVIDUARE I DUE ISTANTI DI TEMPO CHE VI HO INDICATO DI SOPRA.... AVETE QLCHE IDEA? vi ringrazio anticipatamnete
package core;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class HTTPProxyThread implements Runnable {
private ServerSocket server;
private Socket connection;
public HTTPProxyThread(ServerSocket server, Socket connection) {
this.server=server;
this.connection=connection;
}
@Override
public void run() {
double p=0;
String ipServer="127.0.0.1";
int portServer=8080;
//-------------------------------------------------------------
StringBuffer response = new StringBuffer(80);
try{
//System.out.println("\nAccettata la connessione da: \t"+ connection.toString());
InputStream in = new BufferedInputStream(connection.getInputStream());
OutputStream outToJmeter = connection.getOutputStream();
StringBuffer request = new StringBuffer(80);
//-----------RICEVO LA REQUEST
while (true) {
int c = in.read();
request.append((char) c);
if (request.toString().contains("\r\n\r\n") )
break;
}
if(Math.random()>=pAdmission) {
//----------------------------------------------------------FORWARD DELLA REQUEST
Socket socket = new Socket(ipServer, portServer);
OutputStream os = socket.getOutputStream();
InputStream inForward = new BufferedInputStream(socket.getInputStream());
boolean autoflush = true;
PrintWriter out = new PrintWriter( os, autoflush );
System.out.println("request dal client: "+request.toString() );
out.println(request.toString());
//----------------------------------------------------------RICEVO LA RESPONSE DAL WEB SERVER
while (true) {
int c = inForward.read();
response.append((char) c);
if (response.toString().contains("\r\n\r\n") )
break;
// System.out.print((char)c);
}
System.out.println("response dal server: "+response.toString() );
}// END if math.rand
else{
//------------------------------------------------REJECT---------------------------------------------
System.out.println("REJECT"+"\n");}
System.out.println("Devo mandare un 404");
//------------------------------------------------------------- RESPONSE A clients
PrintWriter pwriterToJmeter = new PrintWriter(outToJmeter,true);
pwriterToJmeter.println(response);
connection.close();
}catch(IOException io){io.printStackTrace();}
}//end run method
}

Rispondi quotando