kr.co.hit.live.web.action
Class WebActionDispatcher

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by kr.co.hit.live.web.action.WebActionDispatcher
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class WebActionDispatcher
extends javax.servlet.http.HttpServlet

Live Web Framework의 MVC 아키텍처 구현을 위한 Controller 클래스로서, HttpServletRequest를 받아서 해당 WebAction 객체로 전달해주는 역활을 수행한다. 이 Servlet이 동작하기 위하여 WebApplicationContext 객체가 필요하며 이것은 WebApplicationContextLoader 통하여 Servlet 컨테이너가 초기화되는 시점에 생성된다.

WebActionDispatcher는 그대로 사용할 수 있으나 실제 적용시에는 WebActionDispatcher를 상속받아, preProcess()와 postProcess()에 필요한 기능을 구현하여 사용하도록 한다.

작성예)
 package himed.his.cmc.web.action;
 public class WebActionDispatcher extends kr.co.hit.live.web.action.WebActionDispatcher {
     protected void preProcess(HttpServletRequest request, HttpServletResponse response) {
         // 세션정보로부터 ServiceContext 객체를 생성
         ServiceContext svcCtx = new ServiceContext();
         svcCtx.setRole("...","...");
         ...

         // 서비스별로 고유한 트랜젝션 ID를 설정한다.
         svcCtx.setServiceTransactionID(idgen.getNextId(this).toString());

         // 서비스 컨텍스트를 설정한다.
         ContextManager.setServiceContext(svcCtx);
     }

     protected void postProcess(HttpServletRequest request, HttpServletResponse response,
                        WebActionForward forward) {

         // 처리에 대한 로깅 정보를 남긴다.
         logDiagnostics();

         // 서비스 컨텍스트를 초기화한다.
         ContextManager.clearAll();
     }
 }
 

작성된 WebActionDispatcher는 web.xml에 아래와 같이 <servlet>으로 등록하여 사용하도록 하며 이때 다음의 파라메터를 설정할 수 있다.

또한, <servlet-mapping>으로 처리할 URI 패턴을 지정하여 특정 URI 패턴에 대하여 처리하도록 설정한다.
작성예)
  <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>himed.his.cmc.web.action.WebActionDispatcher</servlet-class>
        <init-param>
                <param-name>live.attach.file.maxsize</param-name>
                <param-value>100000000</param-value>
        </init-param>
        <init-param>
                <param-name>live.web.exception.handler</param-name>
                <param-value>himed.his.cmc.web.action.ExceptionHandler</param-value>
        </init-param>
        <init-param>
                <param-name>live.web.default.encoding</param-name>
                <param-value>utf-8</param-value>
        </init-param>
       <init-param>
                <param-name>live.web.upload.encoding</param-name>
                <param-value>utf-8</param-value>
        </init-param>
   </servlet>

   <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.live</url-pattern>
   </servlet-mapping>

   <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.xrw</url-pattern>
   </servlet-mapping>

   <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.rex</url-pattern>
   </servlet-mapping>
 

이 클래스에서는 다음의 Diagnostic Context 값들을 생성한다.

Since:
4.0
Author:
김형도
See Also:
WebApplicationContextLoader, Serialized Form

Field Summary
static String ATTACH_FILE_MAXSIZE_KEY
          첨부파일의 최대 크기를 설정하기 위한 초기화 파라메터 설정 키값
static String COMMAND_GC_JVM
          WebActionDispatcher 명령들 중 System.gc()를 수행하는 명령이다.
static String COMMAND_RELOAD_CONTAINER
          WebActionDispatcher 명령들 중 ServiceContainer를 reload하는 명령이다.
static String COMMAND_SHOW_CONFIGURATION
          WebActionDispatcher 명령들 중 현재 설정 상태를 출력하는 명령이다.
protected static String defaultCharacterEncoding
          HttpServletRequest의 encoding이 설정되어 있지 않을 경우 적용할 디폴트 인코딩 값
protected static String defaultUploadEncoding
          Multipart HttpServletRequest의 encoding이 설정되어 있지 않을 경우 적용할 디폴트 인코딩 값
static String EXCEPTION_HANDLER_KEY
          에러 발생시 이를 처리할 ExceptionHanlder 클래스를 지정하는 키값.
 
