diff options
Diffstat (limited to 'sca-java-2.x')
19 files changed, 400 insertions, 22 deletions
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JSONUtil.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JSONUtil.java index 30a14dd8bb..e21a2402b1 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JSONUtil.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JSONUtil.java @@ -49,6 +49,7 @@ public class JSONUtil { List<String> objects = new ArrayList<String>(); int bracketNum = 0; int parNum = 0; + int quoteNum = 0; int startPos = 1; for (int i = 0; i < jsonArray.length(); i++) { switch (jsonArray.charAt(i)) { @@ -64,8 +65,11 @@ public class JSONUtil { case ']': parNum--; break; + case '\"': + quoteNum++; + break; case ',': - if ((bracketNum == 0) && (parNum == 1)) { + if ((bracketNum == 0) && (parNum == 1) && quoteNum % 2 == 0) { objects.add(jsonArray.substring(startPos, i)); startPos = i + 1; } diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketServiceBindingProvider.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketServiceBindingProvider.java index efab714e5c..461b364b2f 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketServiceBindingProvider.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketServiceBindingProvider.java @@ -85,7 +85,6 @@ public class WebsocketServiceBindingProvider implements ServiceBindingProvider { }
}
websocketServers.clear();
- websocketServers = null;
}
}
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/Address.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/Address.java new file mode 100644 index 0000000000..149199c55b --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/Address.java @@ -0,0 +1,60 @@ +/* + * 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 registration; + +public class Address { + + private String street; + private String city; + private int zip; + + public Address() { + } + + public Address(String street, String city, int zip) { + this.street = street; + this.city = city; + this.zip = zip; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public int getZip() { + return zip; + } + + public void setZip(int zip) { + this.zip = zip; + } + +} diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/Confirmation.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/Confirmation.java new file mode 100644 index 0000000000..4bc3a5c27e --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/Confirmation.java @@ -0,0 +1,50 @@ +/* + * 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 registration; + +public class Confirmation { + + private String message; + private int messageLength; + + public Confirmation() { + } + + public Confirmation(String confirmationMessage, int messageLength) { + this.message = confirmationMessage; + this.messageLength = messageLength; + } + + public String getMessage() { + return message; + } + + public void setMessage(String confirmationMessage) { + this.message = confirmationMessage; + } + + public int getMessageLength() { + return messageLength; + } + + public void setMessageLength(int messageLength) { + this.messageLength = messageLength; + } + +} diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/Person.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/Person.java new file mode 100644 index 0000000000..8f0ae1b6e9 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/Person.java @@ -0,0 +1,60 @@ +/* + * 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 registration; + +public class Person { + + private String name; + private Address address; + private long ssn; + + public Person() { + } + + public Person(String name, Address address, long ssn) { + this.name = name; + this.address = address; + this.ssn = ssn; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } + + public long getSsn() { + return ssn; + } + + public void setSsn(long ssn) { + this.ssn = ssn; + } + +} diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/RegistrationClient.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/RegistrationClient.java new file mode 100644 index 0000000000..f9c79778e7 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/RegistrationClient.java @@ -0,0 +1,36 @@ +/*
+ * 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 registration;
+
+import java.util.Date;
+
+import org.oasisopen.sca.annotation.Reference;
+
+public class RegistrationClient implements RegistrationService {
+
+ @Reference
+ public RegistrationService service;
+
+ @Override
+ public Confirmation register(Person person, Date date) {
+ return service.register(person, date);
+ }
+
+}
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/RegistrationService.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/RegistrationService.java new file mode 100644 index 0000000000..3fbe0cac10 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/RegistrationService.java @@ -0,0 +1,30 @@ +/*
+ * 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 registration;
+
+import java.util.Date;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface RegistrationService {
+
+ Confirmation register(Person person, Date date);
+
+}
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/RegistrationServiceImpl.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/RegistrationServiceImpl.java new file mode 100644 index 0000000000..b3cefa76da --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/RegistrationServiceImpl.java @@ -0,0 +1,33 @@ +/*
+ * 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 registration;
+
+import java.util.Date;
+
+public class RegistrationServiceImpl implements RegistrationService {
+
+ @Override
+ public Confirmation register(Person person, Date date) {
+ String message = person.getName() + " from " + person.getAddress().getStreet() + ", "
+ + person.getAddress().getCity() + ", " + person.getAddress().getZip() + " with SSN " + person.getSsn()
+ + " registered on " + date.toString();
+ return new Confirmation(message, message.length());
+ }
+
+}
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/CiaoService.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/CiaoService.java index 87ff1c1355..145eb5d720 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/CiaoService.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/CiaoService.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations
* under the License.
*/
-package sample;
+package salutes;
import org.oasisopen.sca.annotation.Remotable;
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/CiaoImpl.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/CiaoServiceImpl.java index fc71681c52..503fc5b51d 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/CiaoImpl.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/CiaoServiceImpl.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations
* under the License.
*/
-package sample;
+package salutes;
-public class CiaoImpl implements CiaoService {
+public class CiaoServiceImpl implements CiaoService {
public String sayCiao(String name) {
return "Ciao " + name;
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/Client.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/Client.java index b4bf3df678..18d29b649a 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/Client.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/Client.java @@ -17,7 +17,7 @@ * under the License.
*/
-package sample;
+package salutes;
import org.oasisopen.sca.annotation.Reference;
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/HelloService.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/HelloService.java index a1c6efe870..a16ce18a1c 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/HelloService.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/HelloService.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations
* under the License.
*/
-package sample;
+package salutes;
import org.oasisopen.sca.annotation.Remotable;
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/HelloImpl.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/HelloServiceImpl.java index 055b04cc23..d0b93387f0 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/HelloImpl.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/HelloServiceImpl.java @@ -16,10 +16,10 @@ * specific language governing permissions and limitations
* under the License.
*/
-package sample;
+package salutes;
-public class HelloImpl implements HelloService {
+public class HelloServiceImpl implements HelloService {
public String sayHello(String name) {
return "Hello " + name;
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/SalutService.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/SalutService.java index 5bc8c56c99..e1dac86e1c 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/SalutService.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/SalutService.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations
* under the License.
*/
-package sample;
+package salutes;
import org.oasisopen.sca.annotation.Remotable;
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/SalutImpl.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/SalutServiceImpl.java index b2747df52e..eb9bea7e46 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/sample/SalutImpl.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/SalutServiceImpl.java @@ -16,9 +16,9 @@ * specific language governing permissions and limitations
* under the License.
*/
-package sample;
+package salutes;
-public class SalutImpl implements SalutService {
+public class SalutServiceImpl implements SalutService {
public String saySalut(String name) {
return "Salut " + name;
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/test/RegistrationWebsocketBindingTestCase.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/test/RegistrationWebsocketBindingTestCase.java new file mode 100644 index 0000000000..d179b18858 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/test/RegistrationWebsocketBindingTestCase.java @@ -0,0 +1,69 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package test;
+
+import java.util.Date;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import registration.Address;
+import registration.Confirmation;
+import registration.Person;
+import registration.RegistrationService;
+
+public class RegistrationWebsocketBindingTestCase {
+
+ private static Node node;
+
+ @Test
+ public void testJSONSerialization() {
+ RegistrationService registrationClient = node.getService(RegistrationService.class,
+ "ClientComponent/RegistrationService");
+ Address address = new Address("Queen Elizabeth", "London", 12345);
+ Person person = new Person("John Locke", address, 1122334455);
+ Date date = new Date();
+
+ Confirmation confirmation = registrationClient.register(person, date);
+
+ String expectedMessage = person.getName() + " from " + person.getAddress().getStreet() + ", "
+ + person.getAddress().getCity() + ", " + person.getAddress().getZip() + " with SSN " + person.getSsn()
+ + " registered on " + date.toString();
+ Assert.assertEquals(expectedMessage, confirmation.getMessage());
+ Assert.assertEquals(expectedMessage.length(), confirmation.getMessageLength());
+ }
+
+ @BeforeClass
+ public static void init() throws Exception {
+ node = NodeFactory.newInstance().createNode("registration.composite").start();
+ }
+
+ @AfterClass
+ public static void destroy() throws Exception {
+ if (node != null) {
+ node.stop();
+ }
+ }
+
+}
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/test/WebsocketBindingTestCase.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/test/SalutesWebsocketBindingTestCase.java index 3161b73a7a..22d0861c81 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/test/WebsocketBindingTestCase.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/test/SalutesWebsocketBindingTestCase.java @@ -26,11 +26,11 @@ import org.junit.AfterClass; import org.junit.BeforeClass;
import org.junit.Test;
-import sample.CiaoService;
-import sample.HelloService;
-import sample.SalutService;
+import salutes.CiaoService;
+import salutes.HelloService;
+import salutes.SalutService;
-public class WebsocketBindingTestCase {
+public class SalutesWebsocketBindingTestCase {
private static Node node;
@@ -54,7 +54,7 @@ public class WebsocketBindingTestCase { @BeforeClass
public static void init() throws Exception {
- node = NodeFactory.newInstance().createNode("test.composite").start();
+ node = NodeFactory.newInstance().createNode("salutes.composite").start();
}
@AfterClass
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/resources/registration.composite b/sca-java-2.x/contrib/modules/binding-websocket/src/test/resources/registration.composite new file mode 100644 index 0000000000..60bbda50ec --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/resources/registration.composite @@ -0,0 +1,37 @@ +<?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.
+ -->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://itest"
+ name="RegistrationComposite">
+
+ <component name="RegistrationComponent">
+ <implementation.java class="registration.RegistrationServiceImpl"/>
+ <service name="RegistrationService" >
+ <tuscany:binding.websocket uri="ws://127.0.0.1:5555" />
+ </service>
+ </component>
+
+ <component name="ClientComponent">
+ <implementation.java class="registration.RegistrationClient"/>
+ <reference name="service" target="RegistrationComponent/RegistrationService" />
+ </component>
+
+</composite>
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/resources/test.composite b/sca-java-2.x/contrib/modules/binding-websocket/src/test/resources/salutes.composite index e7b3e086d5..35126ba267 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/resources/test.composite +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/test/resources/salutes.composite @@ -20,31 +20,31 @@ <composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
targetNamespace="http://itest"
- name="HelloWorldComposite">
+ name="SalutesComposite">
<component name="HelloComponent">
- <implementation.java class="sample.HelloImpl"/>
+ <implementation.java class="salutes.HelloServiceImpl"/>
<service name="HelloService" >
<tuscany:binding.websocket uri="ws://127.0.0.1:5555" />
</service>
</component>
<component name="SalutComponent">
- <implementation.java class="sample.SalutImpl"/>
+ <implementation.java class="salutes.SalutServiceImpl"/>
<service name="SalutService" >
<tuscany:binding.websocket uri="ws://127.0.0.1:5555" />
</service>
</component>
<component name="CiaoComponent">
- <implementation.java class="sample.CiaoImpl"/>
+ <implementation.java class="salutes.CiaoServiceImpl"/>
<service name="CiaoService" >
<tuscany:binding.websocket uri="ws://127.0.0.1:6666" />
</service>
</component>
<component name="ClientComponent">
- <implementation.java class="sample.Client"/>
+ <implementation.java class="salutes.Client"/>
<reference name="hello" target="HelloComponent/HelloService" />
<reference name="salut" target="SalutComponent/SalutService" />
<reference name="ciao" target="CiaoComponent/CiaoService" />
|