From a99f088f7ea6e0d13f6457114e31488726fa5840 Mon Sep 17 00:00:00 2001 From: rfeng Date: Tue, 15 Jul 2008 22:06:58 +0000 Subject: Change the package names and bundle symbolic name to avoid conflicts in OSGi git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@677065 13f79535-47bb-0310-9956-ffa450edef68 --- java/sca/modules/implementation-bpel-ode/pom.xml | 4 +- .../ode/provider/BPELImplementationProvider.java | 132 +++++++++++ .../BPELImplementationProviderFactory.java | 69 ++++++ .../bpel/ode/provider/BPELInvoker.java | 251 +++++++++++++++++++++ .../bpel/provider/BPELImplementationProvider.java | 132 ----------- .../BPELImplementationProviderFactory.java | 69 ------ .../implementation/bpel/provider/BPELInvoker.java | 251 --------------------- ...cany.sca.provider.ImplementationProviderFactory | 2 +- .../bpel/EmbeddedODEServerTestCase.java | 148 ------------ .../bpel/ode/EmbeddedODEServerTestCase.java | 148 ++++++++++++ .../src/test/resources/log4j.properties | 2 +- 11 files changed, 604 insertions(+), 604 deletions(-) create mode 100644 java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java create mode 100644 java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProviderFactory.java create mode 100644 java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java delete mode 100644 java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java delete mode 100644 java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.java delete mode 100644 java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java delete mode 100644 java/sca/modules/implementation-bpel-ode/src/test/java/org/apache/tuscany/sca/implementation/bpel/EmbeddedODEServerTestCase.java create mode 100644 java/sca/modules/implementation-bpel-ode/src/test/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServerTestCase.java (limited to 'java/sca') diff --git a/java/sca/modules/implementation-bpel-ode/pom.xml b/java/sca/modules/implementation-bpel-ode/pom.xml index e2dbafd0aa..f722c4ba9f 100644 --- a/java/sca/modules/implementation-bpel-ode/pom.xml +++ b/java/sca/modules/implementation-bpel-ode/pom.xml @@ -430,9 +430,9 @@ ${tuscany.version} - org.apache.tuscany.sca.implementation.bpel + org.apache.tuscany.sca.implementation.bpel.ode ${pom.name} - org.apache.tuscany.sca.implementation.bpel* + org.apache.tuscany.sca.implementation.bpel.ode* diff --git a/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java b/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java new file mode 100644 index 0000000000..7086e1bc2f --- /dev/null +++ b/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProvider.java @@ -0,0 +1,132 @@ +/* + * 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.tuscany.sca.implementation.bpel.ode.provider; + +import java.io.File; +import java.net.URL; + +import javax.transaction.TransactionManager; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; +import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; +import org.apache.tuscany.sca.implementation.bpel.ode.ODEDeployment; +import org.apache.tuscany.sca.implementation.bpel.ode.ODEInitializationException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * BPEL Implementation provider + * + * @version $Rev$ $Date$ + */ +public class BPELImplementationProvider implements ImplementationProvider { + private final Log __log = LogFactory.getLog(getClass()); + + private RuntimeComponent component; + private BPELImplementation implementation; + + private EmbeddedODEServer odeServer; + private TransactionManager txMgr; + + /** + * Constructs a new BPEL Implementation. + */ + public BPELImplementationProvider(RuntimeComponent component, + BPELImplementation implementation, + EmbeddedODEServer odeServer, + TransactionManager txMgr) { + this.component = component; + this.implementation = implementation; + this.odeServer = odeServer; + this.txMgr = txMgr; + } + + public Invoker createInvoker(RuntimeComponentService service, Operation operation) { + BPELInvoker invoker = new BPELInvoker(component, service, operation, odeServer, txMgr); + return invoker; + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + if(__log.isInfoEnabled()) { + __log.info("Starting " + component.getName()); + } + + try { + if (!odeServer.isInitialized()) { + // start ode server + odeServer.init(); + } + + URL deployURL = this.implementation.getProcessDefinition().getLocation(); + + File deploymentDir = new File(deployURL.toURI().getPath()).getParentFile(); + + if(__log.isInfoEnabled()) { + __log.info(">>> Deploying : " + deploymentDir.toString()); + } + + // deploy the process + if (odeServer.isInitialized()) { + try { + //txMgr.begin(); + odeServer.registerTuscanyRuntimeComponent(implementation.getProcess(), component); + // Replaced by Mike Edwards 23/05/2008 + //odeServer.deploy(new ODEDeployment(deploymentDir)); + odeServer.deploy(new ODEDeployment(deploymentDir), implementation ); + //txMgr.commit(); + } catch (Exception e) { + e.printStackTrace(); + //txMgr.rollback(); + } + } + + } catch (ODEInitializationException inite) { + throw new RuntimeException("BPEL Component Type Implementation : Error initializing embedded ODE server " + inite.getMessage(), inite); + } catch(Exception e) { + throw new RuntimeException("BPEl Component Type Implementation initialization failure : " + e.getMessage(), e); + } + } + + public void stop() { + if(__log.isInfoEnabled()) { + __log.info("Stopping " + component.getName()); + } + + if (odeServer.isInitialized()) { + // start ode server + odeServer.stop(); + } + + txMgr = null; + + if(__log.isInfoEnabled()) { + __log.info("Stopped !!!"); + } + } + +} diff --git a/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProviderFactory.java b/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProviderFactory.java new file mode 100644 index 0000000000..c5d6555a24 --- /dev/null +++ b/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELImplementationProviderFactory.java @@ -0,0 +1,69 @@ +/* + * 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.tuscany.sca.implementation.bpel.ode.provider; + +import javax.transaction.TransactionManager; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; +import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; +import org.apache.tuscany.sca.implementation.bpel.ode.GeronimoTxFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.osoa.sca.annotations.Destroy; + +/** + * BPEL Implementation provider factory + * + * We use the provider factory to instantiate a ODE server that is going to be injected in all BPEL components + * + * @version $Rev$ $Date$ + */ +public class BPELImplementationProviderFactory implements ImplementationProviderFactory { + + private EmbeddedODEServer odeServer; + private TransactionManager txMgr; + + /** + * Default constructor receiving an extension point + * @param extensionPoints + */ + public BPELImplementationProviderFactory(ExtensionPointRegistry extensionPoints) { + GeronimoTxFactory txFactory = new GeronimoTxFactory(); + txMgr = txFactory.getTransactionManager(); + this.odeServer = new EmbeddedODEServer(txMgr); + } + + /** + * Creates a new BPEL Implementation and inject the EmbeddedODEServer + */ + public ImplementationProvider createImplementationProvider(RuntimeComponent component, BPELImplementation implementation) { + return new BPELImplementationProvider(component, implementation, odeServer, txMgr); + } + + public Class getModelType() { + return BPELImplementation.class; + } + + @Destroy + public void destroy() { + txMgr = null; + } +} diff --git a/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java b/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java new file mode 100644 index 0000000000..f301082d59 --- /dev/null +++ b/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/provider/BPELInvoker.java @@ -0,0 +1,251 @@ +/* + * 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.tuscany.sca.implementation.bpel.ode.provider; + +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.Future; + +import javax.transaction.SystemException; +import javax.transaction.TransactionManager; +import javax.wsdl.Part; +import javax.xml.namespace.QName; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.ode.bpel.iapi.MyRoleMessageExchange; +import org.apache.ode.bpel.iapi.MessageExchange.Status; +import org.apache.ode.utils.DOMUtils; +import org.apache.ode.utils.GUID; +import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Implements a target invoker for BPEL component implementations. + * + * The target invoker is responsible for dispatching invocations to the particular + * component implementation logic. In this example we are simply delegating the + * CRUD operation invocations to the corresponding methods on our fake + * resource manager. + * + * @version $Rev$ $Date$ + */ +public class BPELInvoker implements Invoker { + protected final Log __log = LogFactory.getLog(getClass()); + + private EmbeddedODEServer odeServer; + private TransactionManager txMgr; + + private RuntimeComponent component; + private RuntimeComponentService service; + private Operation operation; + private QName bpelServiceName; + private String bpelOperationName; + private Part bpelOperationInputPart; + private Part bpelOperationOutputPart; + + public BPELInvoker(RuntimeComponent component, RuntimeComponentService service, Operation operation, EmbeddedODEServer odeServer, TransactionManager txMgr) { + this.component = component; + this.service = service; + this.operation = operation; + this.bpelOperationName = operation.getName(); + this.odeServer = odeServer; + this.txMgr = txMgr; + + initializeInvocation(); + } + + + private void initializeInvocation() { + + if(true){ + __log.debug("Initializing BPELInvoker"); + } + Interface interfaze = operation.getInterface(); + if(interfaze instanceof WSDLInterface){ + WSDLInterface wsdlInterface = null; + wsdlInterface = (WSDLInterface) interfaze; + + // The following commented out code is bogus and is replaced by what follows - Mike Edwards + // Service serviceDefinition = (Service) wsdlInterface.getWsdlDefinition().getDefinition().getAllServices().values().iterator().next(); + // bpelServiceName = serviceDefinition.getQName(); + // + // Fetch the service name from the service object + bpelServiceName = new QName( "http://tuscany.apache.org", service.getName() ); + //System.out.println("Actual service QName: " + bpelServiceName ); + + bpelOperationInputPart = (Part) wsdlInterface.getPortType().getOperation(bpelOperationName,null,null).getInput().getMessage().getParts().values().iterator().next(); + bpelOperationOutputPart = (Part) wsdlInterface.getPortType().getOperation(bpelOperationName,null,null).getOutput().getMessage().getParts().values().iterator().next(); + } + } + + public Message invoke(Message msg) { + try { + Object[] args = msg.getBody(); + Object resp = doTheWork(args); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setFaultBody(e.getCause()); + } + return msg; + } + + public Object doTheWork(Object[] args) throws InvocationTargetException { + Element response = null; + + if(! (operation.getInterface() instanceof WSDLInterface)) { + throw new InvocationTargetException(null,"Unsupported service contract"); + } + + if(true) { + System.out.println("Invoking bpel component : " + bpelServiceName + "#" + bpelOperationName); + } + + org.apache.ode.bpel.iapi.MyRoleMessageExchange mex = null; + Future onhold = null; + + //Process the BPEL process invocation + try { + txMgr.begin(); + mex = odeServer.getBpelServer().getEngine().createMessageExchange(new GUID().toString(), + bpelServiceName, + bpelOperationName); + + onhold = mex.invoke(createInvocationMessage(mex, args)); + + txMgr.commit(); + } catch (Exception e) { + try { + txMgr.rollback(); + } catch (SystemException se) { + + } + throw new InvocationTargetException(e, "Error invoking BPEL process : " + e.getMessage()); + } + + + // Waiting until the reply is ready in case the engine needs to continue in a different thread + if (onhold != null) { + try { + onhold.get(); + } catch (Exception e) { + throw new InvocationTargetException(e,"Error invoking BPEL process : " + e.getMessage()); + } + } + + //Process the BPEL invocation response + try { + txMgr.begin(); + // Reloading the mex in the current transaction, otherwise we can't + // be sure we have the "freshest" one. + mex = (MyRoleMessageExchange)odeServer.getBpelServer().getEngine().getMessageExchange(mex.getMessageExchangeId()); + + if(true) { + Status status = mex.getStatus(); + Element invocationResponse = mex.getResponse().getMessage(); + + System.out.println(">>>Invocation status:" + status.name()); + System.out.println(">>>Response:\n" + DOMUtils.domToString(invocationResponse)); + System.out.println(">>>Response:\n" + DOMUtils.domToString(invocationResponse)); + } + //process the method invocation result + response = processResponse(mex.getResponse().getMessage()); + + txMgr.commit(); + // end of transaction two + } catch (Exception e) { + try { + txMgr.rollback(); + } catch (SystemException se) { + + } + throw new InvocationTargetException(e, "Error retrieving BPEL process invocation status : " + e.getMessage()); + } + + + return response; + } + + /** + * Create BPEL Invocation message + * + * BPEL invocation message like : + * + * + * Hello + * + * + * @param args + * @return + */ + private org.apache.ode.bpel.iapi.Message createInvocationMessage(org.apache.ode.bpel.iapi.MyRoleMessageExchange mex, Object[] args) { + Document dom = DOMUtils.newDocument(); + + Element contentMessage = dom.createElement("message"); + Element contentPart = dom.createElement(bpelOperationInputPart.getName()); + Element payload = null; + + //TUSCANY-2321 - Properly handling Document or Element types + if(args[0] instanceof Document) { + payload = (Element) ((Document) args[0]).getFirstChild(); + } else { + payload = (Element) args[0]; + } + + contentPart.appendChild(dom.importNode(payload, true)); + contentMessage.appendChild(contentPart); + dom.appendChild(contentMessage); + + if(true) { + System.out.println("Creating invocation message:"); + System.out.println(">> args.....: " + DOMUtils.domToString(payload)); + System.out.println(">> message..:" + DOMUtils.domToString(dom.getDocumentElement())); + } + + org.apache.ode.bpel.iapi.Message request = mex.createMessage(new QName("", "")); + request.setMessage(dom.getDocumentElement()); + + return request; + } + + /** + * Process BPEL response + * + * + * + * World + * + * + * + * @param response + * @return + */ + private Element processResponse(Element response) { + // return (Element) DOMUtils.findChildByName(response, new QName("",bpelOperationOutputPart.getName())).getFirstChild(); + return (Element) DOMUtils.findChildByName(response, new QName("",bpelOperationOutputPart.getName())); + } +} diff --git a/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java b/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java deleted file mode 100644 index a48d5cb20a..0000000000 --- a/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * 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.tuscany.sca.implementation.bpel.provider; - -import java.io.File; -import java.net.URL; - -import javax.transaction.TransactionManager; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; -import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; -import org.apache.tuscany.sca.implementation.bpel.ode.ODEDeployment; -import org.apache.tuscany.sca.implementation.bpel.ode.ODEInitializationException; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.provider.ImplementationProvider; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; - -/** - * BPEL Implementation provider - * - * @version $Rev$ $Date$ - */ -public class BPELImplementationProvider implements ImplementationProvider { - private final Log __log = LogFactory.getLog(getClass()); - - private RuntimeComponent component; - private BPELImplementation implementation; - - private EmbeddedODEServer odeServer; - private TransactionManager txMgr; - - /** - * Constructs a new BPEL Implementation. - */ - public BPELImplementationProvider(RuntimeComponent component, - BPELImplementation implementation, - EmbeddedODEServer odeServer, - TransactionManager txMgr) { - this.component = component; - this.implementation = implementation; - this.odeServer = odeServer; - this.txMgr = txMgr; - } - - public Invoker createInvoker(RuntimeComponentService service, Operation operation) { - BPELInvoker invoker = new BPELInvoker(component, service, operation, odeServer, txMgr); - return invoker; - } - - public boolean supportsOneWayInvocation() { - return false; - } - - public void start() { - if(__log.isInfoEnabled()) { - __log.info("Starting " + component.getName()); - } - - try { - if (!odeServer.isInitialized()) { - // start ode server - odeServer.init(); - } - - URL deployURL = this.implementation.getProcessDefinition().getLocation(); - - File deploymentDir = new File(deployURL.toURI().getPath()).getParentFile(); - - if(__log.isInfoEnabled()) { - __log.info(">>> Deploying : " + deploymentDir.toString()); - } - - // deploy the process - if (odeServer.isInitialized()) { - try { - //txMgr.begin(); - odeServer.registerTuscanyRuntimeComponent(implementation.getProcess(), component); - // Replaced by Mike Edwards 23/05/2008 - //odeServer.deploy(new ODEDeployment(deploymentDir)); - odeServer.deploy(new ODEDeployment(deploymentDir), implementation ); - //txMgr.commit(); - } catch (Exception e) { - e.printStackTrace(); - //txMgr.rollback(); - } - } - - } catch (ODEInitializationException inite) { - throw new RuntimeException("BPEL Component Type Implementation : Error initializing embedded ODE server " + inite.getMessage(), inite); - } catch(Exception e) { - throw new RuntimeException("BPEl Component Type Implementation initialization failure : " + e.getMessage(), e); - } - } - - public void stop() { - if(__log.isInfoEnabled()) { - __log.info("Stopping " + component.getName()); - } - - if (odeServer.isInitialized()) { - // start ode server - odeServer.stop(); - } - - txMgr = null; - - if(__log.isInfoEnabled()) { - __log.info("Stopped !!!"); - } - } - -} diff --git a/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.java b/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.java deleted file mode 100644 index 4233db44e7..0000000000 --- a/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * 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.tuscany.sca.implementation.bpel.provider; - -import javax.transaction.TransactionManager; - -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.implementation.bpel.BPELImplementation; -import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; -import org.apache.tuscany.sca.implementation.bpel.ode.GeronimoTxFactory; -import org.apache.tuscany.sca.provider.ImplementationProvider; -import org.apache.tuscany.sca.provider.ImplementationProviderFactory; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.osoa.sca.annotations.Destroy; - -/** - * BPEL Implementation provider factory - * - * We use the provider factory to instantiate a ODE server that is going to be injected in all BPEL components - * - * @version $Rev$ $Date$ - */ -public class BPELImplementationProviderFactory implements ImplementationProviderFactory { - - private EmbeddedODEServer odeServer; - private TransactionManager txMgr; - - /** - * Default constructor receiving an extension point - * @param extensionPoints - */ - public BPELImplementationProviderFactory(ExtensionPointRegistry extensionPoints) { - GeronimoTxFactory txFactory = new GeronimoTxFactory(); - txMgr = txFactory.getTransactionManager(); - this.odeServer = new EmbeddedODEServer(txMgr); - } - - /** - * Creates a new BPEL Implementation and inject the EmbeddedODEServer - */ - public ImplementationProvider createImplementationProvider(RuntimeComponent component, BPELImplementation implementation) { - return new BPELImplementationProvider(component, implementation, odeServer, txMgr); - } - - public Class getModelType() { - return BPELImplementation.class; - } - - @Destroy - public void destroy() { - txMgr = null; - } -} diff --git a/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java b/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java deleted file mode 100644 index df194dd68d..0000000000 --- a/java/sca/modules/implementation-bpel-ode/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * 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.tuscany.sca.implementation.bpel.provider; - -import java.lang.reflect.InvocationTargetException; -import java.util.concurrent.Future; - -import javax.transaction.SystemException; -import javax.transaction.TransactionManager; -import javax.wsdl.Part; -import javax.xml.namespace.QName; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.ode.bpel.iapi.MyRoleMessageExchange; -import org.apache.ode.bpel.iapi.MessageExchange.Status; -import org.apache.ode.utils.DOMUtils; -import org.apache.ode.utils.GUID; -import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; -import org.apache.tuscany.sca.interfacedef.Interface; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -/** - * Implements a target invoker for BPEL component implementations. - * - * The target invoker is responsible for dispatching invocations to the particular - * component implementation logic. In this example we are simply delegating the - * CRUD operation invocations to the corresponding methods on our fake - * resource manager. - * - * @version $Rev$ $Date$ - */ -public class BPELInvoker implements Invoker { - protected final Log __log = LogFactory.getLog(getClass()); - - private EmbeddedODEServer odeServer; - private TransactionManager txMgr; - - private RuntimeComponent component; - private RuntimeComponentService service; - private Operation operation; - private QName bpelServiceName; - private String bpelOperationName; - private Part bpelOperationInputPart; - private Part bpelOperationOutputPart; - - public BPELInvoker(RuntimeComponent component, RuntimeComponentService service, Operation operation, EmbeddedODEServer odeServer, TransactionManager txMgr) { - this.component = component; - this.service = service; - this.operation = operation; - this.bpelOperationName = operation.getName(); - this.odeServer = odeServer; - this.txMgr = txMgr; - - initializeInvocation(); - } - - - private void initializeInvocation() { - - if(true){ - __log.debug("Initializing BPELInvoker"); - } - Interface interfaze = operation.getInterface(); - if(interfaze instanceof WSDLInterface){ - WSDLInterface wsdlInterface = null; - wsdlInterface = (WSDLInterface) interfaze; - - // The following commented out code is bogus and is replaced by what follows - Mike Edwards - // Service serviceDefinition = (Service) wsdlInterface.getWsdlDefinition().getDefinition().getAllServices().values().iterator().next(); - // bpelServiceName = serviceDefinition.getQName(); - // - // Fetch the service name from the service object - bpelServiceName = new QName( "http://tuscany.apache.org", service.getName() ); - //System.out.println("Actual service QName: " + bpelServiceName ); - - bpelOperationInputPart = (Part) wsdlInterface.getPortType().getOperation(bpelOperationName,null,null).getInput().getMessage().getParts().values().iterator().next(); - bpelOperationOutputPart = (Part) wsdlInterface.getPortType().getOperation(bpelOperationName,null,null).getOutput().getMessage().getParts().values().iterator().next(); - } - } - - public Message invoke(Message msg) { - try { - Object[] args = msg.getBody(); - Object resp = doTheWork(args); - msg.setBody(resp); - } catch (InvocationTargetException e) { - msg.setFaultBody(e.getCause()); - } - return msg; - } - - public Object doTheWork(Object[] args) throws InvocationTargetException { - Element response = null; - - if(! (operation.getInterface() instanceof WSDLInterface)) { - throw new InvocationTargetException(null,"Unsupported service contract"); - } - - if(true) { - System.out.println("Invoking bpel component : " + bpelServiceName + "#" + bpelOperationName); - } - - org.apache.ode.bpel.iapi.MyRoleMessageExchange mex = null; - Future onhold = null; - - //Process the BPEL process invocation - try { - txMgr.begin(); - mex = odeServer.getBpelServer().getEngine().createMessageExchange(new GUID().toString(), - bpelServiceName, - bpelOperationName); - - onhold = mex.invoke(createInvocationMessage(mex, args)); - - txMgr.commit(); - } catch (Exception e) { - try { - txMgr.rollback(); - } catch (SystemException se) { - - } - throw new InvocationTargetException(e, "Error invoking BPEL process : " + e.getMessage()); - } - - - // Waiting until the reply is ready in case the engine needs to continue in a different thread - if (onhold != null) { - try { - onhold.get(); - } catch (Exception e) { - throw new InvocationTargetException(e,"Error invoking BPEL process : " + e.getMessage()); - } - } - - //Process the BPEL invocation response - try { - txMgr.begin(); - // Reloading the mex in the current transaction, otherwise we can't - // be sure we have the "freshest" one. - mex = (MyRoleMessageExchange)odeServer.getBpelServer().getEngine().getMessageExchange(mex.getMessageExchangeId()); - - if(true) { - Status status = mex.getStatus(); - Element invocationResponse = mex.getResponse().getMessage(); - - System.out.println(">>>Invocation status:" + status.name()); - System.out.println(">>>Response:\n" + DOMUtils.domToString(invocationResponse)); - System.out.println(">>>Response:\n" + DOMUtils.domToString(invocationResponse)); - } - //process the method invocation result - response = processResponse(mex.getResponse().getMessage()); - - txMgr.commit(); - // end of transaction two - } catch (Exception e) { - try { - txMgr.rollback(); - } catch (SystemException se) { - - } - throw new InvocationTargetException(e, "Error retrieving BPEL process invocation status : " + e.getMessage()); - } - - - return response; - } - - /** - * Create BPEL Invocation message - * - * BPEL invocation message like : - * - * - * Hello - * - * - * @param args - * @return - */ - private org.apache.ode.bpel.iapi.Message createInvocationMessage(org.apache.ode.bpel.iapi.MyRoleMessageExchange mex, Object[] args) { - Document dom = DOMUtils.newDocument(); - - Element contentMessage = dom.createElement("message"); - Element contentPart = dom.createElement(bpelOperationInputPart.getName()); - Element payload = null; - - //TUSCANY-2321 - Properly handling Document or Element types - if(args[0] instanceof Document) { - payload = (Element) ((Document) args[0]).getFirstChild(); - } else { - payload = (Element) args[0]; - } - - contentPart.appendChild(dom.importNode(payload, true)); - contentMessage.appendChild(contentPart); - dom.appendChild(contentMessage); - - if(true) { - System.out.println("Creating invocation message:"); - System.out.println(">> args.....: " + DOMUtils.domToString(payload)); - System.out.println(">> message..:" + DOMUtils.domToString(dom.getDocumentElement())); - } - - org.apache.ode.bpel.iapi.Message request = mex.createMessage(new QName("", "")); - request.setMessage(dom.getDocumentElement()); - - return request; - } - - /** - * Process BPEL response - * - * - * - * World - * - * - * - * @param response - * @return - */ - private Element processResponse(Element response) { - // return (Element) DOMUtils.findChildByName(response, new QName("",bpelOperationOutputPart.getName())).getFirstChild(); - return (Element) DOMUtils.findChildByName(response, new QName("",bpelOperationOutputPart.getName())); - } -} diff --git a/java/sca/modules/implementation-bpel-ode/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/java/sca/modules/implementation-bpel-ode/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory index b6481b1512..3bce8aa9ab 100644 --- a/java/sca/modules/implementation-bpel-ode/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory +++ b/java/sca/modules/implementation-bpel-ode/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory @@ -16,4 +16,4 @@ # under the License. # Implementation class for the implementation extension -org.apache.tuscany.sca.implementation.bpel.provider.BPELImplementationProviderFactory;model=org.apache.tuscany.sca.implementation.bpel.BPELImplementation +org.apache.tuscany.sca.implementation.bpel.ode.provider.BPELImplementationProviderFactory;model=org.apache.tuscany.sca.implementation.bpel.BPELImplementation diff --git a/java/sca/modules/implementation-bpel-ode/src/test/java/org/apache/tuscany/sca/implementation/bpel/EmbeddedODEServerTestCase.java b/java/sca/modules/implementation-bpel-ode/src/test/java/org/apache/tuscany/sca/implementation/bpel/EmbeddedODEServerTestCase.java deleted file mode 100644 index ac21d47962..0000000000 --- a/java/sca/modules/implementation-bpel-ode/src/test/java/org/apache/tuscany/sca/implementation/bpel/EmbeddedODEServerTestCase.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * 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.tuscany.sca.implementation.bpel; - -import java.io.File; -import java.io.StringReader; -import java.net.URL; -import java.util.concurrent.Future; - -import javax.transaction.TransactionManager; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; - -import junit.framework.TestCase; - -import org.apache.ode.bpel.iapi.Message; -import org.apache.ode.bpel.iapi.MyRoleMessageExchange; -import org.apache.ode.bpel.iapi.MessageExchange.Status; -import org.apache.ode.utils.DOMUtils; -import org.apache.ode.utils.GUID; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; -import org.apache.tuscany.sca.implementation.bpel.ode.GeronimoTxFactory; -import org.apache.tuscany.sca.implementation.bpel.ode.ODEDeployment; -import org.w3c.dom.Element; - -/** - * Test to Deploy and Invoke a HelloWorld BPEL process using EmbeddedODEServer - * - * Major changes introduced to this testcase on 27/05/2008 associated with changes in the - * implementation of EmbeddedODEServer which remove the need for the ODE deploy.xml file - - * instead a Tuscany BPELImplementation object is passed to the EmbeddedODEServer and this is - * introspected to get all the necessary information about the BPEL process - * - * @version $Rev$ $Date$ - */ -public class EmbeddedODEServerTestCase extends TestCase { - - private EmbeddedODEServer odeServer; - - private TransactionManager txMgr; - - @Override - protected void setUp() throws Exception { - // Set up the ODE BPEL server... - GeronimoTxFactory txFactory = new GeronimoTxFactory(); - txMgr = txFactory.getTransactionManager(); - - this.odeServer = new EmbeddedODEServer(txMgr); - odeServer.init(); - - } // end setUp - - @Override - protected void tearDown() throws Exception { - odeServer.stop(); - } - - public void testProcessInvocation() throws Exception { - if (!odeServer.isInitialized()) { - fail("Server did not start !"); - } -// TODO - write effective testcase - made problematic by the need to supply a resolved -// BPELImplementation -/* - URL deployURL = getClass().getClassLoader().getResource("helloworld/deploy.xml"); - File deploymentDir = new File(deployURL.toURI().getPath()).getParentFile(); - System.out.println("Deploying : " + deploymentDir.toString()); - System.out.println(deploymentDir); - - if (odeServer.isInitialized()) { - try { - txMgr.begin(); - odeServer.deploy(new ODEDeployment(deploymentDir), implementation); - txMgr.commit(); - } catch (Exception e) { - e.printStackTrace(); - txMgr.rollback(); - } - - // transaction one - MyRoleMessageExchange mex = null; - Future onhold = null; - try { - // invoke the process - txMgr.begin(); - mex = odeServer.getBpelServer().getEngine().createMessageExchange(new GUID().toString(), - new QName("http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl", "HelloService"), "hello"); - - Message request = mex.createMessage(new QName("", "")); - request.setMessage(DOMUtils.stringToDOM("Hello")); - onhold = mex.invoke(request); - txMgr.commit(); - } catch (Exception e) { - e.printStackTrace(); - txMgr.rollback(); - } - // - end of transaction one - - // Waiting until the reply is ready in case the engine needs to continue in a different thread - if (onhold != null) - onhold.get(); - - // transaction two - try { - txMgr.begin(); - // Reloading the mex in the current transaction, otherwise we can't be sure we have - // the "freshest" one. - mex = (MyRoleMessageExchange) odeServer.getBpelServer().getEngine().getMessageExchange(mex.getMessageExchangeId()); - - Status status = mex.getStatus(); - System.out.println("Status: " + status.name()); - Element response = mex.getResponse().getMessage(); - System.out.println("Response: " + DOMUtils.domToString(response)); - txMgr.commit(); - // end of transaction two - } catch (Exception e) { - e.printStackTrace(); - txMgr.rollback(); - } // end try - } // end if -*/ - } // end testProcessInvocation - -} diff --git a/java/sca/modules/implementation-bpel-ode/src/test/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServerTestCase.java b/java/sca/modules/implementation-bpel-ode/src/test/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServerTestCase.java new file mode 100644 index 0000000000..360df0b2c5 --- /dev/null +++ b/java/sca/modules/implementation-bpel-ode/src/test/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServerTestCase.java @@ -0,0 +1,148 @@ +/* + * 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.tuscany.sca.implementation.bpel.ode; + +import java.io.File; +import java.io.StringReader; +import java.net.URL; +import java.util.concurrent.Future; + +import javax.transaction.TransactionManager; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.ode.bpel.iapi.Message; +import org.apache.ode.bpel.iapi.MyRoleMessageExchange; +import org.apache.ode.bpel.iapi.MessageExchange.Status; +import org.apache.ode.utils.DOMUtils; +import org.apache.ode.utils.GUID; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.implementation.bpel.ode.EmbeddedODEServer; +import org.apache.tuscany.sca.implementation.bpel.ode.GeronimoTxFactory; +import org.apache.tuscany.sca.implementation.bpel.ode.ODEDeployment; +import org.w3c.dom.Element; + +/** + * Test to Deploy and Invoke a HelloWorld BPEL process using EmbeddedODEServer + * + * Major changes introduced to this testcase on 27/05/2008 associated with changes in the + * implementation of EmbeddedODEServer which remove the need for the ODE deploy.xml file - + * instead a Tuscany BPELImplementation object is passed to the EmbeddedODEServer and this is + * introspected to get all the necessary information about the BPEL process + * + * @version $Rev$ $Date$ + */ +public class EmbeddedODEServerTestCase extends TestCase { + + private EmbeddedODEServer odeServer; + + private TransactionManager txMgr; + + @Override + protected void setUp() throws Exception { + // Set up the ODE BPEL server... + GeronimoTxFactory txFactory = new GeronimoTxFactory(); + txMgr = txFactory.getTransactionManager(); + + this.odeServer = new EmbeddedODEServer(txMgr); + odeServer.init(); + + } // end setUp + + @Override + protected void tearDown() throws Exception { + odeServer.stop(); + } + + public void testProcessInvocation() throws Exception { + if (!odeServer.isInitialized()) { + fail("Server did not start !"); + } +// TODO - write effective testcase - made problematic by the need to supply a resolved +// BPELImplementation +/* + URL deployURL = getClass().getClassLoader().getResource("helloworld/deploy.xml"); + File deploymentDir = new File(deployURL.toURI().getPath()).getParentFile(); + System.out.println("Deploying : " + deploymentDir.toString()); + System.out.println(deploymentDir); + + if (odeServer.isInitialized()) { + try { + txMgr.begin(); + odeServer.deploy(new ODEDeployment(deploymentDir), implementation); + txMgr.commit(); + } catch (Exception e) { + e.printStackTrace(); + txMgr.rollback(); + } + + // transaction one + MyRoleMessageExchange mex = null; + Future onhold = null; + try { + // invoke the process + txMgr.begin(); + mex = odeServer.getBpelServer().getEngine().createMessageExchange(new GUID().toString(), + new QName("http://tuscany.apache.org/implementation/bpel/example/helloworld.wsdl", "HelloService"), "hello"); + + Message request = mex.createMessage(new QName("", "")); + request.setMessage(DOMUtils.stringToDOM("Hello")); + onhold = mex.invoke(request); + txMgr.commit(); + } catch (Exception e) { + e.printStackTrace(); + txMgr.rollback(); + } + // - end of transaction one + + // Waiting until the reply is ready in case the engine needs to continue in a different thread + if (onhold != null) + onhold.get(); + + // transaction two + try { + txMgr.begin(); + // Reloading the mex in the current transaction, otherwise we can't be sure we have + // the "freshest" one. + mex = (MyRoleMessageExchange) odeServer.getBpelServer().getEngine().getMessageExchange(mex.getMessageExchangeId()); + + Status status = mex.getStatus(); + System.out.println("Status: " + status.name()); + Element response = mex.getResponse().getMessage(); + System.out.println("Response: " + DOMUtils.domToString(response)); + txMgr.commit(); + // end of transaction two + } catch (Exception e) { + e.printStackTrace(); + txMgr.rollback(); + } // end try + } // end if +*/ + } // end testProcessInvocation + +} diff --git a/java/sca/modules/implementation-bpel-ode/src/test/resources/log4j.properties b/java/sca/modules/implementation-bpel-ode/src/test/resources/log4j.properties index a3aa39127c..82b3c09723 100644 --- a/java/sca/modules/implementation-bpel-ode/src/test/resources/log4j.properties +++ b/java/sca/modules/implementation-bpel-ode/src/test/resources/log4j.properties @@ -28,7 +28,7 @@ log4j.category.org.apache.ode.daohib.bpel.CorrelatorDaoImpl=OFF log4j.category.org.apache.ode.bpel.epr=OFF log4j.category.org.apache.tuscany.sca.implementation.bpel=OFF log4j.category.org.apache.tuscany.sca.implementation.bpel.ode=OFF -log4j.category.org.apache.tuscany.sca.implementation.bpel.provider=OFF +log4j.category.org.apache.tuscany.sca.implementation.bpel.ode.provider=OFF # Console appender log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -- cgit v1.2.3