문서의 선택한 두 판 사이의 차이를 보여줍니다.
|
java:tomcat:contextreload [2012/06/03 16:58] kwon37xi 새로 만듦 |
java:tomcat:contextreload [2012/06/03 17:03] (현재) kwon37xi |
||
|---|---|---|---|
| 줄 19: | 줄 19: | ||
| * " | * " | ||
| + | ===== 소스 ===== | ||
| + | <code java> | ||
| + | package kr.pe.kwonnam.tomcat.reloader; | ||
| + | |||
| + | import java.io.IOException; | ||
| + | |||
| + | import javax.servlet.ServletException; | ||
| + | import javax.servlet.http.HttpServletResponse; | ||
| + | |||
| + | import org.apache.catalina.Container; | ||
| + | import org.apache.catalina.Context; | ||
| + | import org.apache.catalina.connector.Request; | ||
| + | import org.apache.catalina.connector.Response; | ||
| + | import org.apache.catalina.valves.ValveBase; | ||
| + | |||
| + | /** | ||
| + | * Reload Tomcat Context by requesting URL | ||
| + | * | ||
| + | * Context의 reloadable=" | ||
| + | * | ||
| + | * @author 손권남 kwon37xi@gmail.com | ||
| + | * | ||
| + | */ | ||
| + | public class TomcatReloadValve extends ValveBase { | ||
| + | |||
| + | private static final String RELOAD_CONTEXT_URI = "/ | ||
| + | |||
| + | @Override | ||
| + | public void invoke(Request request, Response response) throws IOException, | ||
| + | ServletException { | ||
| + | |||
| + | Container container = getContainer(); | ||
| + | |||
| + | String requestUri = request.getRequestURI(); | ||
| + | |||
| + | String reloadUri = request.getContextPath() + RELOAD_CONTEXT_URI; | ||
| + | |||
| + | if (requestUri.startsWith(reloadUri) | ||
| + | && | ||
| + | reloadContext(response, | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | getNext().invoke(request, | ||
| + | } | ||
| + | |||
| + | private void reloadContext(Response response, Container container) | ||
| + | throws IOException { | ||
| + | ((Context) container).reload(); | ||
| + | HttpServletResponse httpResponse = response.getResponse(); | ||
| + | |||
| + | httpResponse.setContentType(" | ||
| + | httpResponse.getWriter().write(" | ||
| + | httpResponse.getWriter().close(); | ||
| + | |||
| + | return; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||