package com.persagy.dmp.file.handler;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.persagy.dmp.file.context.OldFileAppContext;
import com.persagy.dmp.file.context.OldFileContext;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

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

public class OldFileContextHandler implements HandlerInterceptor {


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        OldFileContext context = OldFileAppContext.getContext();
        context.setSystemId(request.getParameter(OldFileContext.SYSTEM_ID));
        context.setSecret(request.getParameter(OldFileContext.SECRET));
        context.setKey(request.getParameter(OldFileContext.KEY));
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {
        OldFileAppContext.unloadContext();
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        OldFileAppContext.unloadContext();
    }


}
