package jeus_jspwork._moniter._failHandler;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.io.File;
import java.io.FileInputStream;
import java.util.*;
import org.kldp.ebmsh.moniter.failHandler.EngineFailMessageInfo;
import org.kldp.ebmsh.config.EbmsConstants;
import org.kldp.util.io.FileIoUtil;
import org.kldp.ebmsh.moniter.failHandler.*;
import org.kldp.ebmsh.moniter.permission.PermissionManager;
import org.kldp.ebmsh.config.EbmsConstants;
import org.kldp.ebmsh.moniter.permission.PermissionManager;
import org.kldp.ebmsh.config.EbmsConstants;

public final class _500_biFailHandlerProcess_5fjsp extends jeus.servlet.jsp2.runtime.HttpJspBase
    implements jeus.servlet.jsp2.runtime.JspSourceDependent {

  private static java.util.Vector _jspx_dependants;

  static {
    _jspx_dependants = new java.util.Vector(2);
    _jspx_dependants.add("/authorize/loginCheck.jsp");
    _jspx_dependants.add("/setup/setupCheck.jsp");
  }

  public java.util.List getDependants() {
    return _jspx_dependants;
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    JspFactory _jspxFactory = null;
    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      _jspxFactory = JspFactory.getDefaultFactory();
      response.setContentType("text/html; charset=euc-kr");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");

	if( !PermissionManager.isAdminLogin(session) ) {

      out.write("\r\n");
      out.write("\t\t<script language=\"JavaScript\">\r\n");
      out.write("\t\t\tdocument.location.href = '");
      out.print( request.getContextPath() );
      out.write("/authorize/login.jsp';\r\n");
      out.write("\t\t</script>\r\n");
	
		return ;
	}

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");

	if( !EbmsConstants.configured ) {

      out.write("\r\n");
      out.write("\t\t<script language=\"JavaScript\">\r\n");
      out.write("\t\t\tdocument.location.href = '");
      out.print( request.getContextPath() );
      out.write("/setup/setup.jsp';\r\n");
      out.write("\t\t</script>\r\n");
	
		return ;
	}

      out.write("\r\n");
      out.write("\r\n");

	// 실패 메시지 정보를 세션에 저장합니다.
	List<BiFailMessageInfo> failMessageInfoList = (List<BiFailMessageInfo>)session.getAttribute("biFailMessageInfoList");
	
	String failMessageDirectory = EbmsConstants.messagePath + FileIoUtil.fileSeparatorAddOrNone("fail");
	
	// 메시지 처리 결과를 저장할 객체
	List<BiFailMessageProcessResult> failMessageProcessResultList = new ArrayList<BiFailMessageProcessResult>();
	
	for(int i = 0; i < failMessageInfoList.size(); i++) {
		FailMessageManager manager = new FailMessageManager();
	
		BiFailMessageInfo failMessageInfo = failMessageInfoList.get(i);
	
		BiFailMessageProcessResult failMessageProcessResult = manager.reProcessBiFailMessage(failMessageInfo.getMessageId(), failMessageInfo.getMessagePath());
		
		// 객체 저장
		failMessageProcessResultList.add(failMessageProcessResult);
	}
		
	// 세션에서 fail message 정보 삭제
	session.removeAttribute("biFailMessageInfoList");
	
	// 세션에 fail message process result 정보 저장
	session.setAttribute("biFailMessageProcessResultList", failMessageProcessResultList);
	
	response.sendRedirect("biFailHandlerResult.jsp");

      out.write('\r');
      out.write('\n');
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          out.clearBuffer();
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
