⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 serviceservlet.java

📁 intra_mart是日本NDD公司开发的著名企业应用解决方案中间件。集成了J2ee服务器
💻 JAVA
字号:
/*
 * ServiceServlet.java
 *
 * Created on 2001/12/25, 15:16
 */

package jp.co.intra_mart.framework.base.service;

import java.io.IOException;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jp.co.intra_mart.framework.system.exception.ApplicationException;
import jp.co.intra_mart.framework.system.exception.SystemException;
import jp.co.intra_mart.framework.system.log.LogConstant;
import jp.co.intra_mart.framework.system.log.LogManager;

/**
 * 僒乕價僗傪怳傝暘偗傞僒乕僽儗僢僩偱偡丅
 *
 * @author INTRAMART
 * @version 1.0
 */
public class ServiceServlet extends HttpServlet {

    /**
     * 僒乕價僗儅僱乕僕儍
     */
    private ServiceManager manager;

    /**
     * 僒乕價僗僾儘僷僥傿僴儞僪儔
     */
    private ServicePropertyHandler handler;

    /**
     * ServiceServlet傪怴婯偵惗惉偟傑偡丅
     */
    public ServiceServlet() {
        super();
    }

    /**
     * 儕僋僄僗僩偺忣曬傪暘妱偡傞僙僷儗乕僞
     * @since 5.0
     */
    public static final String REQUEST_SEPARATOR = "-";
    
    /**
     * 僒乕僽儗僢僩傪弶婜壔偟傑偡丅
     *
     * @param servletConfig ServletConfig
     * @throws ServletException 僒乕僽儗僢僩弶婜壔帪偵椺奜偑敪惗
     */
    public void init(ServletConfig servletConfig) throws ServletException {

        // ServletConfig偺愝掕
        super.init(servletConfig);

        // 僒乕價僗儅僱乕僕儍偺愝掕
        try {
            this.manager = ServiceManager.getServiceManager();
        } catch (ServiceManagerException e) {
            throw new ServletException(e.getMessage(), e);
        }

        // 僒乕價僗僾儘僷僥傿僴儞僪儔偺愝掕
        this.handler = this.manager.getServicePropertyHandler();
    }

