You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2008/06/25 00:17:17 UTC

svn commit: r671367 - in /tuscany/java/sca/modules/binding-corba-runtime/src: main/java/org/apache/tuscany/sca/binding/corba/impl/reference/ main/java/org/apache/tuscany/sca/binding/corba/impl/service/ main/java/org/apache/tuscany/sca/binding/corba/imp...

Author: rfeng
Date: Tue Jun 24 15:17:17 2008
New Revision: 671367

URL: http://svn.apache.org/viewvc?rev=671367&view=rev
Log:
Apply the patch from Wojtek for TUSCANY-2357 (typescache-tests-jira-2357-24-june-2008.patch). Thanks.

Added:
    tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java   (with props)
    tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java   (with props)
Modified:
    tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java
    tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java
    tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java
    tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java
    tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java
    tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java

Modified: tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java?rev=671367&r1=671366&r2=671367&view=diff
==============================================================================
--- tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java (original)
+++ tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java Tue Jun 24 15:17:17 2008
@@ -29,6 +29,7 @@
 import org.apache.tuscany.sca.binding.corba.impl.types.util.TypeHelpersProxy;
 import org.apache.tuscany.sca.binding.corba.impl.types.util.Utils;
 import org.omg.CORBA.BAD_OPERATION;
+import org.omg.CORBA.BAD_PARAM;
 import org.omg.CORBA.Object;
 import org.omg.CORBA.SystemException;
 import org.omg.CORBA.portable.ApplicationException;
