summaryrefslogtreecommitdiffstats
path: root/branches/sca-java-1.x/modules
diff options
context:
space:
mode:
authorwjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68>2009-04-18 15:48:01 +0000
committerwjaniszewski <wjaniszewski@13f79535-47bb-0310-9956-ffa450edef68>2009-04-18 15:48:01 +0000
commit8f70a12249558f8b342a57740b6d6423ea23da57 (patch)
treeccfea4c62bf67c2d5827943e3128b6e415c1a87c /branches/sca-java-1.x/modules
parent001f5d05380840d811c85547c361ae0fde5a35a1 (diff)
General improvements
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@766345 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules')
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java7
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java22
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java56
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java2
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java35
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java2
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java5
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java4
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.java4
-rw-r--r--branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.java6
10 files changed, 106 insertions, 37 deletions
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java
index 2fe9ae38b9..a2cf71a053 100644
--- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java
+++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ErlangInvoker.java
@@ -62,6 +62,7 @@ public class ErlangInvoker implements Invoker {
} else {
// NOTE: don't throw exception if not declared
// TODO: externalize message?
+ msg.setBody(null);
logger
.log(Level.WARNING, "Problem while sending/receiving data",
e);
@@ -82,7 +83,11 @@ public class ErlangInvoker implements Invoker {
node.setCookie(binding.getCookie());
}
tmpMbox = node.createMbox();
- Object[] args = msg.getBody();
+ // obtain args, make sure they aren't null
+ // NOTE: sending message with no content (but only with senders PID)
+ // is possible
+ Object[] args = (Object[]) (msg.getBody() != null ? msg.getBody()
+ : new Object[0]);
Method jmethod = ((JavaOperation) msg.getOperation())
.getJavaMethod();
// create and send msg with self pid in the beginning
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java
index 26b772f5e3..9e292fe3bb 100644
--- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java
+++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/ServiceExecutor.java
@@ -152,10 +152,8 @@ public class ServiceExecutor implements Runnable {
&& operation.getOutputType().getPhysical()
.isArray()) {
// output type is array
- Annotation[][] outNotes = new Annotation[][] { jmethod
- .getAnnotations() };
- response = TypeHelpersProxy.toErlangAsList(result,
- outNotes);
+ response = TypeHelpersProxy.toErlangAsResultList(
+ result, jmethod.getAnnotations());
} else if (operation.getOutputType() == null) {
// output type is void, create empty reply
Object[] arrArg = new Object[] {};
@@ -248,8 +246,7 @@ public class ServiceExecutor implements Runnable {
msgNoSender = msg.getMsg();
}
} catch (Exception e) {
- // TODO: check when this exception can occur
- e.printStackTrace();
+ logger.log(Level.WARNING, "Unexpected error", e);
}
if (operations == null) {
@@ -294,10 +291,8 @@ public class ServiceExecutor implements Runnable {
&& matchedOperation.getOutputType().getPhysical()
.isArray()) {
// result type is array
- Annotation[][] outNotes = new Annotation[][] { jmethod
- .getAnnotations() };
- response = TypeHelpersProxy.toErlangAsList(result,
- outNotes);
+ response = TypeHelpersProxy.toErlangAsResultList(
+ result, jmethod.getAnnotations());
} else if (matchedOperation.getOutputType() != null) {
// result type is not array and not void
response = TypeHelpersProxy.toErlang(result, jmethod
@@ -330,13 +325,10 @@ public class ServiceExecutor implements Runnable {
e1.printStackTrace();
}
} else {
- // unknown/unhandled error
- // TODO: decide what to do with this exception
- e.printStackTrace();
+ logger.log(Level.WARNING, "Unexpected error", e);
}
} catch (Exception e) {
- // FIXME: log this problem? use linking feature? send error?
- e.printStackTrace();
+ logger.log(Level.WARNING, "Unexpected error", e);
}
} else {
// TODO: externalize message?
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java
index 380abb852b..2ab29490e3 100644
--- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java
+++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/main/java/org/apache/tuscany/sca/binding/erlang/impl/types/TypeHelpersProxy.java
@@ -72,13 +72,23 @@ public class TypeHelpersProxy {
for (int i = 0; i < notes.length; i++) {
typeHelper = primitiveTypes.get(notes[i].annotationType());
if (typeHelper != null) {
- // annotation found, check if it points to array
- // FIXME: check if annotation points to proper type
- // ie. ErlangAtom -> String. If not, then log? exception?
- if (forClass.isArray()) {
- typeHelper = new AnnotatedListTypeHelper(notes);
+ // get type which is annotated, reduce array if needed
+ Class<?> annotatedType = forClass;
+ while (annotatedType.isArray()) {
+ annotatedType = annotatedType.getComponentType();
+ }
+ if (notes[i].annotationType().equals(ErlangAtom.class)
+ && !annotatedType.equals(String.class)) {
+ // NOTE: @ErlangAtom atom will be ignored if not annotates
+ // string
+ typeHelper = null;
+ } else {
+ // check if annotation points to array
+ if (forClass.isArray()) {
+ typeHelper = new AnnotatedListTypeHelper(notes);
+ }
+ break;
}
- break;
}
}
// check for standard types
@@ -145,24 +155,42 @@ public class TypeHelpersProxy {
* Creates Erlang list basing on unknown Java arrays
*
* @param array
+ * @param notes
* @return
*/
public static OtpErlangList toErlangAsList(Object array,
Annotation[][] notes) {
+ return toErlangAsList(array, notes, false);
+ }
+
+ /**
+ * Creates Erlang list of result elements
+ *
+ * @param array
+ * @param notes
+ * @return
+ */
+ public static OtpErlangList toErlangAsResultList(Object array,
+ Annotation[] notes) {
+ return toErlangAsList(array, new Annotation[][] { notes }, true);
+ }
+
+ /**
+ *
+ * @param array
+ * @param notes
+ * @param isArray
+ * @return
+ */
+ private static OtpErlangList toErlangAsList(Object array,
+ Annotation[][] notes, boolean isArray) {
OtpErlangList result = null;
if (array != null) {
List<OtpErlangObject> attrsList = new ArrayList<OtpErlangObject>();
int i = 0;
while (true) {
try {
- // FIXME: if notes.length == 1 then its used to annotate
- // array. Clean up.
- Annotation[] currNotes = null;
- if (notes.length == 1) {
- currNotes = notes[0];
- } else {
- currNotes = notes[i];
- }
+ Annotation[] currNotes = isArray ? notes[0] : notes[i];
TypeHelper helper = getTypeHelper(Array.get(array, i)
.getClass(), currNotes);
attrsList.add(helper.toErlang(Array.get(array, i)));
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java
index 8f950d54f7..034abab8f3 100644
--- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java
+++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/MboxInterface.java
@@ -60,6 +60,6 @@ public interface MboxInterface {
@ErlangAtom
String[][] sendArgs(@ErlangAtom String[][] arg1, int arg2);
- void sendArgs();
+ void sendArgs() throws Exception;
}
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java
index 0c80df7a04..2073e4b154 100644
--- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java
+++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java
@@ -32,7 +32,6 @@ import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -464,6 +463,30 @@ public class ReferenceServiceTestCase {
}
/**
+ * Tests Erlang Atom types on service side
+ *
+ * @throws Exception
+ */
+ @Test(timeout = 1000)
+ public void testServiceAtoms() throws Exception {
+ String[] args = { "Say", "Atoms" };
+ OtpErlangObject[] toList = new OtpErlangObject[2];
+ toList[0] = new OtpErlangString(args[0]);
+ toList[1] = new OtpErlangString(args[1]);
+ OtpErlangList list = new OtpErlangList(toList);
+ OtpErlangObject[] toTuple = new OtpErlangObject[2];
+ toTuple[0] = refMbox.self();
+ toTuple[1] = list;
+ refMbox.send("sayAtoms", "RPCServerMbox", new OtpErlangTuple(toTuple));
+ OtpErlangObject result = refMbox.receiveMsg().getMsg();
+ assertEquals(args.length, ((OtpErlangList) result).arity());
+ for (int i = 0; i < args.length; i++) {
+ assertEquals(args[i], ((OtpErlangAtom) ((OtpErlangList) result)
+ .elementAt(i)).atomValue());
+ }
+ }
+
+ /**
* Tests mismatched interface
*
* @throws Exception
@@ -886,12 +909,16 @@ public class ReferenceServiceTestCase {
cookieModuleReference.sayHellos();
}
+ /**
+ * Tests fix which allow to send message with no user specified content (in
+ * fact always will be some content - senders PID at the content beginning).
+ *
+ * @throws Exception
+ */
@Test(timeout = 1000)
- @Ignore("Nothing to test yet")
public void testMboxNoArgs() throws Exception {
- // FIXME: decide what to do while invoking mbox reference with no params
- // exception? log?
mboxReference.sendArgs();
+ // no exception should occur
}
}
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java
index 76ff3fdbe0..244e6f7f40 100644
--- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java
+++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceInterface.java
@@ -41,5 +41,5 @@ public interface ServiceInterface {
void notExistWithException() throws Exception;
void notExist();
-
+
}
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java
index 60650188bc..7cc1fe4dc1 100644
--- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java
+++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponent.java
@@ -19,6 +19,8 @@
package org.apache.tuscany.sca.binding.erlang.testing;
+import org.apache.tuscany.sca.binding.erlang.meta.ErlangAtom;
+
/**
* @version $Rev$ $Date$
*/
@@ -28,6 +30,9 @@ public interface ServiceTestComponent {
String[] sayHellos() throws Exception;
+ @ErlangAtom
+ String[] sayAtoms(@ErlangAtom String[] arg);
+
StructuredTuple passComplexArgs(StructuredTuple arg1, String[] arg2);
void doNothing();
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java
index 551ad3d063..b3f39fecd4 100644
--- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java
+++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImpl.java
@@ -41,4 +41,8 @@ public class ServiceTestComponentImpl implements ServiceTestComponent {
// doing nothing
}
+ public String[] sayAtoms(String[] arg) {
+ return arg;
+ }
+
}
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.java
index b59662551c..735cefe53d 100644
--- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.java
+++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplClone.java
@@ -41,4 +41,8 @@ public class ServiceTestComponentImplClone implements ServiceTestComponent {
}
+ public String[] sayAtoms(String[] arg) {
+ return arg;
+ }
+
}
diff --git a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.java b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.java
index bcf454837e..40a9f96769 100644
--- a/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.java
+++ b/branches/sca-java-1.x/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ServiceTestComponentImplTimeout.java
@@ -25,7 +25,7 @@ package org.apache.tuscany.sca.binding.erlang.testing;
public class ServiceTestComponentImplTimeout implements ServiceTestComponent {
private long duration = 1000;
-
+
public String sayHello(String arg1, String arg2) {
try {
Thread.sleep(duration);
@@ -58,4 +58,8 @@ public class ServiceTestComponentImplTimeout implements ServiceTestComponent {
}
+ public String[] sayAtoms(String[] arg) {
+ return arg;
+ }
+
}