filter 파일 업로드 -egov


package kr.co.egov.upb.web;


import java.io.IOException;


import javax.servlet.FilterChain;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import org.apache.log4j.Logger;

import org.springframework.web.filter.OncePerRequestFilter;


import kr.co.egov.upb.service.ProgressCapableMultipartResolver;

import kr.co.egov.upb.service.ProgressDescriptor;



public class UploadProgressFilter extends OncePerRequestFilter{


Logger log = Logger.getLogger(this.getClass());


private final String PROGRESS_TAIL = ".progress"; 


protected void doFilterInternal(HttpServletRequest request,

HttpServletResponse response, FilterChain filterChain)

throws ServletException, IOException {


String requestUri = request.getRequestURI();

String originalUrl = requestUri.substring(0, requestUri.length()

- PROGRESS_TAIL.length());


String attributeName = ProgressCapableMultipartResolver.PROGRESS_PREFIX + originalUrl;


Object progress = request.getSession().getAttribute(attributeName);


if(progress != null){

ProgressDescriptor descriptor = (ProgressDescriptor)progress;

log.debug("[pBytesRead=" + descriptor.getBytesRead() + ",

pContentLength=" + descriptor.getBytesTotal() + "]");



response.getOutputStream().write(descriptor.toString().getBytes() );

response.getOutputStream().flush();

response.getOutputStream().close();

}

}

}

블로그 이미지

마크제이콥스

초보 개발자의 이슈및 공부 내용 정리 블로그 입니다.

,