    /**
     * GET儊僜僢僪偵懳偡傞僒乕價僗傪峴偄傑偡丅
     * 偙偺儊僜僢僪偱偼懳墳偡傞僒乕價僗僐儞僩儘乕儔傪屇傃丄師偺夋柺偵慗堏偟傑偡丅
     *
     * @param request 儕僋僄僗僩
     * @param response 儗僗億儞僗
     * @throws ServletException 僒乕僽儗僢僩椺奜偑敪惗
     * @throws IOException 擖弌椡椺奜偑敪惗
     */
    protected void doGet(
        HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException {
        try {
            execute(request, response);
        } catch (ServiceServletException e) {
            throw new ServletException(e.getMessage(), e);
        } catch (ServicePropertyException e) {
            throw new ServletException(e.getMessage(), e);
        } catch (ServiceControllerException e) {
            throw new ServletException(e.getMessage(), e);
        } catch (TransitionException e) {
            throw new ServletException(e.getMessage(), e);
        }
    }

    /**
     * POST儊僜僢僪偵懳偡傞僒乕價僗傪峴偄傑偡丅
     * 偙偺儊僜僢僪偱偼懳墳偡傞僒乕價僗僐儞僩儘乕儔傪屇傃丄師偺夋柺偵慗堏偟傑偡丅
     *
     * @param request 儕僋僄僗僩
     * @param response 儗僗億儞僗
     * @throws ServletException 僒乕僽儗僢僩椺奜偑敪惗
     * @throws IOException 擖弌椡椺奜偑敪惗
     */
    protected void doPost(
        HttpServletRequest request,
        HttpServletResponse response)
        throws ServletException, IOException {
        try {
            execute(request, response);
        } catch (ServiceServletException e) {
            throw new ServletException(e.getMessage(), e);
        } catch (ServicePropertyException e) {
            throw new ServletException(e.getMessage(), e);
        } catch (ServiceControllerException e) {
            throw new ServletException(e.getMessage(), e);
        } catch (TransitionException e) {
            throw new ServletException(e.getMessage(), e);
        }
    }

    /**
     * 儕僋僄僗僩偵懳偡傞張棟傪峴偄傑偡丅
     * 偙偺儊僜僢僪偱偼懳墳偡傞僒乕價僗僐儞僩儘乕儔傪屇傃丄師偺夋柺偵慗堏偟傑偡丅
     *
     * @param request 儕僋僄僗僩
     * @param response 儗僗億儞僗
     * @throws ServiceServletException 僒乕價僗偵娭楢偡傞椺奜偑敪惗
     * @throws ServicePropertyException 僒乕價僗僾儘僷僥傿庢摼帪偵椺奜偑敪惗
     * @throws ServiceControllerException 僒乕價僗僐儞僩儘乕儔庢摼帪偵椺奜偑敪惗
     * @throws TransitionException 僩儔儞僕僔儑儞椺奜偑敪惗
     * @throws ServletException 僒乕僽儗僢僩椺奜偑敪惗
     * @throws IOException 僒乕僽儗僢僩椺奜偑敪惗
     * @see ServiceController
     * @see Transition
     */
    private void execute(
        HttpServletRequest request,
        HttpServletResponse response)
        throws
            ServiceServletException,
            ServicePropertyException,
            ServiceControllerException,
            TransitionException,
            ServletException,
            IOException {

        String application = null;
        String service = null;
        ServiceController controller = null;
        Transition transition = null;
        ServiceResult result = null;
        String nextPage = null;
        Locale locale = this.manager.getLocale(request, response);

        // 傾僾儕働乕僔儑儞ID偺庢摼
        application = this.manager.getApplication(request, response);
        if (application == null || application.equals("")) {
            String errorMessage = null;
            try {
                errorMessage =
                    ResourceBundle
                        .getBundle("jp.co.intra_mart.framework.base.service.i18n")
                        .getString("ServiceServlet.ApplicationNotRequested")
					 + " - "
					 + request.getServletPath();
            } catch (MissingResourceException e) {
            }
            ServiceServletException exception =
                new ServiceServletException(errorMessage);
            LogManager.getLogManager().getLogAgent().sendMessage(
                ServiceServlet.class.getName(),
                LogConstant.LEVEL_ERROR,
                ServiceManager.LOG_HEAD + errorMessage,
                exception);
            throw exception;
        }

        // 僒乕價僗ID偺庢摼
        service = this.manager.getService(request, response);
        if (service == null || service.equals("")) {
            String errorMessage = null;
            try {
                errorMessage =
                    ResourceBundle
                        .getBundle("jp.co.intra_mart.framework.base.service.i18n")
                        .getString("ServiceServlet.ServiceNotRequested")
				 + " - "
				 + request.getServletPath();
            } catch (MissingResourceException e) {
            }
            ServiceServletException exception =
                new ServiceServletException(errorMessage);
            LogManager.getLogManager().getLogAgent().sendMessage(
                ServiceServlet.class.getName(),
                LogConstant.LEVEL_ERROR,
                ServiceManager.LOG_HEAD + errorMessage,
                exception);
            throw exception;
        }

        // 僒乕價僗僐儞僩儘乕儔偺庢摼
        controller =
            this.manager.getServiceController(application, service, locale);

        // 僩儔儞僕僔儑儞偺庢摼
        transition = this.manager.getTransition(application, service, locale);
        transition.setRequest(request);
        transition.setResponse(response);

        // 僒乕價僗僐儞僩儘乕儔偑懚嵼偡傞応崌偺傒張棟傪幚峴偡傞
        if (controller != null) {

            // 儕僋僄僗僩丄儗僗億儞僗偺愝掕
            controller.setRequest(request);
            controller.setResponse(response);

            // 擖椡僠僃僢僋
            try {
                controller.check();
            } catch (RequestException e) {
                nextPage = transition.getInputErrorPage(e);
                request.setAttribute(
                    this.handler.getExceptionAttributeName(),
                    e);
                getServletConfig().getServletContext().getRequestDispatcher(
                    nextPage).forward(
                    request,
                    response);
                return;
            } catch (SystemException e) {
                // 僔僗僥儉椺奜偑敪惗偟偨応崌
                LogManager.getLogManager().getLogAgent().sendMessage(
                    ServiceServlet.class.getName(),
                    LogConstant.LEVEL_ERROR,
                    ServiceManager.LOG_HEAD + e.getMessage(),
                    e);
                nextPage = transition.getSystemErrorPage(e);
                request.setAttribute(
                    this.handler.getExceptionAttributeName(),
                    e);
                getServletConfig().getServletContext().getRequestDispatcher(
                    nextPage).forward(
                    request,
                    response);
                return;
            }

            // 張棟幚峴
            try {
                result = controller.service();
            } catch (SystemException e) {
                // 僔僗僥儉椺奜偑敪惗偟偨応崌
                LogManager.getLogManager().getLogAgent().sendMessage(
                    ServiceServlet.class.getName(),
                    LogConstant.LEVEL_ERROR,
                    ServiceManager.LOG_HEAD + e.getMessage(),
                    e);
                nextPage = transition.getSystemErrorPage(e);
                request.setAttribute(
                    this.handler.getExceptionAttributeName(),
                    e);
                getServletConfig().getServletContext().getRequestDispatcher(
                    nextPage).forward(
                    request,
                    response);
                return;
            } catch (ApplicationException e) {
                // 傾僾儕働乕僔儑儞椺奜偑敪惗偟偨応崌
                LogManager.getLogManager().getLogAgent().sendMessage(
                    ServiceServlet.class.getName(),
                    LogConstant.LEVEL_ERROR,
                    ServiceManager.LOG_HEAD + e.getMessage(),
                    e);
                nextPage = transition.getServiceErrorPage(e);
                request.setAttribute(
                    this.handler.getExceptionAttributeName(),
                    e);
                getServletConfig().getServletContext().getRequestDispatcher(
                    nextPage).forward(
                    request,
                    response);
                return;
            }
        }

        // 師偺儁乕僕傊偺忣曬傪愝掕偡傞
        transition.setResult(result);
        transition.setInformation();

        // 師偺儁乕僕偵慗堏偡傞
        try {
            transition.transfer();
        } catch (SystemException e) {
            // 僔僗僥儉椺奜偑敪惗偟偨応崌
            LogManager.getLogManager().getLogAgent().sendMessage(
                ServiceServlet.class.getName(),
                LogConstant.LEVEL_ERROR,
                ServiceManager.LOG_HEAD + e.getMessage(),
                e);
            nextPage = transition.getSystemErrorPage(e);
            request.setAttribute(this.handler.getExceptionAttributeName(), e);
            getServletConfig().getServletContext().getRequestDispatcher(
                nextPage).forward(
                request,
                response);
            return;
        }
    }

    /**
     * 僒乕僽儗僢僩傪夝曻偟傑偡丅
     */
    public void destroy() {
        this.manager = null;
        super.destroy();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -