package com.rjconsultores.ventaboletos.web.utilerias.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.rjconsultores.ventaboletos.rest.service.AmbienteService;
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;

public class ReloadDBConnection extends HttpServlet {
	private static final long serialVersionUID = -2076848353707789950L;

	private PrintWriter out = null;
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		out = resp.getWriter();
		out.println("<h2>Reload DB Connection</h2>");

		ApplicationProperties.getInstance().readReadOnlyConnection();

		AmbienteService service = (AmbienteService) AppContext.getApplicationContext().getBean("ambienteService");

		out.println("Ambiente: " + service.getAmbienteReadOnly());
		out.println("<br><br>");
		out.println("Processo realizado com sucesso.");

		out.close();
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}
