diff options
Diffstat (limited to 'java')
15 files changed, 670 insertions, 296 deletions
diff --git a/java/sca/itest/corba/pom.xml b/java/sca/itest/corba/pom.xml index b1d45f7c32..c79e84b660 100644 --- a/java/sca/itest/corba/pom.xml +++ b/java/sca/itest/corba/pom.xml @@ -1,73 +1,162 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - * 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. + * 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. --> <project> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-itest</artifactId> - <version>1.4-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - <artifactId>itest-corba-binding</artifactId> - <name>Apache Tuscany SCA CORBA Binding Integration Tests</name> - <dependencies> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-itest</artifactId> + <version>1.4-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>itest-corba-binding</artifactId> + <name>Apache Tuscany SCA CORBA Binding Integration Tests</name> + <dependencies> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-embedded</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>1.4-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-corba-runtime</artifactId> + <version>1.4-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-corba-jdk</artifactId> + <version>1.4-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-sca</artifactId> + <version>1.4-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-sca-corba</artifactId> + <version>1.4-SNAPSHOT</version> + <scope>runtime</scope> + </dependency> + +<!-- + <dependency> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-api</artifactId> + <exclusions> + <exclusion> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + </exclusion> + <exclusion> + <groupId>stax</groupId> + <artifactId>stax-api</artifactId> + </exclusion> + </exclusions> + <version>1.2.5</version> + </dependency> + --> + <dependency> <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-host-embedded</artifactId> - <version>1.4-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-implementation-java-runtime</artifactId> - <version>1.4-SNAPSHOT</version> - <scope>runtime</scope> - </dependency> - <dependency> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-binding-corba-runtime</artifactId> - <version>1.4-SNAPSHOT</version> - <scope>runtime</scope> - </dependency> - <dependency> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-host-corba-jdk</artifactId> + <artifactId>tuscany-databinding-axiom</artifactId> <version>1.4-SNAPSHOT</version> <scope>runtime</scope> </dependency> - <dependency> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-binding-sca</artifactId> - <version>1.4-SNAPSHOT</version> - <scope>runtime</scope> - </dependency> - <dependency> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-binding-sca-corba</artifactId> - <version>1.4-SNAPSHOT</version> - <scope>runtime</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.2</version> - <scope>compile</scope> - </dependency> - </dependencies> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-databinding-sdo</artifactId> + <version>1.4-SNAPSHOT</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.2</version> + <scope>compile</scope> + </dependency> + + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <version>1.0</version> + <executions> + <execution> + <id>add-source</id> + <phase>generate-sources</phase> + <goals> + <goal>add-test-source</goal> + </goals> + <configuration> + <sources> + <source>target/sdo-source</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.tuscany.sdo</groupId> + <artifactId>tuscany-sdo-plugin</artifactId> + <version>1.1-incubating</version> + <executions> + <execution> + <id>generate-scenariofour-sdo</id> + <phase>generate-sources</phase> + <configuration> + <schemaFile> + ${basedir}/src/test/resources/scenariofour.xsd + </schemaFile> + <javaPackage> + org.apache.tuscany.sca.test.corba.scenariofour + </javaPackage> + <prefix>ScenarioFour</prefix> + <noNotification>true</noNotification> + <noContainer>true</noContainer> + <noUnsettable>true</noUnsettable> + </configuration> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> diff --git a/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/ScenarioFourTestCase.java b/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/ScenarioFourTestCase.java index f47792c5f2..7ab5ca1e14 100644 --- a/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/ScenarioFourTestCase.java +++ b/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/ScenarioFourTestCase.java @@ -26,13 +26,17 @@ import junit.framework.Assert; import org.apache.tuscany.sca.host.corba.naming.TransientNameServer; import org.apache.tuscany.sca.host.corba.naming.TransientNameService; import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.test.corba.scenariofour.ScenarioFourFactory; +import org.apache.tuscany.sca.test.corba.scenariofour.ScenarioFourSdo; import org.apache.tuscany.sca.test.corba.types.ScenarioFour; import org.apache.tuscany.sca.test.corba.types.ScenarioFourComponent; +import org.apache.tuscany.sca.test.corba.types.ScenarioFourException; import org.apache.tuscany.sca.test.corba.types.ScenarioFourStruct; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; + /** * Tests SCA default binding over CORBA binding */ @@ -42,6 +46,8 @@ public class ScenarioFourTestCase { private static int ORB_INITIAL_PORT = 5060; private static SCADomain domain; private static TransientNameServer server; + private static ScenarioFourComponent scenarioFourComponent; + private static ScenarioFour scenarioFour; /** * Sets up name service, creates and registers traditional CORBA service, @@ -63,6 +69,8 @@ public class ScenarioFourTestCase { } // obtain domain domain = SCADomain.newInstance("ScenarioFour.composite"); + scenarioFourComponent = domain.getService(ScenarioFourComponent.class, "ScenarioFour"); + scenarioFour = scenarioFourComponent.getScenarioFour(); } catch (Exception e) { e.printStackTrace(); } @@ -76,16 +84,17 @@ public class ScenarioFourTestCase { server.stop(); } + /** + * General tests for passing JAXB objects + */ @Test - public void test_generalTest() { + public void test_generalJAXB() { try { - ScenarioFourComponent soc = domain.getService(ScenarioFourComponent.class, "ScenarioFour"); - ScenarioFour so = soc.getScenarioFour(); ScenarioFourStruct input = new ScenarioFourStruct(); input.field1 = "Test"; input.field2 = 1; input.field3 = new double[1]; - ScenarioFourStruct output = so.setStruct(input); + ScenarioFourStruct output = scenarioFour.setStruct(input); assertTrue(input.equals(output)); } catch (Exception e) { e.printStackTrace(); @@ -93,4 +102,36 @@ public class ScenarioFourTestCase { } } + /** + * Test for JAXB exceptions + */ + @Test + public void test_exceptionsJAXB() { + try { + scenarioFour.exceptionTest(); + fail(); + } catch (ScenarioFourException e) { + assertTrue(ScenarioFourException.DEFAULT_CONTENT.equals(e.getContent())); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + /** + * General test for passing SDO objects + */ + @Test + public void test_generalSDO() { + try { + ScenarioFourSdo scenarioFourSdo = ScenarioFourFactory.INSTANCE.createScenarioFourSdo(); + scenarioFourSdo.setMessage("Test1"); + scenarioFourSdo.setSymbol("Test2"); + ScenarioFourSdo result = scenarioFour.passScenarioFourStruct(scenarioFourSdo); + assertTrue(scenarioFourSdo.getMessage().equals(result.getMessage()) && scenarioFourSdo.getSymbol().equals(result.getSymbol())); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } } diff --git a/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/types/ScenarioFour.java b/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/types/ScenarioFour.java index d1492f85e5..936021719e 100644 --- a/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/types/ScenarioFour.java +++ b/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/types/ScenarioFour.java @@ -19,6 +19,7 @@ package org.apache.tuscany.sca.test.corba.types; +import org.apache.tuscany.sca.test.corba.scenariofour.ScenarioFourSdo; import org.osoa.sca.annotations.Remotable; /** @@ -29,4 +30,8 @@ public interface ScenarioFour { ScenarioFourStruct setStruct(ScenarioFourStruct struct); + void exceptionTest() throws ScenarioFourException; + + ScenarioFourSdo passScenarioFourStruct(ScenarioFourSdo scenarioFourSdo); + } diff --git a/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/types/ScenarioFourException.java b/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/types/ScenarioFourException.java new file mode 100644 index 0000000000..1afda33e35 --- /dev/null +++ b/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/types/ScenarioFourException.java @@ -0,0 +1,37 @@ +/* + * 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.test.corba.types; + +public class ScenarioFourException extends Exception { + + public static final String DEFAULT_CONTENT = "Test"; + + private static final long serialVersionUID = 1L; + private String content; + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + +} diff --git a/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/types/ScenarioFourImpl.java b/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/types/ScenarioFourImpl.java index c047fafca4..35c3109ef4 100644 --- a/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/types/ScenarioFourImpl.java +++ b/java/sca/itest/corba/src/test/java/org/apache/tuscany/sca/test/corba/types/ScenarioFourImpl.java @@ -19,6 +19,8 @@ package org.apache.tuscany.sca.test.corba.types; +import org.apache.tuscany.sca.test.corba.scenariofour.ScenarioFourSdo; + /** * Implementation of ScenarioFour service */ @@ -28,4 +30,14 @@ public class ScenarioFourImpl implements ScenarioFour { return struct; } + public void exceptionTest() throws ScenarioFourException { + ScenarioFourException exception = new ScenarioFourException(); + exception.setContent(ScenarioFourException.DEFAULT_CONTENT); + throw exception; + } + + public ScenarioFourSdo passScenarioFourStruct(ScenarioFourSdo scenarioFourSdo) { + return scenarioFourSdo; + } + } diff --git a/java/sca/itest/corba/src/test/resources/scenariofour.xsd b/java/sca/itest/corba/src/test/resources/scenariofour.xsd new file mode 100644 index 0000000000..2669b54be3 --- /dev/null +++ b/java/sca/itest/corba/src/test/resources/scenariofour.xsd @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<schema targetNamespace="http://example.com/scenariofour" xmlns="http://www.w3.org/2001/XMLSchema"> + + <element name="ScenarioFourSdo"> + <complexType> + <sequence> + <element name="message" minOccurs="1" type="string" /> + <element name="symbol" minOccurs="1" type="string" /> + </sequence> + </complexType> + </element> + +</schema> diff --git a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java index a7cc210470..fe4fabc293 100644 --- a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java +++ b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/CorbaServiceBindingProvider.java @@ -20,9 +20,13 @@ package org.apache.tuscany.sca.binding.corba.impl; import org.apache.tuscany.sca.binding.corba.CorbaBinding; +import org.apache.tuscany.sca.binding.corba.impl.service.ComponentInvocationProxy; import org.apache.tuscany.sca.binding.corba.impl.service.DynaCorbaServant; +import org.apache.tuscany.sca.binding.corba.impl.service.InvocationProxy; +import org.apache.tuscany.sca.binding.corba.impl.types.util.Utils; import org.apache.tuscany.sca.host.corba.CorbaHost; import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.provider.ServiceBindingProvider; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.osoa.sca.ServiceRuntimeException; @@ -55,7 +59,9 @@ public class CorbaServiceBindingProvider implements ServiceBindingProvider { */ public void start() { try { - servant = new DynaCorbaServant(service, binding); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(binding), javaClass); + servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); servant.setIds(new String[] {binding.getId()}); host.registerServant(binding.getCorbaname(), servant); } catch (Exception e) { diff --git a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java index 0d9d33b198..26f006242e 100644 --- a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java +++ b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java @@ -19,24 +19,14 @@ package org.apache.tuscany.sca.binding.corba.impl.service; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; import org.apache.tuscany.sca.binding.corba.impl.types.TypeTree; import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeCreator; import org.apache.tuscany.sca.binding.corba.impl.types.util.TypeHelpersProxy; import org.apache.tuscany.sca.binding.corba.impl.types.util.Utils; -import org.apache.tuscany.sca.binding.corba.impl.util.OperationMapper; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.java.JavaInterface; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.omg.CORBA.MARSHAL; import org.omg.CORBA.portable.InputStream; import org.omg.CORBA.portable.InvokeHandler; @@ -49,114 +39,23 @@ import org.omg.CORBA.portable.ResponseHandler; */ public class DynaCorbaServant extends ObjectImpl implements InvokeHandler { - private RuntimeComponentService service; - private Binding binding; private String[] ids; - private Map<Operation, OperationTypes> operationsCache = new HashMap<Operation, OperationTypes>(); - private Class<?> javaClass; - private Map<String, Method> operationsMap; - private Map<Method, Operation> methodOperationMapping; - private boolean scaBindingRules; - - /** - * Creates servant with CORBA binding mapping rules in default - * - * @param service backed service - * @param binding binding object - * @throws RequestConfigurationException - */ - public DynaCorbaServant(RuntimeComponentService service, Binding binding) throws RequestConfigurationException { - // use CORBA binding rules by default - this(service, binding, false); - } + private InvocationProxy invocationProxy; + private String typeId; /** * Creates servant object - * - * @param service backed service - * @param binding binding object - * @param scaBindingRules apply SCA default binding mapping rules + * @param invocationProxy + * @param typeId * @throws RequestConfigurationException */ - public DynaCorbaServant(RuntimeComponentService service, Binding binding, boolean scaBindingRules) throws RequestConfigurationException { - this.scaBindingRules = scaBindingRules; - this.service = service; - this.binding = binding; - this.javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); - this.operationsMap = OperationMapper.mapOperationToMethod(javaClass); - cacheOperationTypes(service.getInterfaceContract().getInterface().getOperations()); - createMethod2OperationMapping(); + public DynaCorbaServant(InvocationProxy invocationProxy, String typeId) throws RequestConfigurationException { + this.invocationProxy = invocationProxy; + this.typeId = typeId; setDefaultIds(); } /** - * Maps Java methods to Tuscany operations - */ - private void createMethod2OperationMapping() { - // for every operation find all methods with the same name, then - // compare operations and methods parameters - this.methodOperationMapping = new HashMap<Method, Operation>(); - for (Operation operation : service.getInterfaceContract().getInterface().getOperations()) { - List<DataType> inputTypes = operation.getInputType().getLogical(); - Method[] methods = javaClass.getMethods(); - for (int i = 0; i < methods.length; i++) { - if (methods[i].getName().equals(operation.getName()) && inputTypes.size() == methods[i] - .getParameterTypes().length) { - Class<?>[] parameterTypes = methods[i].getParameterTypes(); - int j = 0; - boolean parameterMatch = true; - for (DataType dataType : inputTypes) { - if (!dataType.getPhysical().equals(parameterTypes[j])) { - parameterMatch = false; - break; - } - j++; - } - if (parameterMatch) { - // match found - methodOperationMapping.put(methods[i], operation); - break; - } - } - } - - } - } - - /** - * Caches TypeTree for every operation in backed component - * @param operations - * @throws RequestConfigurationException - */ - private void cacheOperationTypes(List<Operation> operations) throws RequestConfigurationException { - for (Operation operation : operations) { - try { - OperationTypes operationTypes = new OperationTypes(); - List<TypeTree> inputInstances = new ArrayList<TypeTree>(); - // cache output type tree - if (operation.getOutputType() != null && operation.getOutputType().getPhysical() != null - && !operation.getOutputType().getPhysical().equals(void.class)) { - TypeTree outputType = TypeTreeCreator.createTypeTree(operation.getOutputType().getPhysical(), scaBindingRules); - operationTypes.setOutputType(outputType); - } - // cache input types trees - if (operation.getInputType() != null) { - for (DataType<List<DataType>> type : operation.getInputType().getLogical()) { - Class<?> forClass = type.getPhysical(); - TypeTree inputType = TypeTreeCreator.createTypeTree(forClass, scaBindingRules); - inputInstances.add(inputType); - } - - } - operationTypes.setInputType(inputInstances); - operationsCache.put(operation, operationTypes); - } catch (RequestConfigurationException e) { - throw e; - } - } - } - - /** * Sets CORBA object ID * @param ids */ @@ -172,16 +71,12 @@ public class DynaCorbaServant extends ObjectImpl implements InvokeHandler { } public OutputStream _invoke(String operationName, InputStream in, ResponseHandler rh) { - Operation operation = null; - Method method = operationsMap.get(operationName); - // searching for proper operation - operation = methodOperationMapping.get(method); - if (operation == null) { + OperationTypes types = invocationProxy.getOperationTypes(operationName); + if (types == null) { // operation wasn't found throw new org.omg.CORBA.BAD_OPERATION(0, org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE); } else { List<Object> inputInstances = new ArrayList<Object>(); - OperationTypes types = operationsCache.get(operation); try { // retrieving in arguments for (TypeTree tree : types.getInputType()) { @@ -195,19 +90,19 @@ public class DynaCorbaServant extends ObjectImpl implements InvokeHandler { } try { // invocation and sending result - Object result = service.getRuntimeWire(binding).invoke(operation, inputInstances.toArray()); + Object result = invocationProxy.invoke(operationName, inputInstances); OutputStream out = rh.createReply(); if (types.getOutputType() != null) { TypeTree tree = types.getOutputType(); TypeHelpersProxy.write(tree.getRootNode(), out, result); } return out; - } catch (InvocationTargetException ie) { + } catch (InvocationException ie) { // handling user exception try { OutputStream out = rh.createExceptionReply(); Class<?> exceptionClass = ie.getTargetException().getClass(); - TypeTree tree = TypeTreeCreator.createTypeTree(exceptionClass, scaBindingRules); + TypeTree tree = TypeTreeCreator.createTypeTree(exceptionClass, false); String exceptionId = Utils.getTypeId(exceptionClass); out.write_string(exceptionId); TypeHelpersProxy.write(tree.getRootNode(), out, ie.getTargetException()); @@ -234,8 +129,7 @@ public class DynaCorbaServant extends ObjectImpl implements InvokeHandler { * Sets servant ID to default, based on Java class name */ private void setDefaultIds() { - String id = Utils.getTypeId(javaClass); - this.ids = new String[] {id}; + this.ids = new String[] {typeId}; } } diff --git a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationProxy.java b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationProxy.java new file mode 100644 index 0000000000..f732e142b2 --- /dev/null +++ b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/InvocationProxy.java @@ -0,0 +1,45 @@ +/* + * 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.binding.corba.impl.service; + +import java.util.List; + +/** + * Target proxy interface for service bindings + */ +public interface InvocationProxy { + + /** + * Gets operations types for target + * @param operationName + * @return + */ + public OperationTypes getOperationTypes(String operationName); + + /** + * Invokes target operation + * @param operationName + * @param arguments + * @return + * @throws InvocationException + */ + public Object invoke(String operationName, List<Object> arguments) throws InvocationException; + +} diff --git a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java index 74642f1984..1ccf22140b 100644 --- a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java +++ b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java @@ -30,7 +30,10 @@ import org.apache.tuscany.sca.binding.corba.impl.exceptions.CorbaException; import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaRequest; import org.apache.tuscany.sca.binding.corba.impl.reference.DynaCorbaResponse; +import org.apache.tuscany.sca.binding.corba.impl.service.ComponentInvocationProxy; import org.apache.tuscany.sca.binding.corba.impl.service.DynaCorbaServant; +import org.apache.tuscany.sca.binding.corba.impl.service.InvocationProxy; +import org.apache.tuscany.sca.binding.corba.impl.types.util.Utils; import org.apache.tuscany.sca.binding.corba.testing.enums.Color; import org.apache.tuscany.sca.binding.corba.testing.enums.EnumManager; import org.apache.tuscany.sca.binding.corba.testing.enums.EnumManagerHelper; @@ -58,6 +61,7 @@ import org.apache.tuscany.sca.binding.corba.testing.servants.TestObjectServant; import org.apache.tuscany.sca.binding.corba.testing.service.mocks.TestRuntimeComponentService; import org.apache.tuscany.sca.host.corba.naming.TransientNameServer; import org.apache.tuscany.sca.host.corba.naming.TransientNameService; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -138,7 +142,9 @@ public class CorbaServantTestCase { try { PrimitivesSetter primitivesSetter = new PrimitivesSetterServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(primitivesSetter); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/PrimitivesSetter:1.0"}; servant.setIds(ids); @@ -187,7 +193,9 @@ public class CorbaServantTestCase { try { ArraysSetter arraysSetter = new ArraysSetterServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(arraysSetter); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/ArraysSetter:1.0"}; servant.setIds(ids); java.lang.Object result = null; @@ -244,7 +252,9 @@ public class CorbaServantTestCase { try { TestObject to = new TestObjectServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(to); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; servant.setIds(ids); bindServant(servant, "TestObject"); @@ -279,7 +289,9 @@ public class CorbaServantTestCase { try { TestObjectServant tos = new TestObjectServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(tos); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; servant.setIds(ids); bindServant(servant, "TestObject"); @@ -298,7 +310,9 @@ public class CorbaServantTestCase { try { InvalidTestObjectServant tos = new InvalidTestObjectServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(tos); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; servant.setIds(ids); bindServant(servant, "InvalidTestObject"); @@ -328,7 +342,9 @@ public class CorbaServantTestCase { try { CalcServant calc = new CalcServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(calc); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc:1.0"}; servant.setIds(ids); bindServant(servant, "Calc"); @@ -347,7 +363,9 @@ public class CorbaServantTestCase { try { CalcServant calc = new CalcServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(calc); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/exceptions/Calc:1.0"}; servant.setIds(ids); bindServant(servant, "Calc"); @@ -372,7 +390,9 @@ public class CorbaServantTestCase { try { EnumManagerServant ems = new EnumManagerServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(ems); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = {"IDL:org/apache/tuscany/sca/binding/corba/testing/enums/EnumManager:1.0"}; servant.setIds(ids); bindServant(servant, "Enum"); @@ -390,7 +410,9 @@ public class CorbaServantTestCase { try { NonCorbaServant ncs = new NonCorbaServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(ncs); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); bindServant(servant, "NonCorbaServant"); // it's non corba servant so we don't have stubs to test them DynaCorbaRequest request = new DynaCorbaRequest(bindReference("NonCorbaServant"), "setString"); @@ -406,7 +428,9 @@ public class CorbaServantTestCase { try { NonCorbaServant ncs = new NonCorbaServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(ncs); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); bindServant(servant, "NonCorbaServant"); // it's non corba servant so we don't have stubs to test them DynaCorbaRequest request = new DynaCorbaRequest(bindReference("NonCorbaServant"), "throwException"); @@ -431,7 +455,9 @@ public class CorbaServantTestCase { try { CalcServant calc = new CalcServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(calc); - DynaCorbaServant servant = new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); String[] ids = new String[] {"IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0"}; servant.setIds(ids); bindServant(servant, "Calc"); @@ -459,7 +485,9 @@ public class CorbaServantTestCase { InvalidTypesServant its = new InvalidTypesServant(); TestRuntimeComponentService service = new TestRuntimeComponentService(its); //expecting exception... - new DynaCorbaServant(service, null); + Class<?> javaClass = ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass(); + InvocationProxy proxy = new ComponentInvocationProxy(service, service.getRuntimeWire(null), javaClass); + DynaCorbaServant servant = new DynaCorbaServant(proxy, Utils.getTypeId(javaClass)); fail(); } catch (Exception e) { if (e instanceof RequestConfigurationException) { diff --git a/java/sca/modules/binding-sca-corba/pom.xml b/java/sca/modules/binding-sca-corba/pom.xml index 9ff1ae1003..37e7914254 100644 --- a/java/sca/modules/binding-sca-corba/pom.xml +++ b/java/sca/modules/binding-sca-corba/pom.xml @@ -1,87 +1,132 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- - * 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. + * 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. --> <project> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-modules</artifactId> - <version>1.4-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-modules</artifactId> + <version>1.4-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> - <artifactId>tuscany-binding-sca-corba</artifactId> - <name>Apache Tuscany SCA CORBA-based Default Binding Extension</name> + <artifactId>tuscany-binding-sca-corba</artifactId> + <name> + Apache Tuscany SCA CORBA-based Default Binding Extension + </name> - <dependencies> + <dependencies> - <dependency> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-binding-sca</artifactId> - <version>1.4-SNAPSHOT</version> - </dependency> + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-sca</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-corba</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-corba-runtime</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-corba</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-corba-jdk</artifactId> + <version>1.4-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-interface-wsdl</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> - <dependency> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-binding-corba</artifactId> - <version>1.4-SNAPSHOT</version> - </dependency> - <dependency> <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-binding-corba-runtime</artifactId> + <artifactId>tuscany-databinding-axiom</artifactId> <version>1.4-SNAPSHOT</version> </dependency> - <dependency> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-host-corba</artifactId> - <version>1.4-SNAPSHOT</version> - </dependency> - - <dependency> - <groupId>org.apache.tuscany.sca</groupId> - <artifactId>tuscany-host-corba-jdk</artifactId> - <version>1.4-SNAPSHOT</version> - <scope>test</scope> - </dependency> - - </dependencies> - - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - - <configuration> - <instructions> - <Bundle-Version>${tuscany.version}</Bundle-Version> - <Bundle-SymbolicName>org.apache.tuscany.sca.binding.sca.corba</Bundle-SymbolicName> - <Bundle-Description>${pom.name}</Bundle-Description> - <Export-Package>org.apache.tuscany.sca.binding.sca.corba*</Export-Package> - </instructions> - </configuration> - </plugin> - </plugins> - </build> + <!-- + <dependency> + <groupId>org.apache.ws.commons.axiom</groupId> + <artifactId>axiom-api</artifactId> + <exclusions> + <exclusion> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + </exclusion> + <exclusion> + <groupId>stax</groupId> + <artifactId>stax-api</artifactId> + </exclusion> + </exclusions> + <version>1.2.5</version> + </dependency> + --> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-ws-wsdlgen</artifactId> + <version>1.4-SNAPSHOT</version> + </dependency> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + + <configuration> + <instructions> + <Bundle-Version> + ${tuscany.version} + </Bundle-Version> + <Bundle-SymbolicName> + org.apache.tuscany.sca.binding.sca.corba + </Bundle-SymbolicName> + <Bundle-Description> + ${pom.name} + </Bundle-Description> + <Export-Package> + org.apache.tuscany.sca.binding.sca.corba* + </Export-Package> + </instructions> + </configuration> + </plugin> + </plugins> + </build> </project> diff --git a/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCABindingProviderFactory.java b/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCABindingProviderFactory.java index a8a9a3d5eb..2eee714de6 100644 --- a/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCABindingProviderFactory.java +++ b/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCABindingProviderFactory.java @@ -38,22 +38,24 @@ public class CorbaSCABindingProviderFactory implements BindingProviderFactory<Di private CorbaHostExtensionPoint chep; private CorbaHost host; + private ExtensionPointRegistry extensions; - public CorbaSCABindingProviderFactory(ExtensionPointRegistry registry) { - chep = registry.getExtensionPoint(CorbaHostExtensionPoint.class); + public CorbaSCABindingProviderFactory(ExtensionPointRegistry extensions) { + this.extensions = extensions; + chep = extensions.getExtensionPoint(CorbaHostExtensionPoint.class); host = new ExtensibleCorbaHost(chep); } public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, DistributedSCABinding binding) { - return new CorbaSCAReferenceBindingProvider(binding.getSCABinding(), host, reference); + return new CorbaSCAReferenceBindingProvider(binding.getSCABinding(), host, component, reference, extensions); } public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, DistributedSCABinding binding) { - return new CorbaSCAServiceBindingProvider(binding.getSCABinding(), host, service); + return new CorbaSCAServiceBindingProvider(binding.getSCABinding(), host, component, service, extensions); } public Class<DistributedSCABinding> getModelType() { diff --git a/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAInvocationProxy.java b/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAInvocationProxy.java new file mode 100644 index 0000000000..f20b027644 --- /dev/null +++ b/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAInvocationProxy.java @@ -0,0 +1,113 @@ +/* + * 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.binding.sca.corba.impl; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.stream.XMLStreamException; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.llom.util.AXIOMUtil; +import org.apache.tuscany.sca.binding.corba.impl.exceptions.RequestConfigurationException; +import org.apache.tuscany.sca.binding.corba.impl.service.InvocationException; +import org.apache.tuscany.sca.binding.corba.impl.service.InvocationProxy; +import org.apache.tuscany.sca.binding.corba.impl.service.OperationTypes; +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTree; +import org.apache.tuscany.sca.binding.corba.impl.types.TypeTreeCreator; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Invocation proxy for SCA default binding over CORBA binding + */ +public class CorbaSCAInvocationProxy implements InvocationProxy { + + private RuntimeWire wire; + private Interface componentInterface; + private OperationTypes types = new OperationTypes(); + private MessageFactory messageFactory; + + public CorbaSCAInvocationProxy(RuntimeWire wire, Interface componentInterface, MessageFactory messageFactory) { + this.wire = wire; + this.componentInterface = componentInterface; + this.messageFactory = messageFactory; + try { + List<TypeTree> inputType = new ArrayList<TypeTree>(); + inputType.add(TypeTreeCreator.createTypeTree(String.class, false)); + types.setInputType(inputType); + types.setOutputType(TypeTreeCreator.createTypeTree(String.class, false)); + } catch (RequestConfigurationException e) { + // ignore - string type should not cause this exception + } + } + + public Object invoke(String operationName, List<Object> arguments) throws InvocationException { + try { + OMElement omContent = AXIOMUtil.stringToOM((String)arguments.get(0)); + String componentOperationName = omContent.getQName().getLocalPart(); + Operation componentOperation = null; + for (Operation operation : componentInterface.getOperations()) { + if (operation.getName().equals(componentOperationName)) { + componentOperation = operation; + break; + } + } + if (componentOperation == null) { + // TODO: throw an exception - no such operation + } else { + Message msg = messageFactory.createMessage(); + msg.setOperation(componentOperation); + Object[] args = new Object[1]; + args[0] = omContent; + msg.setBody(args); + OMElement omResult = (OMElement)wire.invoke(componentOperation, msg); + return omResult.toStringWithConsume(); + } + } catch (XMLStreamException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvocationTargetException e) { + OMElement omException = (OMElement)((FaultException)e.getCause()).getFaultInfo(); + try { + WrappedSCAException wrappedException = new WrappedSCAException(omException.toStringWithConsume()); + InvocationException exception = new InvocationException(wrappedException); + throw exception; + } catch (XMLStreamException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + } + + return null; + } + + public OperationTypes getOperationTypes(String operationName) { + // ignoring operationName - only one operation for this proxy is allowed + return types; + } + +} diff --git a/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAReferenceBindingProvider.java b/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAReferenceBindingProvider.java index f20a0b1a02..c578f8bdf4 100644 --- a/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAReferenceBindingProvider.java +++ b/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAReferenceBindingProvider.java @@ -19,19 +19,20 @@ package org.apache.tuscany.sca.binding.sca.corba.impl; -import java.lang.reflect.Method; -import java.util.Map; import java.util.logging.Logger; +import org.apache.axiom.om.OMElement; import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.binding.corba.impl.CorbaInvoker; -import org.apache.tuscany.sca.binding.corba.impl.util.OperationMapper; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.host.corba.CorbaHost; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.invocation.Invoker; import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentReference; import org.omg.CORBA.Object; @@ -44,23 +45,27 @@ public class CorbaSCAReferenceBindingProvider implements ReferenceBindingProvide private SCABinding binding; private CorbaHost host; - private RuntimeComponentReference reference; private Object remoteObject; private Class<?> referenceClass; - private Map<Method, String> operationsMap = null; + private InterfaceContract wsdlInterfaceContract; public CorbaSCAReferenceBindingProvider(SCABinding binding, CorbaHost host, - RuntimeComponentReference reference) { + RuntimeComponent component, + RuntimeComponentReference reference, + ExtensionPointRegistry extensions) { this.binding = binding; this.host = host; - this.reference = reference; - this.referenceClass = ((JavaInterface)reference.getInterfaceContract().getInterface()).getJavaClass(); - operationsMap = OperationMapper.mapMethodToOperation(referenceClass); + + WebServiceBindingFactory wsFactory = extensions.getExtensionPoint(WebServiceBindingFactory.class); + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + BindingWSDLGenerator.generateWSDL(component, reference, wsBinding, extensions, null); + wsdlInterfaceContract = wsBinding.getBindingInterfaceContract(); + wsdlInterfaceContract.getInterface().resetDataBinding(OMElement.class.getName()); } public InterfaceContract getBindingInterfaceContract() { - return reference.getInterfaceContract(); + return wsdlInterfaceContract; } public boolean supportsOneWayInvocation() { @@ -72,7 +77,7 @@ public class CorbaSCAReferenceBindingProvider implements ReferenceBindingProvide if (remoteObject == null) { remoteObject = host.lookup(binding.getURI()); } - return new CorbaInvoker(remoteObject, referenceClass, operationsMap, true); + return new CorbaSCAInvoker(remoteObject, referenceClass, null, true); } catch (Exception e) { logger.warning(e.getMessage()); } diff --git a/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAServiceBindingProvider.java b/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAServiceBindingProvider.java index 88e785bd42..1dabefc9f7 100644 --- a/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAServiceBindingProvider.java +++ b/java/sca/modules/binding-sca-corba/src/main/java/org/apache/tuscany/sca/binding/sca/corba/impl/CorbaSCAServiceBindingProvider.java @@ -19,35 +19,55 @@ package org.apache.tuscany.sca.binding.sca.corba.impl; +import org.apache.axiom.om.OMElement; import org.apache.tuscany.sca.assembly.SCABinding; import org.apache.tuscany.sca.binding.corba.impl.service.DynaCorbaServant; +import org.apache.tuscany.sca.binding.corba.impl.service.InvocationProxy; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.wsdlgen.BindingWSDLGenerator; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.host.corba.CorbaHost; import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.osoa.sca.ServiceRuntimeException; + /** * Service binding provider for SCA default binding over CORBA binding */ public class CorbaSCAServiceBindingProvider implements ServiceBindingProvider { - + private SCABinding binding; private CorbaHost host; private RuntimeComponentService service; private DynaCorbaServant servant; - + private MessageFactory messageFactory; + private InterfaceContract wsdlInterfaceContract; public CorbaSCAServiceBindingProvider(SCABinding binding, CorbaHost host, - RuntimeComponentService service) { + RuntimeComponent component, + RuntimeComponentService service, + ExtensionPointRegistry extensions) { this.binding = binding; this.host = host; this.service = service; + + messageFactory = extensions.getExtensionPoint(MessageFactory.class); + + WebServiceBindingFactory wsFactory = extensions.getExtensionPoint(WebServiceBindingFactory.class); + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + BindingWSDLGenerator.generateWSDL(component, service, wsBinding, extensions, null); + wsdlInterfaceContract = wsBinding.getBindingInterfaceContract(); + wsdlInterfaceContract.getInterface().resetDataBinding(OMElement.class.getName()); } public InterfaceContract getBindingInterfaceContract() { - return service.getInterfaceContract(); + return wsdlInterfaceContract; } public boolean supportsOneWayInvocation() { @@ -56,19 +76,20 @@ public class CorbaSCAServiceBindingProvider implements ServiceBindingProvider { public void start() { try { - servant = new DynaCorbaServant(service, binding, true); + InvocationProxy proxy = new CorbaSCAInvocationProxy(service.getRuntimeWire(binding), service.getInterfaceContract().getInterface(), messageFactory); + servant = new DynaCorbaServant(proxy, "IDL:org/apache/tuscany/sca/binding/sca/corba/Service:1.0"); host.registerServant(binding.getURI(), servant); } catch (Exception e) { throw new ServiceRuntimeException(e); - } + } } public void stop() { try { host.unregisterServant(binding.getURI()); - } catch (Exception e) { - throw new ServiceRuntimeException(e); - } + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } } |