package servlets;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.Scanner;
/**
* Servlet implementation class Connect
*/
public class Connect extends HttpServlet
{
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Connect()
{
super();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
final String ip = request.getParameter("ip");
final String user = request.getParameter("user");
final String pw = request.getParameter("pw");
final String interval = request.getParameter("interval");
InputStream is = null;
Authenticator.setDefault(new Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(user, pw.toCharArray());
}
} );
try
{
URL url = new URL("http://" + ip + "/CGI/Screenshot");
is = url.openStream();
response.setContentType("image/bmp");
response.getWriter().write(new Scanner(is).useDelimiter( "\\Z" ).next());
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
is.close();
}
}
}