package com.pku.judgeonline.servlet;
import com.pku.judgeonline.security.Guard;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
public class RecentSRM extends HttpServlet
{
/**
*
*/
private static final long serialVersionUID = 1L;
public RecentSRM()
{
}
public void init() throws ServletException
{
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html; charset=UTF-8");
request.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
if (!Guard.Guarder(request, response, out))
return;
String tLine = "";
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod("http://acm.nankai.edu.cn/contests.json");
getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler());
try
{
int statusCode = httpClient.executeMethod(getMethod);
if (statusCode != HttpStatus.SC_OK)
{
System.err.println("Method failed: " + getMethod.getStatusLine());
}
byte[] responseBody = getMethod.getResponseBody();
tLine = new String(responseBody, "UTF-8");
} catch (Exception e)
{
getMethod.releaseConnection();
return;
}
// System.out.println(tLine);
out.println(tLine);
out.close();
}
public void destroy()
{
}
}