Constructor Summary
WebActionDispatcher()
           
 
Method Summary
protected  void doDelete(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          RESTful Service 지원을 위한 추가 구현
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  void doPut(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          RESTful Service 지원을 위한 추가 구현
protected  void handleException(Throwable thr, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          ExceptionHandler가 지정되지 않았을 경우 사용되는 exception 처리 루틴
 void init()
           
protected  WebActionForward postProcess(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Throwable thr)
          WebAction의 execute()나 WebMultiAction()의 method 호출 시 Exception 발생하였을 경우의 후처리 로직으로 전달된 Exception에 맞는 처리를 한 후 Exception을 다시 던지거나 에러 처리용 WebActionForward를 리턴하는 방식으로 구현한다.
protected  void postProcess(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, WebActionForward forward)
          WebAction의 execute()나 WebMultiAction()의 method 호출이 정상 처리되었을 경우의 후처리 로직을 구현한다.
protected  void preProcess(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          WebAction의 execute()나 WebMultiAction()의 method 호출 전에 처리할 전처리 로직을 구현한다.
protected  void process(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          HttpServletRequest를 받아서 호출된 URI path의 마지막 항목을 WebAction 객체의 서비스 명으로삼는다.
protected  WebActionForward processWebAction(WebAction webAction, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Map<String,Object> diagMap)
          WebAction에 대한 처리를 수행한다.
protected  WebActionForward processWebMultiAction(WebMultiAction multiAction, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Map<String,Object> diagMap)
          WebMultiAction에 대한 처리를 수행한다.
protected  void showConfiguration(javax.servlet.http.HttpServletResponse response)
          WebActionDispatcher, Live 및 System 설정 내역을 출력한다.
 
Methods inherited from class javax.servlet.http.HttpServlet
doHead, doOptions, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultCharacterEncoding

protected static String defaultCharacterEncoding
HttpServletRequest의 encoding이 설정되어 있지 않을 경우 적용할 디폴트 인코딩 값


defaultUploadEncoding

protected static String defaultUploadEncoding
Multipart HttpServletRequest의 encoding이 설정되어 있지 않을 경우 적용할 디폴트 인코딩 값


EXCEPTION_HANDLER_KEY

public static final String EXCEPTION_HANDLER_KEY
에러 발생시 이를 처리할 ExceptionHanlder 클래스를 지정하는 키값.

See Also:
Constant Field Values

ATTACH_FILE_MAXSIZE_KEY

public static final String ATTACH_FILE_MAXSIZE_KEY
첨부파일의 최대 크기를 설정하기 위한 초기화 파라메터 설정 키값

See Also:
Constant Field Values

COMMAND_SHOW_CONFIGURATION

public static final String COMMAND_SHOW_CONFIGURATION
WebActionDispatcher 명령들 중 현재 설정 상태를 출력하는 명령이다.

See Also:
Constant Field Values

COMMAND_RELOAD_CONTAINER

public static final String COMMAND_RELOAD_CONTAINER
WebActionDispatcher 명령들 중 ServiceContainer를 reload하는 명령이다.

See Also:
Constant Field Values

COMMAND_GC_JVM

public static final String COMMAND_GC_JVM
WebActionDispatcher 명령들 중 System.gc()를 수행하는 명령이다.

See Also:
Constant Field Values
Constructor Detail

WebActionDispatcher

public WebActionDispatcher()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

doGet

protected void doGet(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws javax.servlet.ServletException,
                     IOException
Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

doPost

protected void doPost(javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response)
               throws javax.servlet.ServletException,
                      IOException
Overrides:
doPost in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

doPut

protected void doPut(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws javax.servlet.ServletException,
                     IOException
RESTful Service 지원을 위한 추가 구현. - 2013.02.28 노준훈.

Overrides:
doPut in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

doDelete

protected void doDelete(javax.servlet.http.HttpServletRequest request,
                        javax.servlet.http.HttpServletResponse response)
                 throws javax.servlet.ServletException,
                        IOException
RESTful Service 지원을 위한 추가 구현. - 2013.02.28 노준훈.

Overrides:
doDelete in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
IOException

handleException

protected void handleException(Throwable thr,
                               javax.servlet.http.HttpServletRequest request,
                               javax.servlet.http.HttpServletResponse response)
                        throws javax.servlet.ServletException,
                               IOException
ExceptionHandler가 지정되지 않았을 경우 사용되는 exception 처리 루틴

Parameters:
thr -
request -
response -
Throws:
javax.servlet.ServletException
IOException

process

protected void process(javax.servlet.http.HttpServletRequest request,
                       javax.servlet.http.HttpServletResponse response)
                throws javax.servlet.ServletException,
                       IOException
HttpServletRequest를 받아서 호출된 URI path의 마지막 항목을 WebAction 객체의 서비스 명으로삼는다. ServiceContainer로부터 호출할 해당 객체를 얻어온 후 객체가 WebMultiAction 타입이라면 해당 객체에 getMethodName()를 사용하여 호출할 메소드 명을 얻어와 다시 메소드를 호출한다. ServiceContainer로부터 얻어온 객체가 WebAction 타입이라면 해당 객체의 execute() 메소드를 호출한다.

WebAction 또는 WebMultiAction 객체의 메소드 호출 결과로 리턴된 WebActionForward 객체의 getModel()를 사용하여 얻어진 데이터는 request의 setAttribute()를 통하여 request에 저장한 후 WebActionForward 객체의 getViewURL()로 얻어진 URL로 포워드한다.

리턴된 WebActionForward 객체가 null 이라면 포워드 하지 않고 종료한다.

Parameters:
request -
response -
Throws:
javax.servlet.ServletException
IOException

preProcess

protected void preProcess(javax.servlet.http.HttpServletRequest request,
                          javax.servlet.http.HttpServletResponse response)
                   throws Throwable
WebAction의 execute()나 WebMultiAction()의 method 호출 전에 처리할 전처리 로직을 구현한다.

Throws:
Throwable

postProcess

protected void postProcess(javax.servlet.http.HttpServletRequest request,
                           javax.servlet.http.HttpServletResponse response,
                           WebActionForward forward)
WebAction의 execute()나 WebMultiAction()의 method 호출이 정상 처리되었을 경우의 후처리 로직을 구현한다.

Parameters:
request -
response -
forward -

postProcess

protected WebActionForward postProcess(javax.servlet.http.HttpServletRequest request,
                                       javax.servlet.http.HttpServletResponse response,
                                       Throwable thr)
                                throws Throwable
WebAction의 execute()나 WebMultiAction()의 method 호출 시 Exception 발생하였을 경우의 후처리 로직으로 전달된 Exception에 맞는 처리를 한 후 Exception을 다시 던지거나 에러 처리용 WebActionForward를 리턴하는 방식으로 구현한다.

Parameters:
request -
response -
exeception -
Returns:
WebActionForward
Throws:
Throwable

processWebAction

protected WebActionForward processWebAction(WebAction webAction,
                                            javax.servlet.http.HttpServletRequest request,
                                            javax.servlet.http.HttpServletResponse response,
                                            Map<String,Object> diagMap)
                                     throws Throwable
WebAction에 대한 처리를 수행한다. 주어진 WebAction 서비스 객체의 execute() 메소들 호출한다.

Parameters:
webAction -
svcName -
request -
response -
Returns:
Throws:
javax.servlet.ServletException
Throwable

processWebMultiAction

protected WebActionForward processWebMultiAction(WebMultiAction multiAction,
                                                 javax.servlet.http.HttpServletRequest request,
                                                 javax.servlet.http.HttpServletResponse response,
                                                 Map<String,Object> diagMap)
                                          throws Throwable
WebMultiAction에 대한 처리를 수행한다. 주어진 WebMultiAction 서비스 객체의 메소드를 호출하며, 호출할 메소드 이름은 WebMultiAction 객체의 getMethodname()을 호출하여 얻어온다.

Parameters:
multiAction -
svcName -
request -
response -
Returns:
Throws:
javax.servlet.ServletException
Throwable

showConfiguration

protected void showConfiguration(javax.servlet.http.HttpServletResponse response)
                          throws IOException
WebActionDispatcher, Live 및 System 설정 내역을 출력한다.

Parameters:
response -
Throws:
IOException


Copyright © 2014. All Rights Reserved.