package asignacionServlet;

import java.io.IOException;

import javax.naming.InitialContext;
import javax.servlet.http.HttpSession;

import m05bAsignacionEJB.m05Asignacion;
import m05bAsignacionEJB.m05AsignacionHome;
import m05bAsignacionEJB.m05AsignacionPK;
import m05bBD.m05bAsignacion;
import m05bClasses.m05bFileLog;

/**
 * Inserte aquí la descripción del tipo.
 * Fecha de creación: (08/01/04)
 */
public class m05bGenerarAsignacionServlet extends javax.servlet.http.HttpServlet {m05bFileLog miLog = new m05bFileLog();
/**
 * Process incoming HTTP GET requests 
 * 
 * @param request Object that encapsulates the request to the servlet 
 * @param response Object that encapsulates the response from the servlet
 */
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {

	performTask(request, response);

}
/**
 * Returns the servlet info string.
 */
public String getServletInfo() {

	return super.getServletInfo();

}
/**
 * Initializes the servlet.
 */
public void init() {
	// insert code to initialize the servlet here

}
/**
 * Process incoming requests for information
 * 
 * @param request Object that encapsulates the request to the servlet 
 * @param response Object that encapsulates the response from the servlet
 */
public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) {

	try

	{
		// Insert user code from here.

		String codigo, mensaje, msg;
		String sURL = "", sql = "";

		HttpSession session = request.getSession(true);

		codigo = new String(request.getParameter("Codigo"));
		mensaje = new String(request.getParameter("Mensaje"));
        ////System.out.println("Codigo"+codigo);

		try{

			m05AsignacionPK primaryKey = new m05AsignacionPK();
			primaryKey.asi_codigo = codigo;
			InitialContext ctx2 = new InitialContext();
			m05AsignacionHome asignacionEBHome = (m05AsignacionHome) ctx2.lookup("m05Asignacion");
			m05Asignacion asignacionEB = asignacionEBHome.findByPrimaryKey(primaryKey);
			m05bAsignacion asignacion = asignacionEB.getAsignacion();
			session.setAttribute("m05bAsignacion", asignacion);
			response.sendRedirect("m05bAsignacionesJsp.jsp?Codigo=" + codigo +  "&Mensaje=" + mensaje);
	    	/*sURL = response.encodeRedirectURL("m05bAsignacionesJsp.jsp?Codigo=" + codigo +  "&Mensaje=" + mensaje);

		    RequestDispatcher rd;
		    rd = request.getRequestDispatcher(sURL);

		    try{
		    	rd.forward(request, response);
	    	} 
		    catch (ServletException e){
		      System.err.println("m05b - Generar Asignacion EXCEPTION: OutletMaintenanceS.service: " + e);
		    }    	*/
			
		} catch (javax.ejb.ObjectNotFoundException E) {
			
			response.sendRedirect("m05bAsignacionesJsp.jsp?Codigo=" + codigo +  "&Mensaje=ERROR" );
		}catch (Exception SQLException) {
			m05bFileLog miLog = new m05bFileLog();
			miLog.addTraza(SQLException);
			response.sendRedirect("m05bError.jsp");
		}
	}
	catch(Throwable theException)
	{
		try {
			// uncomment the following line when unexpected exceptions
			// are occuring to aid in debugging the problem.
			
			response.sendRedirect("m05bError.jsp");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			m05bFileLog miLog = new m05bFileLog();
			miLog.addTraza(e);
		}
	}
}
}