Generate one redirection request
BufferedReader is; // inputStream, from Viewer
PrintWriter os; // outputStream, to Viewer
String request; // what Viewer sends us.
try {
String from = s.getInetAddress().toString();
System.out.println("Accepted connection from " + from);
os = new PrintWriter(s.getOutputStream(), true);
is = new BufferedReader(new InputStreamReader(s.getInputStream()));
request = is.readLine();
StringTokenizer st = new StringTokenizer(request);
if (st.countTokens() < 3) {
os.println("HTTP/1.0 400 invalid request");
os.println();
os.flush();
s.close();
}
String requestMethod = st.nextToken();
String requestURI = st.nextToken();
String requestVersion = st.nextToken();
System.out.println("Request: " + requestMethod + " for " + requestURI + " via " + requestVersion);
String nullLine = is.readLine();
os.println("HTTP/1.1 302 Moved Temporarily");
os.println("Location: " + GOTO + requestURI);
os.println("Content-Type: text/plain");
os.println("Server-name: DarwinSys NULL Java WebRedirector 0");
os.flush();
s.close();
} catch (IOException ex){
System.err.println("Error: " + ex);
}