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

📄 serviceeventhandler.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: ServiceEventHandler.java 6475 2006-01-07 17:57:17Z jonesde $ * * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */package org.ofbiz.webapp.event;import java.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Locale;import java.util.Map;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.commons.fileupload.DiskFileUpload;import org.apache.commons.fileupload.FileItem;import org.apache.commons.fileupload.FileUpload;import org.apache.commons.fileupload.FileUploadException;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilHttp;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.util.ByteWrapper;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ModelParam;import org.ofbiz.service.ModelService;import org.ofbiz.service.ServiceAuthException;import org.ofbiz.service.ServiceValidationException;/** * ServiceEventHandler - Service Event Handler * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @version    $Rev: 6475 $ * @since      2.0 */public class ServiceEventHandler implements EventHandler {    public static final String module = ServiceEventHandler.class.getName();    public static final String SYNC = "sync";    public static final String ASYNC = "async";    /**     * @see org.ofbiz.webapp.event.EventHandler#init(javax.servlet.ServletContext)     */    public void init(ServletContext context) throws EventHandlerException {    }    /**     * @see org.ofbiz.webapp.event.EventHandler#invoke(java.lang.String, java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)     */    public String invoke(String eventPath, String eventMethod, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException {        // make sure we have a valid reference to the Service Engine        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");        if (dispatcher == null) {            throw new EventHandlerException("The local service dispatcher is null");        }        DispatchContext dctx = dispatcher.getDispatchContext();        if (dctx == null) {            throw new EventHandlerException("Dispatch context cannot be found");        }        // get the details for the service(s) to call        String mode = SYNC;        String serviceName = null;        if (eventPath == null || eventPath.length() == 0) {            mode = SYNC;        } else {            mode = eventPath;        }        // nake sure we have a defined service to call        serviceName = eventMethod;        if (serviceName == null) {            throw new EventHandlerException("Service name (eventMethod) cannot be null");        }        if (Debug.verboseOn()) Debug.logVerbose("[Set mode/service]: " + mode + "/" + serviceName, module);        // some needed info for when running the service        Locale locale = UtilHttp.getLocale(request);        HttpSession session = request.getSession();        GenericValue userLogin = (GenericValue) session.getAttribute("userLogin");        // get the service model to generate context        ModelService model = null;        try {            model = dctx.getModelService(serviceName);        } catch (GenericServiceException e) {            throw new EventHandlerException("Problems getting the service model", e);        }        if (model == null) {            throw new EventHandlerException("Problems getting the service model");        }        if (Debug.verboseOn()) Debug.logVerbose("[Processing]: SERVICE Event", module);        if (Debug.verboseOn()) Debug.logVerbose("[Using delegator]: " + dispatcher.getDelegator().getDelegatorName(), module);        // get the http upload configuration        String maxSizeStr = UtilProperties.getPropertyValue("general.properties", "http.upload.max.size", "-1");        long maxUploadSize = -1;        try {            maxUploadSize = Long.parseLong(maxSizeStr);        } catch (NumberFormatException e) {            Debug.logError(e, "Unable to obtain the max upload size from general.properties; using default -1", module);            maxUploadSize = -1;        }        // check for multipart content types which may have uploaded items        boolean isMultiPart = FileUpload.isMultipartContent(request);        Map multiPartMap = new HashMap();        if (isMultiPart) {            DiskFileUpload upload = new DiskFileUpload();            upload.setSizeMax(maxUploadSize);            List uploadedItems = null;            try {                uploadedItems = upload.parseRequest(request);            } catch (FileUploadException e) {                throw new EventHandlerException("Problems reading uploaded data", e);            }            if (uploadedItems != null) {                Iterator i = uploadedItems.iterator();                while (i.hasNext()) {                    FileItem item = (FileItem) i.next();                    String fieldName = item.getFieldName();                    //byte[] itemBytes = item.get();                    //Debug.log("Item Info : " + item.getName() + " / " + item.getSize() + " / " + item.getContentType(), module);                    if (item.isFormField() || item.getSize() == 0) {                        if (multiPartMap.containsKey(fieldName)) {                            Object mapValue = multiPartMap.get(fieldName);                            if (mapValue instanceof List) {                                ((List) mapValue).add(item.getString());                            } else if (mapValue instanceof String) {                                List newList = new ArrayList();                                newList.add((String) mapValue);                                newList.add(item.getString());                                multiPartMap.put(fieldName, newList);                            } else {                                Debug.logWarning("Form field found [" + fieldName + "] which was not handled!", module);                            }                        } else {                            multiPartMap.put(fieldName, item.getString());                        }                    } else {                        String fileName = item.getName();

⌨️ 快捷键说明

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