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

📄 servicedispatcher.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                if (modelService.auth && userLogin == null) {                    throw new ServiceAuthException("User authorization is required for this service: " + modelService.name + modelService.debugInfo());                }                // pre-validate ECA                if (eventMap != null) ServiceEcaUtil.evalRules(modelService.name, eventMap, "in-validate", ctx, context, result, false, false);                // check for pre-validate failure/erros                isFailure = ModelService.RESPOND_FAIL.equals(result.get(ModelService.RESPONSE_MESSAGE));                isError = ModelService.RESPOND_ERROR.equals(result.get(ModelService.RESPONSE_MESSAGE));                // validate the context                if (modelService.validate && !isError && !isFailure) {                    try {                        modelService.validate(context, ModelService.IN_PARAM, locale);                    } catch (ServiceValidationException e) {                        Debug.logError(e, "Incoming context (in runSync : " + modelService.name + ") does not match expected requirements", module);                        throw e;                    }                }                // pre-invoke ECA                if (eventMap != null) ServiceEcaUtil.evalRules(modelService.name, eventMap, "invoke", ctx, context, result, false, false);                // check for pre-invoke failure/erros                isFailure = ModelService.RESPOND_FAIL.equals(result.get(ModelService.RESPONSE_MESSAGE));                isError = ModelService.RESPOND_ERROR.equals(result.get(ModelService.RESPONSE_MESSAGE));                // ===== invoke the service =====                if (!isError && !isFailure) {                    Map invokeResult = engine.runSync(localName, modelService, context);                    engine.sendCallbacks(modelService, context, invokeResult, GenericEngine.SYNC_MODE);                    if (invokeResult != null) {                        result.putAll(invokeResult);                    } else {                        Debug.logWarning("Service (in runSync : " + modelService.name + ") returns null result", module);                    }                }                // re-check the errors/failures                isFailure = ModelService.RESPOND_FAIL.equals(result.get(ModelService.RESPONSE_MESSAGE));                isError = ModelService.RESPOND_ERROR.equals(result.get(ModelService.RESPONSE_MESSAGE));                // create a new context with the results to pass to ECA services; necessary because caller may reuse this context                ecaContext = FastMap.newInstance();                ecaContext.putAll(context);                // copy all results: don't worry parameters that aren't allowed won't be passed to the ECA services                ecaContext.putAll(result);                // validate the result                if (modelService.validate && validateOut) {                    // pre-out-validate ECA                    if (eventMap != null) ServiceEcaUtil.evalRules(modelService.name, eventMap, "out-validate", ctx, ecaContext, result, isError, isFailure);                    try {                        modelService.validate(result, ModelService.OUT_PARAM, locale);                    } catch (ServiceValidationException e) {                        Debug.logError(e, "Outgoing result (in runSync : " + modelService.name + ") does not match expected requirements", module);                        throw e;                    }                }                // pre-commit ECA                if (eventMap != null) ServiceEcaUtil.evalRules(modelService.name, eventMap, "commit", ctx, ecaContext, result, isError, isFailure);                // check for failure and log on info level; this is used for debugging                if (isFailure) {                    Debug.logWarning("Service Failure [" + modelService.name + "]: " + ServiceUtil.getErrorMessage(result), module);                }            } catch (Throwable t) {                if (Debug.timingOn()) {                    UtilTimer.closeTimer(localName + " / " + modelService.name, "Sync service failed...", module);                }                String errMsg = "Service [" + modelService.name + "] threw an unexpected exception/error";                Debug.logError(t, errMsg, module);                engine.sendCallbacks(modelService, context, t, GenericEngine.SYNC_MODE);                try {                    TransactionUtil.rollback(beganTrans, errMsg, t);                } catch (GenericTransactionException te) {                    Debug.logError(te, "Cannot rollback transaction", module);                }                checkDebug(modelService, 0, debugging);                rs.setEndStamp();                if (t instanceof ServiceAuthException) {                    throw (ServiceAuthException) t;                } else if (t instanceof ServiceValidationException) {                    throw (ServiceValidationException) t;                } else if (t instanceof GenericServiceException) {                    throw (GenericServiceException) t;                } else {                    throw new GenericServiceException("Service [" + modelService.name + "] Failed" + modelService.debugInfo() , t);                }            } finally {                // if there was an error, rollback transaction, otherwise commit                if (isError) {                    String errMsg = "Service Error [" + modelService.name + "]: " + ServiceUtil.getErrorMessage(result);                    // try to log the error                    Debug.logError(errMsg, module);                    // rollback the transaction                    try {                        TransactionUtil.rollback(beganTrans, errMsg, null);                    } catch (GenericTransactionException e) {                        Debug.logError(e, "Could not rollback transaction", module);                    }                } else {                    // commit the transaction                    try {                        TransactionUtil.commit(beganTrans);                    } catch (GenericTransactionException e) {                        Debug.logError(e, "Could not commit transaction", module);                        throw new GenericServiceException("Commit transaction failed");                    }                }            }        } catch (GenericTransactionException te) {            Debug.logError(te, "Problems with the transaction", module);            throw new GenericServiceException("Problems with the transaction.", te.getNested());        } finally {            // resume the parent transaction            if (parentTransaction != null) {                try {                    TransactionUtil.resume(parentTransaction);                } catch (GenericTransactionException ite) {                    Debug.logWarning(ite, "Transaction error, not resumed", module);                    throw new GenericServiceException("Resume transaction exception, see logs");                }            }        }        // pre-return ECA        if (eventMap != null) ServiceEcaUtil.evalRules(modelService.name, eventMap, "return", ctx, ecaContext, result, isError, isFailure);        checkDebug(modelService, 0, debugging);        rs.setEndStamp();        if (timer != null) {            timer.setLog(true);            timer.timerString("Sync service finished", module);        }        return result;    }    /**     * Run the service asynchronously, passing an instance of GenericRequester that will receive the result.     * @param localName Name of the context to use.     * @param service Service model object.     * @param context Map of name, value pairs composing the context.     * @param requester Object implementing GenericRequester interface which will receive the result.     * @param persist True for store/run; False for run.     * @throws ServiceAuthException     * @throws ServiceValidationException     * @throws GenericServiceException     */    public void runAsync(String localName, ModelService service, Map context, GenericRequester requester, boolean persist) throws ServiceAuthException, ServiceValidationException, GenericServiceException {        if (Debug.timingOn()) {            UtilTimer.timerLog(localName + " / " + service.name, "ASync service started...", module);        }        boolean debugging = checkDebug(service, 1, true);        if (Debug.verboseOn()) {            Debug.logVerbose("[ServiceDispatcher.runAsync] : prepareing service " + service.name + " [" + service.location + "/" + service.invoke +                "] (" + service.engineName + ")", module);        }        // setup the result map        Map result = FastMap.newInstance();        boolean isFailure = false;        boolean isError = false;        // set up the running service log        this.logService(localName, service, GenericEngine.ASYNC_MODE);        // check the locale        Locale locale = this.checkLocale(context);        // setup the engine and context        DispatchContext ctx = (DispatchContext) localContext.get(localName);        GenericEngine engine = this.getGenericEngine(service.engineName);        // for isolated transactions        Transaction parentTransaction = null;        // start the transaction        boolean beganTrans = false;        try {            if (service.useTransaction) {                beganTrans = TransactionUtil.begin(service.transactionTimeout);                // isolate the transaction if defined                if (service.requireNewTransaction && !beganTrans) {                    parentTransaction = TransactionUtil.suspend();                    // now start a new transaction                    beganTrans = TransactionUtil.begin(service.transactionTimeout);                }            }            // XAResource debugging            if (beganTrans && TransactionUtil.debugResources) {                DebugXaResource dxa = new DebugXaResource(service.name);                try {                    dxa.enlist();                } catch (Exception e) {                    Debug.logError(e, module);                }            }            try {                // get eventMap once for all calls for speed, don't do event calls if it is null                Map eventMap = ServiceEcaUtil.getServiceEventMap(service.name);                // pre-auth ECA                if (eventMap != null) ServiceEcaUtil.evalRules(service.name, eventMap, "auth", ctx, context, result, isError, isFailure);                context = checkAuth(localName, context, service);                Object userLogin = context.get("userLogin");                if (service.auth && userLogin == null)                    throw new ServiceAuthException("User authorization is required for this service: " + service.name + service.debugInfo());                // pre-validate ECA                if (eventMap != null) ServiceEcaUtil.evalRules(service.name, eventMap, "in-validate", ctx, context, result, isError, isFailure);                // check for pre-validate failure/errors                isFailure = ModelService.RESPOND_FAIL.equals(result.get(ModelService.RESPONSE_MESSAGE));                isError = ModelService.RESPOND_ERROR.equals(result.get(ModelService.RESPONSE_MESSAGE));                // validate the context                if (service.validate && !isError && !isFailure) {                    try {                        service.validate(context, ModelService.IN_PARAM, locale);                    } catch (ServiceValidationException e) {                        Debug.logError(e, "Incoming service context (in runAsync: " + service.name + ") does not match expected requirements", module);                        throw e;                    }                }                // run the service                if (!isError && !isFailure) {                    if (requester != null) {                        engine.runAsync(localName, service, context, requester, persist);                    } else {                        engine.runAsync(localName, service, context, persist);                    }                    engine.sendCallbacks(service, context, null, GenericEngine.ASYNC_MODE);                }                if (Debug.timingOn()) {                    UtilTimer.closeTimer(localName + " / " + service.name, "ASync service finished...", module);                }                checkDebug(service, 0, debugging);            } catch (Throwable t) {                if (Debug.timingOn()) {                    UtilTimer.closeTimer(localName + " / " + service.name, "ASync service failed...", module);                }                String errMsg = "Service [" + service.name + "] threw an unexpected exception/error";                Debug.logError(t, errMsg, module);                engine.sendCallbacks(service, context, t, GenericEngine.ASYNC_MODE);                try {                    TransactionUtil.rollback(beganTrans, errMsg, t);                } catch (GenericTransactionException te) {                    Debug.logError(te, "Cannot rollback transaction", module);                }                checkDebug(service, 0, debugging);                if (t instanceof ServiceAuthException) {                    throw (ServiceAuthException) t;                } else if (t instanceof ServiceValidationException) {                    throw (ServiceValidationException) t;                } else if (t instanceof GenericServiceException) {                    throw (GenericServiceException) t;                } else {                    throw new GenericServiceException("Service [" + service.name + "] Failed" + service.debugInfo() , t);                }            } finally {                // always try to commit the transaction since we don't know in this case if its was an error or not                try {                    TransactionUtil.commit(beganTrans);                } catch (GenericTransactionException e) {                    Debug.logError(e, "Could not commit transaction", module);                    throw new GenericServiceException("Commit transaction failed");                }            }        } catch (GenericTransactionException se) {            Debug.logError(se, "Problems with the transaction", module);            throw new GenericServiceException("Problems with the transaction: " + se.getMessage() + "; See logs for more detail");        } finally {            // resume the parent transaction            if (parentTransaction != null) {                try {                    TransactionUtil.resume(parentTransaction);                } catch (GenericTransactionException ise) {                    Debug.logError(ise, "Trouble resuming parent transaction", module);                    throw new GenericServiceException("Resume transaction exception: " + ise.getMessage() + "; See logs for more detail");                }            }        }    }    /**     * Run the service asynchronously and IGNORE the result.     * @param localName Name of the context to use.     * @param service Service model object.     * @param context Map of name, value pairs composing the context.     * @param persist True for store/run; False for run.     * @throws ServiceAuthException     * @throws ServiceValidationException     * @throws GenericServiceException     */    public void runAsync(String localName, ModelService service, Map context, boolean persist) throws ServiceAuthException, ServiceValidationException, GenericServiceException {        this.runAsync(localName, service, context, null, persist);

⌨️ 快捷键说明

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