@@ -137,6 +138,8 @@
 	private void handleSystemException(SystemException se) throws Exception {
 		if (se instanceof BAD_OPERATION) {
 			throw new CorbaException("Bad operation name: " + operation, se);
+		} else if (se instanceof BAD_PARAM) {
+			throw new CorbaException("Bad parameter", se);
 		} else {
 			// TODO: handle more system exception types
 			throw new CorbaException(se.getMessage(), se);

Modified: tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java?rev=671367&r1=671366&r2=671367&view=diff
==============================================================================
--- tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java (original)
+++ tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java Tue Jun 24 15:17:17 2008
@@ -21,7 +21,9 @@
 
 import java.lang.reflect.InvocationTargetException;
 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;
@@ -32,6 +34,7 @@
 import org.apache.tuscany.sca.interfacedef.DataType;
 import org.apache.tuscany.sca.interfacedef.Operation;
 import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.omg.CORBA.MARSHAL;
 import org.omg.CORBA.portable.InputStream;
 import org.omg.CORBA.portable.InvokeHandler;
 import org.omg.CORBA.portable.ObjectImpl;
@@ -47,10 +50,50 @@
 	private RuntimeComponentService service;
 	private Binding binding;
 	private String[] ids = DEFAULT_IDS;
+	private Map<String, OperationTypes> operationsCache = new HashMap<String, OperationTypes>();
 
-	public DynaCorbaServant(RuntimeComponentService service, Binding binding) {
+	public DynaCorbaServant(RuntimeComponentService service, Binding binding)
+			throws RequestConfigurationException {
 		this.service = service;
 		this.binding = binding;
+		cacheOperationTypes(service.getInterfaceContract().getInterface()
+				.getOperations());
+
+	}
+
+	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());
+					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);
+						inputInstances.add(inputType);
+					}
+
+				}
+				operationTypes.setInputType(inputInstances);
+				operationsCache.put(operation.getName(), operationTypes);
+			} catch (RequestConfigurationException e) {
+				throw e;
+			}
+		}
 	}
 
 	public void setIds(String[] ids) {
@@ -64,8 +107,6 @@
 	public OutputStream _invoke(String method, InputStream in,
 			ResponseHandler rh) {
 
-		DataType outputType = null;
-		DataType<List<DataType>> inputType = null;
 		Operation operation = null;
 
 		List<Operation> operations = service.getInterfaceContract()
@@ -73,8 +114,6 @@
 		// searching for proper operation
 		for (Operation oper : operations) {
 			if (oper.getName().equals(method)) {
-				outputType = oper.getOutputType();
-				inputType = oper.getInputType();
 				operation = oper;
 				break;
 			}
@@ -85,27 +124,26 @@
 					org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
 		} else {
 			List<Object> inputInstances = new ArrayList<Object>();
+			OperationTypes types = operationsCache.get(operation.getName());
 			try {
 				// retrieving in arguments
-				for (DataType type : inputType.getLogical()) {
-					Class<?> forClass = type.getPhysical();
-					TypeTree tree = TypeTreeCreator.createTypeTree(forClass);
+				for (TypeTree tree : types.getInputType()) {
 					Object o = TypeHelpersProxy.read(tree.getRootNode(), in);
 					inputInstances.add(o);
-
 				}
-			} catch (RequestConfigurationException e) {
-				// TODO: raise remote exception, BAD_PARAM exception maybe?
-				e.printStackTrace();
+			} catch (MARSHAL e) {
+				// parameter passed by user was not compatible with Java to
+				// Corba mapping
+				throw new org.omg.CORBA.BAD_PARAM(0,
+						org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
 			}
 			try {
 				// invocation and sending result
 				Object result = service.getRuntimeWire(binding).invoke(
 						operation, inputInstances.toArray());
-				if (outputType != null) {
+				if (types.getOutputType() != null) {
 					OutputStream out = rh.createReply();
-					TypeTree tree = TypeTreeCreator.createTypeTree(outputType
-							.getPhysical());
+					TypeTree tree = types.getOutputType();
 					TypeHelpersProxy.write(tree.getRootNode(), out, result);
 					return out;
 				}
@@ -122,7 +160,7 @@
 					TypeHelpersProxy.write(tree.getRootNode(), out, ie
 							.getTargetException());
 					return out;
-				} catch (RequestConfigurationException e) {
+				} catch (Exception e) {
 					// TODO: raise remote exception - exception while handling
 					// target exception
 					e.printStackTrace();

Added: tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java?rev=671367&view=auto
==============================================================================
--- tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java (added)
+++ tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java Tue Jun 24 15:17:17 2008
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+import org.apache.tuscany.sca.binding.corba.impl.types.TypeTree;
+
+public class OperationTypes {
+
+	private TypeTree outputType;
+	private List<TypeTree> inputType;
+	
+	public TypeTree getOutputType() {
+		return outputType;
+	}
+	public void setOutputType(TypeTree outputType) {
+		this.outputType = outputType;
+	}
+	public List<TypeTree> getInputType() {
+		return inputType;
+	}
+	public void setInputType(List<TypeTree> inputType) {
+		this.inputType = inputType;
+	}
+	
+}

Propchange: tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java?rev=671367&r1=671366&r2=671367&view=diff
==============================================================================
--- tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java (original)
+++ tuscany/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java Tue Jun 24 15:17:17 2008
@@ -240,7 +240,7 @@
 			node.setJavaClass(forClass);
 		} else {
 			RequestConfigurationException e = new RequestConfigurationException(
-					"User defined type which cannot be handler: "
+					"User defined type which cannot be handled: "
 							+ forClass.getCanonicalName());
 			throw e;
 		}
@@ -366,7 +366,7 @@
 			} else {
 				forClass = forClass.getSuperclass();
 			}
-		} while (!forClass.equals(Object.class));
+		} while (forClass != null && !forClass.equals(Object.class));
 		return false;
 	}
 }

Modified: tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java?rev=671367&r1=671366&r2=671367&view=diff
==============================================================================
--- tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java (original)
+++ tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java Tue Jun 24 15:17:17 2008
@@ -25,6 +25,7 @@
 import junit.framework.TestCase;
 
 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.DynaCorbaServant;
@@ -48,6 +49,7 @@
 import org.apache.tuscany.sca.binding.corba.testing.servants.CalcServant;
 import org.apache.tuscany.sca.binding.corba.testing.servants.EnumManagerServant;
 import org.apache.tuscany.sca.binding.corba.testing.servants.InvalidTestObjectServant;
+import org.apache.tuscany.sca.binding.corba.testing.servants.InvalidTypesServant;
 import org.apache.tuscany.sca.binding.corba.testing.servants.NonCorbaServant;
 import org.apache.tuscany.sca.binding.corba.testing.servants.PrimitivesSetterServant;
 import org.apache.tuscany.sca.binding.corba.testing.servants.TestObjectServant;
@@ -283,7 +285,7 @@
 	/**
 	 * Tests handling BAD_OPERATION system exception
 	 */
-	public void test_noSuchOperation() {
+	public void test_systemException_BAD_OPERATION() {
 		try {
 			TestObjectServant tos = new TestObjectServant();
 			TestRuntimeComponentService service = new TestRuntimeComponentService(
@@ -436,5 +438,53 @@
 			}
 		}
 	}
-
+	
+	/**
+	 * Tests handling BAD_PARAM system exception
+	 */
+	public void test_systemException_BAD_PARAM() {
+		try {
+			CalcServant calc = new CalcServant();
+			TestRuntimeComponentService service = new TestRuntimeComponentService(
+					calc);
+			DynaCorbaServant servant = new DynaCorbaServant(service, null);
+			String[] ids = new String[] { "IDL:org/apache/tuscany/sca/binding/corba/testing/generated/TestObject:1.0" };
+			servant.setIds(ids);
+			bindServant(servant, "Calc");
+			DynaCorbaRequest request = new DynaCorbaRequest(
+					bindReference("Calc"), "div");
+			request.addArgument(2d);
+			request.setOutputType(double.class);
+			request.invoke();
+			fail();
+		} catch (Exception e) {
+			if (e instanceof CorbaException) {
+				assertTrue(true);
+			} else {
+				e.printStackTrace();
+				fail();
+			}
+		}
+	}
+	
+	/**
+	 * Tests handling BAD_PARAM system exception
+	 */
+	public void test_invalidServantConfiguraion() {
+		try {
+			InvalidTypesServant its = new InvalidTypesServant();
+			TestRuntimeComponentService service = new TestRuntimeComponentService(its);
+			//expecting exception...
+			new DynaCorbaServant(service, null);
+			fail();
+		} catch (Exception e) {
+			if (e instanceof RequestConfigurationException) {
+				assertTrue(true);
+			} else {
+				e.printStackTrace();
+				fail();
+			}
+		}
+	}
+	
 }

Modified: tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java?rev=671367&r1=671366&r2=671367&view=diff
==============================================================================
--- tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java (original)
+++ tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java Tue Jun 24 15:17:17 2008
@@ -491,7 +491,7 @@
 	/**
 	 * Tests handling non existing operation situation
 	 */
-	public void test_noOperationException() {
+	public void test_systemException_BAD_OPERATION() { 
 		DynaCorbaRequest request = new DynaCorbaRequest(refCalcObject,
 				"thisOperationSurelyDoesNotExist");
 		try {
@@ -605,5 +605,25 @@
 			fail();
 		}
 	}
+	
+	/**
+	 * Tests hanlding passing wrong params
+	 */
+	public void test_systemException_BAD_PARAM() {
+		try {
+			DynaCorbaRequest request = new DynaCorbaRequest(refCalcObject, "div");
+			request.setOutputType(Double.class);
+			request.addArgument(3d);
+			request.invoke();
+			fail();
+		} catch (Exception e) {
+			if (e instanceof CorbaException) {
+				assertTrue(true);
+			} else {
+				e.printStackTrace();
+				fail();
+			}
+		}
+	}
 
 }

Added: tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java?rev=671367&view=auto
==============================================================================
--- tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java (added)
+++ tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java Tue Jun 24 15:17:17 2008
@@ -0,0 +1,34 @@
+/*
+ * 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.testing.servants;
+
+import org.apache.tuscany.sca.binding.corba.testing.hierarchy.InvalidStruct1;
+
+public class InvalidTypesServant {
+
+	public InvalidStruct1 firstMethodWithInvalidArg() {
+		return null;
+	}
+	
+	public void secondMethodWithInvalidArg(InvalidStruct1 arg) {
+		
+	}
+	
+}

Propchange: tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java?rev=671367&r1=671366&r2=671367&view=diff
==============================================================================
--- tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java (original)
+++ tuscany/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java Tue Jun 24 15:17:17 2008
@@ -57,7 +57,7 @@
 		Method[] methods = invocationTarget.getClass().getMethods();
 		for (int i = 0; i < methods.length; i++) {
 			int mod = methods[i].getModifiers();
-			if (Modifier.isPublic(mod)) {
+			if (methods[i].getDeclaringClass().equals(invocationTarget.getClass()) && Modifier.isPublic(mod) && !methods[i].getName().startsWith("_")) {
 				Operation operation = new TestOperation();
 				DataType returnType = new TestDataType(methods[i]
 						.getReturnType());