summaryrefslogtreecommitdiffstats
path: root/java/sca/modules
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-06-24 22:17:17 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2008-06-24 22:17:17 +0000
commitadae3fa3d6d27c7475596876fb7acc248d040d6d (patch)
tree092137f60adf502990ba8c9974763ae1a04b17da /java/sca/modules
parent29ee2565f719b58a808160c961ff55e9c05c520f (diff)
Apply the patch from Wojtek for TUSCANY-2357 (typescache-tests-jira-2357-24-june-2008.patch). Thanks.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@671367 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules')
-rw-r--r--java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java3
-rw-r--r--java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/DynaCorbaServant.java70
-rw-r--r--java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java44
-rw-r--r--java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java4
-rw-r--r--java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaServantTestCase.java54
-rw-r--r--java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java22
-rw-r--r--java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java34
-rw-r--r--java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java2
8 files changed, 211 insertions, 22 deletions
diff --git a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java
index 178a0fdc8a..1e41e60b9f 100644
--- a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java
+++ b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/reference/DynaCorbaRequest.java
@@ -29,6 +29,7 @@ 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.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 @@ public class DynaCorbaRequest {
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);
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 52d1383025..e5b2ec597b 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
@@ -21,7 +21,9 @@ package org.apache.tuscany.sca.binding.corba.impl.service;
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.binding.corba.impl.types.util.Utils;
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 @@ public class DynaCorbaServant extends ObjectImpl implements InvokeHandler {
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 class DynaCorbaServant extends ObjectImpl implements InvokeHandler {
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 @@ public class DynaCorbaServant extends ObjectImpl implements InvokeHandler {
// 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 @@ public class DynaCorbaServant extends ObjectImpl implements InvokeHandler {
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 @@ public class DynaCorbaServant extends ObjectImpl implements InvokeHandler {
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();
diff --git a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java
new file mode 100644
index 0000000000..fba667b072
--- /dev/null
+++ b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/service/OperationTypes.java
@@ -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;
+ }
+
+}
diff --git a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java
index 24bd8dcbe7..16ae0b502e 100644
--- a/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java
+++ b/java/sca/modules/binding-corba-runtime/src/main/java/org/apache/tuscany/sca/binding/corba/impl/types/TypeTreeCreator.java
@@ -240,7 +240,7 @@ public class TypeTreeCreator {
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 @@ public class TypeTreeCreator {
} else {
forClass = forClass.getSuperclass();
}
- } while (!forClass.equals(Object.class));
+ } while (forClass != null && !forClass.equals(Object.class));
return false;
}
}
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 607695f971..b3b3474636 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
@@ -25,6 +25,7 @@ import java.lang.reflect.Array;
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.ArraysSetterServant
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 @@ public class CorbaServantTestCase extends TestCase {
/**
* 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 @@ public class CorbaServantTestCase extends TestCase {
}
}
}
-
+
+ /**
+ * 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();
+ }
+ }
+ }
+
}
diff --git a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java
index d68510b6af..a91fc55496 100644
--- a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java
+++ b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/CorbaTypesTestCase.java
@@ -491,7 +491,7 @@ public class CorbaTypesTestCase extends TestCase {
/**
* 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 @@ public class CorbaTypesTestCase extends TestCase {
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();
+ }
+ }
+ }
}
diff --git a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java
new file mode 100644
index 0000000000..00fc367139
--- /dev/null
+++ b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/servants/InvalidTypesServant.java
@@ -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) {
+
+ }
+
+}
diff --git a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java
index 698114a2d0..594b8a8a38 100644
--- a/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java
+++ b/java/sca/modules/binding-corba-runtime/src/test/java/org/apache/tuscany/sca/binding/corba/testing/service/mocks/TestRuntimeComponentService.java
@@ -57,7 +57,7 @@ public class TestRuntimeComponentService implements RuntimeComponentService {
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());