/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.example.hello.android.web_server_jetty_service_hello;

import android.util.Log;
import java.io.IOException;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;

/**
 *
 * @author sawai
 */
public class HelloJettyHandler extends AbstractHandler
{

	private static final String LOG_TAG = "XXX";

	public void handle(String string, Request request, HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException, ServletException
	{
		Log.d(LOG_TAG, "HelloJettyHandler#handle() : Hello");
		Log.d(LOG_TAG, "HelloJettyHandler#handle() : string => " + string);
		servletResponse.setContentType("text/html");
		servletResponse.setStatus(HttpServletResponse.SC_OK);
		servletResponse.getWriter().println("<html>");
		servletResponse.getWriter().println("<head>");
		servletResponse.getWriter().println("<meta name=\"viewport\" content=\"width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=1;\"/>");
		servletResponse.getWriter().println("</head>");
		servletResponse.getWriter().println("<body>");
		servletResponse.getWriter().println("<h1>Hello</h1>");
		servletResponse.getWriter().println("<p>Hello Web Server</p>");
		servletResponse.getWriter().println("<p>" + new Date() + "</p>");
		servletResponse.getWriter().println("</body>");
		servletResponse.getWriter().println("</html>");
		((Request) request).setHandled(true);
	}
}