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

📄 odeservice.java

📁 bpel执行引擎用来执行bpel业务流程
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements.  See the NOTICE file * distributed with this work for additional information * regarding copyright ownership.  The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License.  You may obtain a copy of the License at * *    http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied.  See the License for the * specific language governing permissions and limitations * under the License. */package org.apache.ode.axis2;import org.apache.axiom.soap.SOAPEnvelope;import org.apache.axiom.soap.SOAPFactory;import org.apache.axiom.soap.SOAPFault;import org.apache.axis2.AxisFault;import org.apache.axis2.context.MessageContext;import org.apache.axis2.description.AxisService;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.ode.axis2.util.SoapMessageConverter;import org.apache.ode.bpel.epr.EndpointFactory;import org.apache.ode.bpel.epr.MutableEndpoint;import org.apache.ode.bpel.epr.WSAEndpoint;import org.apache.ode.bpel.iapi.BpelServer;import org.apache.ode.bpel.iapi.EndpointReference;import org.apache.ode.bpel.iapi.Message;import org.apache.ode.bpel.iapi.MessageExchange;import org.apache.ode.bpel.iapi.MyRoleMessageExchange;import org.apache.ode.bpel.iapi.ProcessConf;import org.apache.ode.utils.DOMUtils;import org.apache.ode.utils.GUID;import org.apache.ode.utils.Namespaces;import org.w3c.dom.Document;import org.w3c.dom.Element;import javax.transaction.TransactionManager;import javax.wsdl.Definition;import javax.wsdl.Port;import javax.wsdl.Service;import javax.wsdl.extensions.UnknownExtensibilityElement;import javax.wsdl.extensions.http.HTTPAddress;import javax.wsdl.extensions.soap.SOAPAddress;import javax.xml.namespace.QName;import java.util.concurrent.Future;import java.util.concurrent.TimeUnit;/** * A running service, encapsulates the Axis service, its receivers and our * receivers as well. * * @author Matthieu Riou <mriou at apache dot org> */public class ODEService {    private static final Log __log = LogFactory.getLog(ODEService.class);    private AxisService _axisService;    private BpelServer _server;    private TransactionManager _txManager;    private ProcessConf _pconf;    private Definition _wsdlDef;    private QName _serviceName;    private String _portName;    private WSAEndpoint _serviceRef;    private SoapMessageConverter _converter;    public ODEService(AxisService axisService, ProcessConf pconf, QName serviceName, String portName, BpelServer server,                      TransactionManager txManager) throws AxisFault {        _axisService = axisService;        _server = server;        _txManager = txManager;        _pconf = pconf;        _wsdlDef = pconf.getDefinitionForService(serviceName);        _serviceName = serviceName;        _portName = portName;        _serviceRef = EndpointFactory.convertToWSA(createServiceRef(genEPRfromWSDL(_wsdlDef, serviceName, portName)));        _converter = new SoapMessageConverter(_wsdlDef, serviceName, portName);    }    public void onAxisMessageExchange(MessageContext msgContext, MessageContext outMsgContext, SOAPFactory soapFactory)            throws AxisFault {        boolean success = true;        MyRoleMessageExchange odeMex = null;        Future responseFuture = null;        try {            _txManager.begin();            if (__log.isDebugEnabled()) __log.debug("Starting transaction.");            // Creating mesage exchange            String messageId = new GUID().toString();            odeMex = _server.getEngine().createMessageExchange("" + messageId, _serviceName,                    msgContext.getAxisOperation().getName().getLocalPart());            __log.debug("ODE routed to operation " + odeMex.getOperation() + " from service " + _serviceName);            if (odeMex.getOperation() != null) {                // Preparing message to send to ODE                Message odeRequest = odeMex.createMessage(odeMex.getOperation().getInput().getMessage().getQName());                _converter.parseSoapRequest(odeRequest, msgContext.getEnvelope(), odeMex.getOperation());                readHeader(msgContext, odeMex);                if (__log.isDebugEnabled()) {                    __log.debug("Invoking ODE using MEX " + odeMex);                    __log.debug("Message content:  " + DOMUtils.domToString(odeRequest.getMessage()));                }                // Invoke ODE                responseFuture = odeMex.invoke(odeRequest);                __log.debug("Commiting ODE MEX " + odeMex);                try {                    if (__log.isDebugEnabled()) __log.debug("Commiting transaction.");                    _txManager.commit();                } catch (Exception e) {                    __log.error("Commit failed", e);                    success = false;                }            } else {                success = false;            }        } catch (Exception e) {            __log.error("Exception occured while invoking ODE", e);            success = false;            throw new OdeFault("An exception occured while invoking ODE.", e);        } finally {            if (!success) {                if (odeMex != null) odeMex.release();                try {                    _txManager.rollback();                } catch (Exception e) {                    throw new OdeFault("Rollback failed", e);                }            }        }        if (odeMex.getOperation().getOutput() != null) {            // Waits for the response to arrive            try {                responseFuture.get(getTimeout(), TimeUnit.MILLISECONDS);            } catch (Exception e) {                String errorMsg = "Timeout or execution error when waiting for response to MEX "                        + odeMex + " " + e.toString();                __log.error(errorMsg);                throw new OdeFault(errorMsg);            }            if (outMsgContext != null) {                SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();                outMsgContext.setEnvelope(envelope);                // Hopefully we have a response                __log.debug("Handling response for MEX " + odeMex);                boolean commit = false;                try {                    if (__log.isDebugEnabled()) __log.debug("Starting transaction.");                    _txManager.begin();                } catch (Exception ex) {                    throw new OdeFault("Error starting transaction!", ex);                }                try {                    // Refreshing the message exchange                    odeMex = (MyRoleMessageExchange) _server.getEngine().getMessageExchange(odeMex.getMessageExchangeId());                    onResponse(odeMex, outMsgContext);                    commit = true;                } catch (AxisFault af) {                    __log.warn("MEX produced a fault " + odeMex, af);                    commit = true;                    throw af;                } catch (Exception e) {                    __log.error("Error processing response for MEX " + odeMex, e);                    throw new OdeFault("An exception occured when invoking ODE.", e);                } finally {                    odeMex.release();                    if (commit) {                        try {                            if (__log.isDebugEnabled()) __log.debug("Comitting transaction.");                            _txManager.commit();                        } catch (Exception e) {                            throw new OdeFault("Commit failed!", e);                        }                    } else {

⌨️ 快捷键说明

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