diff options
Diffstat (limited to '')
42 files changed, 623 insertions, 1140 deletions
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/deploy-monsoon.sh b/sca-java-2.x/contrib/modules/binding-websocket/deploy-monsoon.sh deleted file mode 100755 index 641100d2ba..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/deploy-monsoon.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -~/apps/apache-maven-2.2.1/bin/mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file -Dfile=target/websocket-0.0.1-SNAPSHOT.jar -DgroupId=org.apache -DartifactId=websocket -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar -DlocalRepositoryPath=/home/fmoga/coding/apache-tuscany/contrib/modules/binding-websocket/monsoon-repo diff --git a/sca-java-2.x/contrib/modules/binding-websocket/monsoon-repo/org/apache/websocket/0.0.1-SNAPSHOT/maven-metadata-local.xml b/sca-java-2.x/contrib/modules/binding-websocket/monsoon-repo/org/apache/websocket/0.0.1-SNAPSHOT/maven-metadata-local.xml deleted file mode 100644 index 73a9522d80..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/monsoon-repo/org/apache/websocket/0.0.1-SNAPSHOT/maven-metadata-local.xml +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<metadata> - <groupId>org.apache</groupId> - <artifactId>websocket</artifactId> - <version>0.0.1-SNAPSHOT</version> - <versioning> - <snapshot> - <localCopy>true</localCopy> - </snapshot> - <lastUpdated>20110708014923</lastUpdated> - </versioning> -</metadata> diff --git a/sca-java-2.x/contrib/modules/binding-websocket/monsoon-repo/org/apache/websocket/0.0.1-SNAPSHOT/websocket-0.0.1-SNAPSHOT.jar b/sca-java-2.x/contrib/modules/binding-websocket/monsoon-repo/org/apache/websocket/0.0.1-SNAPSHOT/websocket-0.0.1-SNAPSHOT.jar Binary files differdeleted file mode 100644 index d65c001bec..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/monsoon-repo/org/apache/websocket/0.0.1-SNAPSHOT/websocket-0.0.1-SNAPSHOT.jar +++ /dev/null diff --git a/sca-java-2.x/contrib/modules/binding-websocket/monsoon-repo/org/apache/websocket/0.0.1-SNAPSHOT/websocket-0.0.1-SNAPSHOT.pom b/sca-java-2.x/contrib/modules/binding-websocket/monsoon-repo/org/apache/websocket/0.0.1-SNAPSHOT/websocket-0.0.1-SNAPSHOT.pom deleted file mode 100644 index 118bbdb13e..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/monsoon-repo/org/apache/websocket/0.0.1-SNAPSHOT/websocket-0.0.1-SNAPSHOT.pom +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - <groupId>org.apache</groupId> - <artifactId>websocket</artifactId> - <version>0.0.1-SNAPSHOT</version> - <description>POM was created from install:install-file</description> -</project> diff --git a/sca-java-2.x/contrib/modules/binding-websocket/monsoon-repo/org/apache/websocket/maven-metadata-local.xml b/sca-java-2.x/contrib/modules/binding-websocket/monsoon-repo/org/apache/websocket/maven-metadata-local.xml deleted file mode 100644 index b52871f6c2..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/monsoon-repo/org/apache/websocket/maven-metadata-local.xml +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<metadata> - <groupId>org.apache</groupId> - <artifactId>websocket</artifactId> - <version>0.0.1-SNAPSHOT</version> - <versioning> - <versions> - <version>0.0.1-SNAPSHOT</version> - </versions> - <lastUpdated>20110708014923</lastUpdated> - </versioning> -</metadata> diff --git a/sca-java-2.x/contrib/modules/binding-websocket/pom.xml b/sca-java-2.x/contrib/modules/binding-websocket/pom.xml index 6d063755a5..376369e750 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/pom.xml +++ b/sca-java-2.x/contrib/modules/binding-websocket/pom.xml @@ -42,11 +42,11 @@ </dependency>
<dependency>
- <groupId>org.apache</groupId>
- <artifactId>websocket</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <scope>compile</scope>
- </dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-websocket</artifactId>
+ <version>8.0.0.M3</version>
+ <scope>compile</scope>
+ </dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
@@ -64,11 +64,4 @@ </dependencies>
- <repositories>
- <repository>
- <id>monsoon-local</id>
- <url>file://${basedir}/monsoon-repo</url>
- </repository>
- </repositories>
-
</project>
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/META-INF/MANIFEST.MF b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..5e9495128c --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0
+Class-Path:
+
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/WebsocketBinding.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/WebsocketBinding.java index 8988b376de..a78a6b11c2 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/WebsocketBinding.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/WebsocketBinding.java @@ -28,6 +28,7 @@ import org.apache.tuscany.sca.provider.BaseBindingImpl; public class WebsocketBinding extends BaseBindingImpl {
public static final QName TYPE = new QName(SCA11_TUSCANY_NS, "binding.websocket");
+ private String port;
public WebsocketBinding() {
}
@@ -37,4 +38,12 @@ public class WebsocketBinding extends BaseBindingImpl { return TYPE;
}
+ public String getPort() {
+ return port;
+ }
+
+ public void setPort(String port) {
+ this.port = port;
+ }
+
}
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 492dfae3dd..3fdb1ee1c1 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 @@ -33,6 +33,18 @@ public class JSONUtil { private static Gson gson = new Gson(); + public static String encodeMessage(WebSocketBindingMessage request) { + return gson.toJson(request); + } + + public static WebSocketBindingMessage decodeMessage(String jsonRequest) { + return gson.fromJson(jsonRequest, WebSocketBindingMessage.class); + } + + public static String encodePayload(Object payload) { + return gson.toJson(payload); + } + /** * Convert request parameters from JSON to operation parameter types. * @@ -42,7 +54,7 @@ public class JSONUtil { * the operation to invoke * @return an array of objects */ - public static Object[] decodeJsonParamsForOperation(String jsonData, Operation operation) { + public static Object[] decodePayloadForOperation(String jsonData, Operation operation) { Object[] args = new Object[operation.getInputType().getLogical().size()]; final String[] json = parseArray(jsonData); int index = 0; @@ -100,49 +112,4 @@ public class JSONUtil { private JSONUtil() { } - /** - * Converts a Java object to JSON format. - * - * @param response - * the response to convert - * @return the object in JSON format - */ - public static String encodeResponse(Object response) { - return gson.toJson(response); - } - - /** - * Convert request parameters as JSON array. - * - * @param params - * request parameters - * @return request parameters as JSON array - */ - public static String encodeRequestParams(Object[] params) { - StringBuilder builder = new StringBuilder(); - for (int index = 0; index < params.length; index++) { - Object param = params[index]; - builder.append(index == 0 ? "[" : ","); - builder.append(gson.toJson(param)); - } - builder.append("]"); - return builder.toString(); - } - - public static String encodeRequest(WebSocketBindingRequest request) { - return gson.toJson(request); - } - - public static WebSocketBindingRequest decodeRequest(String jsonRequest) { - return gson.fromJson(jsonRequest, WebSocketBindingRequest.class); - } - - public static WebSocketBindingResponse decodeResponse(String operationResponse) { - return gson.fromJson(operationResponse, WebSocketBindingResponse.class); - } - - public static Object decodeResponsePayload(String payload, Class<?> returnType) { - return gson.fromJson(payload, returnType); - } - } diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JavascriptGenerator.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JavascriptGenerator.java new file mode 100644 index 0000000000..04faf0113d --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JavascriptGenerator.java @@ -0,0 +1,99 @@ +/*
+ * 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.
+ */
+
+package org.apache.tuscany.sca.binding.websocket.runtime;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+
+public class JavascriptGenerator {
+
+ private final static String CONTEXT = "this.WebsocketComponentContext";
+ private static final String LF = "\n";
+ private static StringBuilder builder = new StringBuilder();
+
+ public static void generateServiceProxy(String component, String service, List<Operation> operations, int port) {
+ if (builder.length() == 0) {
+ builder.append(CONTEXT).append("={};").append(LF);
+ }
+ builder.append("if(!" + CONTEXT + "." + component + ")" + CONTEXT + "." + component + "={};").append(LF);
+ builder.append(CONTEXT + "." + component + "." + service + "={};").append(LF);
+ for (Operation operation : operations) {
+ builder.append(
+ CONTEXT + "." + component + "." + service + "." + operation.getName() + "="
+ + generateFunctionHeader(operation)).append(LF);
+ builder.append(generateFunctionContent(port, component, service, operation)).append(LF);
+ builder.append("};").append(LF);
+ }
+ }
+
+ private static String generateFunctionHeader(Operation operation) {
+ String header = "function(";
+ for (int i = 0; i < operation.getInputType().getLogical().size(); i++) {
+ if (i > 0)
+ header += ",";
+ header += "p" + i;
+ }
+ header += ") {";
+ return header;
+ }
+
+ private static String generateFunctionContent(int port, String component, String service, Operation operation) {
+ String content = "sendMessage(" + port + ",'" + component + "." + service + "." + operation.getName() + "',[";
+ for (int i = 0; i < operation.getInputType().getLogical().size(); i++) {
+ if (i > 0)
+ content += ",";
+ content += "p" + i;
+ }
+ content += "]);";
+ return content;
+ }
+
+ public static String getServiceProxies() {
+ return builder.toString();
+ }
+
+ public static void clear() {
+ builder.setLength(0);
+ }
+
+ private JavascriptGenerator() {
+ }
+
+}
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JavascriptResourceServlet.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JavascriptResourceServlet.java new file mode 100644 index 0000000000..def2783a81 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/JavascriptResourceServlet.java @@ -0,0 +1,109 @@ +/*
+ * 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.
+ */
+
+package org.apache.tuscany.sca.binding.websocket.runtime;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class JavascriptResourceServlet extends HttpServlet {
+
+ private static final String JSON_PLUGIN_PATH = "js/jquery.json-2.2.min.js";
+ private static final String WEBSOCKET_TOOLKIT_PATH = "js/TuscanyWebsocketToolkit.js";
+
+ private String jsonPlugin;
+ private String websocketToolkit;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
+ try {
+ resp.setContentType("text/javascript");
+ OutputStream os = resp.getOutputStream();
+ os.write(getJsonPlugin().getBytes());
+ os.write("var Tuscany = new function() {\n".getBytes());
+ os.write(getWebsocketToolkit().getBytes());
+ os.write(JavascriptGenerator.getServiceProxies().getBytes());
+ os.write("}\n".getBytes());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private String getJsonPlugin() {
+ if (jsonPlugin == null) {
+ jsonPlugin = getResource(JSON_PLUGIN_PATH);
+ }
+ return jsonPlugin;
+ }
+
+ private String getWebsocketToolkit() {
+ if (websocketToolkit == null) {
+ websocketToolkit = getResource(WEBSOCKET_TOOLKIT_PATH);
+ }
+ return websocketToolkit;
+ }
+
+ private String getResource(String path) {
+ InputStream is = getClass().getClassLoader().getResourceAsStream(path);
+ BufferedReader r = new BufferedReader(new InputStreamReader(is));
+ StringBuilder builder = new StringBuilder();
+ try {
+ String line = null;
+ while ((line = r.readLine()) != null) {
+ builder.append(line + "\n");
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } finally {
+ try {
+ r.close();
+ } catch (IOException ignored) {
+ }
+ }
+ return builder.toString();
+ }
+
+}
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/TuscanyWebSocket.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/TuscanyWebSocket.java new file mode 100644 index 0000000000..c267d9e6a4 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/TuscanyWebSocket.java @@ -0,0 +1,61 @@ +/* + * 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.websocket.runtime; + +import java.io.IOException; + +import org.eclipse.jetty.websocket.WebSocket; + +public class TuscanyWebSocket implements WebSocket, WebSocket.OnTextMessage { + + private Connection connection; + private WebSocketBindingDispatcher dispatcher; + + public TuscanyWebSocket(WebSocketBindingDispatcher dispatcher) { + this.dispatcher = dispatcher; + } + + @Override + public void onOpen(Connection connection) { + this.connection = connection; + } + + @Override + public void onMessage(String jsonRequest) { + WebSocketBindingMessage request = JSONUtil.decodeMessage(jsonRequest); + WebsocketServiceInvoker invoker = dispatcher.dispatch(request.getOperation()); + if (invoker == null) { + throw new RuntimeException("No operation found for " + request.getOperation()); + } else { + WebSocketBindingMessage response = invoker.invokeSync(request); + String jsonResponse = JSONUtil.encodeMessage(response); + try { + connection.sendMessage(jsonResponse); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + @Override + public void onClose(int closeCode, String message) { + } + +} diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/Client.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketBindingDispatcher.java index 18d29b649a..4e0dbaffd5 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/Client.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketBindingDispatcher.java @@ -1,48 +1,39 @@ -/*
- * 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 salutes;
-
-import org.oasisopen.sca.annotation.Reference;
-
-public class Client implements HelloService, SalutService, CiaoService {
-
- @Reference
- public HelloService hello;
- @Reference
- public SalutService salut;
- @Reference
- public CiaoService ciao;
-
- @Override
- public String sayHello(String name) {
- return hello.sayHello(name);
- }
-
- @Override
- public String saySalut(String name) {
- return salut.saySalut(name);
- }
-
- @Override
- public String sayCiao(String name) {
- return ciao.sayCiao(name);
- }
-
-}
+/* + * 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.websocket.runtime; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; + +public class WebSocketBindingDispatcher { + + private Map<String, WebsocketServiceInvoker> invokers = new HashMap<String, WebsocketServiceInvoker>(); + + public void addOperation(String uri, RuntimeEndpoint endpoint, Operation operation) { + System.out.println("Adding " + uri); + invokers.put(uri, new WebsocketServiceInvoker(operation, endpoint)); + } + + public WebsocketServiceInvoker dispatch(String uri) { + return invokers.get(uri); + } +}
\ No newline at end of file diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketBindingResponse.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketBindingMessage.java index 51664879a3..1ff8c4c10e 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketBindingResponse.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketBindingMessage.java @@ -18,22 +18,22 @@ */ package org.apache.tuscany.sca.binding.websocket.runtime; -public class WebSocketBindingResponse { +public class WebSocketBindingMessage { - private String uri; + private String operation; private String payload; - public WebSocketBindingResponse(String uri, String payload) { - this.uri = uri; + public WebSocketBindingMessage(String operation, String payload) { + this.operation = operation; this.payload = payload; } - public String getUri() { - return uri; + public String getOperation() { + return operation; } - public void setUri(String uri) { - this.uri = uri; + public void setOperation(String operation) { + this.operation = operation; } public String getPayload() { diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketBindingRequest.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketBindingRequest.java deleted file mode 100644 index 19b875805a..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketBindingRequest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.websocket.runtime; - -public class WebSocketBindingRequest { - - private String requestId; - private String uri; - private String payload; - - public WebSocketBindingRequest(String requestId, String uri, String payload) { - this.requestId = requestId; - this.uri = uri; - this.payload = payload; - } - - public String getRequestId() { - return requestId; - } - - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - public String getUri() { - return uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public String getPayload() { - return payload; - } - - public void setPayload(String payload) { - this.payload = payload; - } - -} diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketOperationDispatcher.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketOperationDispatcher.java deleted file mode 100644 index c33b3ca12a..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketOperationDispatcher.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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.websocket.runtime; - -import java.io.IOException; -import java.nio.channels.SocketChannel; -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.runtime.RuntimeEndpoint; -import org.apache.websocket.ServerWebSocket; -import org.apache.websocket.WebSocket; -import org.apache.websocket.WebSocketApplication; -import org.apache.websocket.WebSocketException; - -public class WebSocketOperationDispatcher implements WebSocketApplication<SocketChannel> { - - private ServerWebSocket server; - private Map<String, RuntimeEndpoint> endpoints = new HashMap<String, RuntimeEndpoint>(); - private Map<String, Operation> operations = new HashMap<String, Operation>(); - - public WebSocketOperationDispatcher(ServerWebSocket server) { - this.server = server; - } - - public void addOperation(String uri, RuntimeEndpoint endpoint, Operation operation) { - endpoints.put(uri, endpoint); - operations.put(uri, operation); - } - - public Operation getOperation(String uri) { - return operations.get(uri); - } - - public RuntimeEndpoint getEndpoint(String uri) { - return endpoints.get(uri); - } - - @Override - public void onConnection(WebSocket<SocketChannel> socket) { - // release server thread - new Thread(new WebSocketRequestHandler(socket, this)).start(); - } - - @Override - public void onHandshakeError(IOException e) { - throw new RuntimeException(e); - } - - @Override - public String acceptProtocol(String protocol) { - // don't accept any subprotocols - return null; - } - - @Override - public boolean acceptOrigin(String origin) { - // accept all clients - return true; - } - - @Override - public Map<String, String> acceptExtensions(Map<String, String> headers) throws WebSocketException { - // don't accept any extensions - return null; - } - - public void shutdown() { - try { - server.close(); - endpoints.clear(); - operations.clear(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - -}
\ No newline at end of file diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketRequestHandler.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketRequestHandler.java deleted file mode 100644 index 59d8af3133..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketRequestHandler.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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.websocket.runtime; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.nio.channels.SocketChannel; - -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.runtime.RuntimeEndpoint; -import org.apache.websocket.WebSocket; - -public class WebSocketRequestHandler implements Runnable { - - private WebSocket<SocketChannel> websocket; - private WebSocketOperationDispatcher dispatcher; - - public WebSocketRequestHandler(WebSocket<SocketChannel> socket, WebSocketOperationDispatcher dispatcher) { - this.websocket = socket; - this.dispatcher = dispatcher; - } - - @Override - public void run() { - while (true) { - try { - // TODO use Java NIO selectors on websockets - String request = websocket.receiveText(); - String response = handleRequest(request); - websocket.sendText(response); - } catch (IOException e) { - if (!websocket.isOpen()) { - System.out.println("Client disconnected. Stopping WebSocketRequestHandler."); - break; - } else { - throw new RuntimeException(e); - } - } - } - } - - // TODO handle request asynchronously in a background thread - private String handleRequest(String jsonRequest) { - WebSocketBindingRequest request = JSONUtil.decodeRequest(jsonRequest); - RuntimeEndpoint wire = dispatcher.getEndpoint(request.getUri()); - Operation operation = dispatcher.getOperation(request.getUri()); - System.out.println("handleRequest - " + request.getUri() + " - " + wire + " - " + operation); - String jsonParams = request.getPayload(); - Object[] args = JSONUtil.decodeJsonParamsForOperation(jsonParams, operation); - try { - Object operationResponse = wire.invoke(operation, args); - String payload = JSONUtil.encodeResponse(operationResponse); - WebSocketBindingResponse response = new WebSocketBindingResponse(request.getRequestId(), payload); - return JSONUtil.encodeResponse(response); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } - } - -} diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketServer.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketServer.java new file mode 100644 index 0000000000..e470ddfde0 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebSocketServer.java @@ -0,0 +1,56 @@ +/* + * 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.websocket.runtime; + +import java.net.URISyntaxException; + +import javax.servlet.http.HttpServletRequest; + +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.nio.SelectChannelConnector; +import org.eclipse.jetty.websocket.WebSocket; +import org.eclipse.jetty.websocket.WebSocketHandler; + +public class WebSocketServer extends Server { + + private WebSocketBindingDispatcher dispatcher; + + public WebSocketServer(int port) throws URISyntaxException { + SelectChannelConnector connector = new SelectChannelConnector(); + connector.setPort(port); + addConnector(connector); + + setHandler(new WebSocketHandler() { + + @Override + public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) { + System.out.println("Connection established"); + return new TuscanyWebSocket(dispatcher); + } + }); + + dispatcher = new WebSocketBindingDispatcher(); + } + + public WebSocketBindingDispatcher getDispatcher() { + return dispatcher; + } + +} diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketBindingProviderFactory.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketBindingProviderFactory.java index d7f8ef98a5..1f750234ae 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketBindingProviderFactory.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketBindingProviderFactory.java @@ -21,6 +21,8 @@ package org.apache.tuscany.sca.binding.websocket.runtime; import org.apache.tuscany.sca.binding.websocket.WebsocketBinding;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.host.http.ServletHost;
+import org.apache.tuscany.sca.host.http.ServletHostHelper;
import org.apache.tuscany.sca.provider.BindingProviderFactory;
import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
import org.apache.tuscany.sca.provider.ServiceBindingProvider;
@@ -29,7 +31,10 @@ import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; public class WebsocketBindingProviderFactory implements BindingProviderFactory<WebsocketBinding> {
+ private ServletHost servletHost;
+
public WebsocketBindingProviderFactory(ExtensionPointRegistry extensionPoints) {
+ this.servletHost = ServletHostHelper.getServletHost(extensionPoints);
}
public Class<WebsocketBinding> getModelType() {
@@ -41,7 +46,7 @@ public class WebsocketBindingProviderFactory implements BindingProviderFactory<W }
public ServiceBindingProvider createServiceBindingProvider(RuntimeEndpoint endpoint) {
- return new WebsocketServiceBindingProvider(endpoint);
+ return new WebsocketServiceBindingProvider(endpoint, servletHost);
}
}
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketReferenceBindingProvider.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketReferenceBindingProvider.java index d2e95f9623..4057e46956 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketReferenceBindingProvider.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketReferenceBindingProvider.java @@ -41,7 +41,6 @@ public class WebsocketReferenceBindingProvider implements ReferenceBindingProvid }
public void stop() {
- WebsocketReferenceInvoker.shutdown();
}
public InterfaceContract getBindingInterfaceContract() {
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketReferenceInvoker.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketReferenceInvoker.java index 84025491fe..65c9139a28 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketReferenceInvoker.java +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketReferenceInvoker.java @@ -19,26 +19,13 @@ package org.apache.tuscany.sca.binding.websocket.runtime;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.channels.SocketChannel;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
import org.apache.tuscany.sca.assembly.EndpointReference;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
-import org.apache.websocket.WebSocket;
-import org.apache.websocket.WebSocketConnector;
public class WebsocketReferenceInvoker implements Invoker {
- // TODO add timeout mechanism for persistent connections
- private static ConcurrentMap<String, WebSocket<SocketChannel>> persistentWebsockets = new ConcurrentHashMap<String, WebSocket<SocketChannel>>();
-
protected Operation operation;
protected EndpointReference endpoint;
@@ -48,58 +35,7 @@ public class WebsocketReferenceInvoker implements Invoker { }
public Message invoke(Message msg) {
- try {
- WebSocket<SocketChannel> websocket = initWebsocketConnection(endpoint.getBinding().getURI());
- return doInvoke(msg, websocket);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- private WebSocket<SocketChannel> initWebsocketConnection(String uri) throws IOException, URISyntaxException {
- WebSocket<SocketChannel> websocket = null;
- synchronized (persistentWebsockets) {
- websocket = persistentWebsockets.get(uri);
- if (websocket == null) {
- WebSocketConnector connector = new WebSocketConnector();
- websocket = connector.connect(new URI(uri), null, "apache-tuscany", null);
- persistentWebsockets.put(uri, websocket);
- }
- }
- return websocket;
- }
-
- public Message doInvoke(Message msg, WebSocket<SocketChannel> websocket) throws IOException {
- String componentName = endpoint.getTargetEndpoint().getComponent().getName();
- String serviceName = endpoint.getTargetEndpoint().getService().getName();
- String operationName = operation.getName();
- String uri = componentName + "/" + serviceName + "/" + operationName;
- String payload = JSONUtil.encodeRequestParams((Object[]) msg.getBody());
- WebSocketBindingRequest request = new WebSocketBindingRequest(UUID.randomUUID().toString(), uri, payload);
-
- String operationResponse = invokeViaWebsocket(websocket, JSONUtil.encodeRequest(request));
-
- WebSocketBindingResponse response = JSONUtil.decodeResponse(operationResponse);
- Class<?> returnType = operation.getOutputType().getLogical().get(0).getPhysical();
- Object invocationResponse = JSONUtil.decodeResponsePayload(response.getPayload(), returnType);
- msg.setBody(invocationResponse);
- return msg;
- }
-
- private String invokeViaWebsocket(WebSocket<SocketChannel> websocket, String request) throws IOException {
- websocket.sendText(request);
- return websocket.receiveText();
- }
-
- public static void shutdown() {
- for (WebSocket<SocketChannel> websocket : persistentWebsockets.values()) {
- try {
- websocket.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- persistentWebsockets.clear();
+ throw new RuntimeException("Not implemented yet");
}
}
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 fe5efcffef..7f89a523c3 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 @@ -19,65 +19,75 @@ package org.apache.tuscany.sca.binding.websocket.runtime;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
+import org.apache.tuscany.sca.binding.websocket.WebsocketBinding;
+import org.apache.tuscany.sca.host.http.ServletHost;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.provider.ServiceBindingProvider;
import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
-import org.apache.websocket.ServerWebSocket;
public class WebsocketServiceBindingProvider implements ServiceBindingProvider {
- private static Map<String, WebSocketOperationDispatcher> dispatchers = new HashMap<String, WebSocketOperationDispatcher>();
-
+ private static final String JAVASCRIPT_RESOURCE_PATH = "/org.apache.tuscany.sca.WebsocketComponentContext.js";
+ private static Map<Integer, WebSocketServer> servers = new HashMap<Integer, WebSocketServer>();
private RuntimeEndpoint endpoint;
+ private ServletHost servletHost;
- public WebsocketServiceBindingProvider(RuntimeEndpoint endpoint) {
+ public WebsocketServiceBindingProvider(RuntimeEndpoint endpoint, ServletHost servletHost) {
this.endpoint = endpoint;
+ this.servletHost = servletHost;
}
public void start() {
- String uri = endpoint.getBinding().getURI();
- WebSocketOperationDispatcher dispatcher = initDispatcherForURI(uri);
- String component = endpoint.getComponent().getName();
- String service = endpoint.getService().getName();
- for (Operation op : getBindingInterfaceContract().getInterface().getOperations()) {
- String operation = op.getName();
- dispatcher.addOperation(component + "/" + service + "/" + operation, endpoint, op);
+ WebsocketBinding binding = (WebsocketBinding) endpoint.getBinding();
+ int port = Integer.parseInt(binding.getPort());
+ try {
+ WebSocketServer server = initServerForURI(port);
+ String component = endpoint.getComponent().getName();
+ String service = endpoint.getService().getName();
+ for (Operation op : getBindingInterfaceContract().getInterface().getOperations()) {
+ String operation = op.getName();
+ server.getDispatcher().addOperation(component + "." + service + "." + operation, endpoint, op);
+ }
+ JavascriptGenerator.generateServiceProxy(component, service, getBindingInterfaceContract().getInterface()
+ .getOperations(), port);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
+ initJavascriptResource();
+ }
+ private WebSocketServer initServerForURI(int port) throws Exception {
+ WebSocketServer server = servers.get(port);
+ if (server == null) {
+ server = new WebSocketServer(port);
+ server.start();
+ servers.put(port, server);
+ }
+ return server;
}
- private WebSocketOperationDispatcher initDispatcherForURI(String uri) {
- WebSocketOperationDispatcher dispatcher = dispatchers.get(uri);
- if (dispatcher == null) {
- try {
- ServerWebSocket server = new ServerWebSocket(new URI(uri));
- System.out.println("Starting websocket server " + server + " at " + uri + "...");
- dispatcher = new WebSocketOperationDispatcher(server);
- System.out.println("Created new dispatcher for " + uri + " " + dispatcher);
- dispatchers.put(uri, dispatcher);
- server.register("/", dispatcher);
- new Thread(server).start();
- } catch (IOException e) {
- throw new RuntimeException(e);
- } catch (URISyntaxException e) {
- throw new RuntimeException(e);
- }
+ private void initJavascriptResource() {
+ if (servletHost.getServletMapping(JAVASCRIPT_RESOURCE_PATH) == null) {
+ System.out.println("Adding javascript servlet");
+ servletHost.addServletMapping(JAVASCRIPT_RESOURCE_PATH, new JavascriptResourceServlet());
}
- return dispatcher;
}
public void stop() {
- for (WebSocketOperationDispatcher dispatcher : dispatchers.values()) {
- dispatcher.shutdown();
+ for (WebSocketServer server : servers.values()) {
+ try {
+ server.stop();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
}
- dispatchers.clear();
+ servers.clear();
+ servletHost.removeServletMapping(JAVASCRIPT_RESOURCE_PATH);
+ JavascriptGenerator.clear();
}
public InterfaceContract getBindingInterfaceContract() {
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketServiceInvoker.java b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketServiceInvoker.java new file mode 100644 index 0000000000..7615be916c --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/java/org/apache/tuscany/sca/binding/websocket/runtime/WebsocketServiceInvoker.java @@ -0,0 +1,73 @@ +/*
+ * 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.
+ */
+
+package org.apache.tuscany.sca.binding.websocket.runtime;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+public class WebsocketServiceInvoker {
+
+ protected Operation operation;
+ protected RuntimeEndpoint endpoint;
+
+ public WebsocketServiceInvoker(Operation operation, RuntimeEndpoint endpoint) {
+ this.operation = operation;
+ this.endpoint = endpoint;
+ }
+
+ public WebSocketBindingMessage invokeSync(WebSocketBindingMessage request) {
+ String jsonParams = request.getPayload();
+ Object[] args = JSONUtil.decodePayloadForOperation(jsonParams, operation);
+ try {
+ Object operationResponse = endpoint.invoke(operation, args);
+ String payload = JSONUtil.encodePayload(operationResponse);
+ WebSocketBindingMessage response = new WebSocketBindingMessage(request.getOperation(), payload);
+ return response;
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void invokeAsync(WebSocketBindingMessage request, TuscanyWebSocket channel) {
+ // TODO add multiple response support
+ }
+
+}
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/resources/binding-websocket.xsd b/sca-java-2.x/contrib/modules/binding-websocket/src/main/resources/binding-websocket.xsd index daccffc814..2617865c13 100644 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/main/resources/binding-websocket.xsd +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/resources/binding-websocket.xsd @@ -30,7 +30,7 @@ <complexType name="WebsocketBinding">
<complexContent>
<extension base="sca:Binding">
- <attribute name="someAttr" type="string" use="optional"/>
+ <attribute name="port" type="string" use="required"/>
</extension>
</complexContent>
</complexType>
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/resources/js/TuscanyWebsocketToolkit.js b/sca-java-2.x/contrib/modules/binding-websocket/src/main/resources/js/TuscanyWebsocketToolkit.js new file mode 100644 index 0000000000..501250f3cf --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/resources/js/TuscanyWebsocketToolkit.js @@ -0,0 +1,51 @@ +/* + * 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. + */ + +var channels = []; + +function buildRequest(operation, message) { + return $.toJSON({ + operation: operation, + payload: $.toJSON(message) + }); +} + +function sendMessage(port, operation, message) { + if (!channels[port]) { + ws = new WebSocket("ws://" + window.location.hostname + ":" + port); + channels[port] = ws; + ws.onopen = function() { + $(document).trigger('' + port); + } + ws.onmessage = function (message) { + var response = $.evalJSON(message.data); + eval('Tuscany.WebsocketComponentContext.' + response.operation + '.responseHandler(' + response.payload + ')'); + } + } + + var jsonReq = buildRequest(operation, message); + + if (ws.readyState == WebSocket.CONNECTING) { + $(document).bind('' + port, jsonReq, function(event) { + ws.send(event.data); + }); + } else if (ws.readyState == WebSocket.OPEN) { + ws.send(jsonReq); + } +}
\ No newline at end of file diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/main/resources/js/jquery.json-2.2.min.js b/sca-java-2.x/contrib/modules/binding-websocket/src/main/resources/js/jquery.json-2.2.min.js new file mode 100644 index 0000000000..b176b7ace5 --- /dev/null +++ b/sca-java-2.x/contrib/modules/binding-websocket/src/main/resources/js/jquery.json-2.2.min.js @@ -0,0 +1,45 @@ +/* + * jQuery JSON Plugin + * version: 2.2 (2009-08-14) + * + * This document is licensed as free software under the terms of the + * MIT License: http://www.opensource.org/licenses/mit-license.php + * + * Brantley Harris wrote this plugin. It is based somewhat on the JSON.org + * website's http://www.json.org/json2.js, which proclaims: + * "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that + * I uphold. + * + * It is also influenced heavily by MochiKit's serializeJSON, which is + * copyrighted 2005 by Bob Ippolito. + */ +(function($){$.toJSON=function(o) +{if(typeof(JSON)=='object'&&JSON.stringify) +return JSON.stringify(o);var type=typeof(o);if(o===null) +return"null";if(type=="undefined") +return undefined;if(type=="number"||type=="boolean") +return o+"";if(type=="string") +return $.quoteString(o);if(type=='object') +{if(typeof o.toJSON=="function") +return $.toJSON(o.toJSON());if(o.constructor===Date) +{var month=o.getUTCMonth()+1;if(month<10)month='0'+month;var day=o.getUTCDate();if(day<10)day='0'+day;var year=o.getUTCFullYear();var hours=o.getUTCHours();if(hours<10)hours='0'+hours;var minutes=o.getUTCMinutes();if(minutes<10)minutes='0'+minutes;var seconds=o.getUTCSeconds();if(seconds<10)seconds='0'+seconds;var milli=o.getUTCMilliseconds();if(milli<100)milli='0'+milli;if(milli<10)milli='0'+milli;return'"'+year+'-'+month+'-'+day+'T'+ +hours+':'+minutes+':'+seconds+'.'+milli+'Z"';} +if(o.constructor===Array) +{var ret=[];for(var i=0;i<o.length;i++) +ret.push($.toJSON(o[i])||"null");return"["+ret.join(",")+"]";} +var pairs=[];for(var k in o){var name;var type=typeof k;if(type=="number") +name='"'+k+'"';else if(type=="string") +name=$.quoteString(k);else +continue;if(typeof o[k]=="function") +continue;var val=$.toJSON(o[k]);pairs.push(name+":"+val);} +return"{"+pairs.join(", ")+"}";}};$.evalJSON=function(src) +{if(typeof(JSON)=='object'&&JSON.parse) +return JSON.parse(src);return eval("("+src+")");};$.secureEvalJSON=function(src) +{if(typeof(JSON)=='object'&&JSON.parse) +return JSON.parse(src);var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered)) +return eval("("+src+")");else +throw new SyntaxError("Error parsing JSON, source is not valid.");};$.quoteString=function(string) +{if(string.match(_escapeable)) +{return'"'+string.replace(_escapeable,function(a) +{var c=_meta[a];if(typeof c==='string')return c;c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';} +return'"'+string+'"';};var _escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var _meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};})(jQuery);
\ No newline at end of file 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 deleted file mode 100644 index 149199c55b..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/Address.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 deleted file mode 100644 index 4bc3a5c27e..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/Confirmation.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 deleted file mode 100644 index 8f0ae1b6e9..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/Person.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 deleted file mode 100644 index f9c79778e7..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/RegistrationClient.java +++ /dev/null @@ -1,36 +0,0 @@ -/*
- * 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 deleted file mode 100644 index 3fbe0cac10..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/RegistrationService.java +++ /dev/null @@ -1,30 +0,0 @@ -/*
- * 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 deleted file mode 100644 index b3cefa76da..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/registration/RegistrationServiceImpl.java +++ /dev/null @@ -1,33 +0,0 @@ -/*
- * 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/salutes/CiaoService.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/CiaoService.java deleted file mode 100644 index 145eb5d720..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/CiaoService.java +++ /dev/null @@ -1,28 +0,0 @@ -/*
- * 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 salutes;
-
-import org.oasisopen.sca.annotation.Remotable;
-
-@Remotable
-public interface CiaoService {
-
- String sayCiao(String name);
-
-}
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/CiaoServiceImpl.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/CiaoServiceImpl.java deleted file mode 100644 index 503fc5b51d..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/CiaoServiceImpl.java +++ /dev/null @@ -1,27 +0,0 @@ -/*
- * 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 salutes;
-
-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/salutes/HelloService.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/HelloService.java deleted file mode 100644 index a16ce18a1c..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/HelloService.java +++ /dev/null @@ -1,28 +0,0 @@ -/*
- * 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 salutes;
-
-import org.oasisopen.sca.annotation.Remotable;
-
-@Remotable
-public interface HelloService {
-
- String sayHello(String name);
-
-}
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/HelloServiceImpl.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/HelloServiceImpl.java deleted file mode 100644 index d0b93387f0..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/HelloServiceImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -/*
- * 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 salutes;
-
-
-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/salutes/SalutService.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/SalutService.java deleted file mode 100644 index e1dac86e1c..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/SalutService.java +++ /dev/null @@ -1,28 +0,0 @@ -/*
- * 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 salutes;
-
-import org.oasisopen.sca.annotation.Remotable;
-
-@Remotable
-public interface SalutService {
-
- String saySalut(String name);
-
-}
diff --git a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/SalutServiceImpl.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/SalutServiceImpl.java deleted file mode 100644 index eb9bea7e46..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/salutes/SalutServiceImpl.java +++ /dev/null @@ -1,27 +0,0 @@ -/*
- * 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 salutes;
-
-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 deleted file mode 100644 index d179b18858..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/test/RegistrationWebsocketBindingTestCase.java +++ /dev/null @@ -1,69 +0,0 @@ -/*
- * 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/SalutesWebsocketBindingTestCase.java b/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/test/SalutesWebsocketBindingTestCase.java deleted file mode 100644 index 22d0861c81..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/java/test/SalutesWebsocketBindingTestCase.java +++ /dev/null @@ -1,67 +0,0 @@ -/*
- * 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 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 salutes.CiaoService;
-import salutes.HelloService;
-import salutes.SalutService;
-
-public class SalutesWebsocketBindingTestCase {
-
- private static Node node;
-
- @Test
- public void testHello() {
- HelloService helloClient = node.getService(HelloService.class, "ClientComponent/HelloService");
- Assert.assertEquals("Hello Tuscany", helloClient.sayHello("Tuscany"));
- }
-
- @Test
- public void testSalut() {
- SalutService salutClient = node.getService(SalutService.class, "ClientComponent/SalutService");
- Assert.assertEquals("Salut Tuscany", salutClient.saySalut("Tuscany"));
- }
-
- @Test
- public void testCiao() {
- CiaoService ciaoClient = node.getService(CiaoService.class, "ClientComponent/CiaoService");
- Assert.assertEquals("Ciao Tuscany", ciaoClient.sayCiao("Tuscany"));
- }
-
- @BeforeClass
- public static void init() throws Exception {
- node = NodeFactory.newInstance().createNode("salutes.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/resources/registration.composite b/sca-java-2.x/contrib/modules/binding-websocket/src/test/resources/registration.composite deleted file mode 100644 index 60bbda50ec..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/resources/registration.composite +++ /dev/null @@ -1,37 +0,0 @@ -<?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/salutes.composite b/sca-java-2.x/contrib/modules/binding-websocket/src/test/resources/salutes.composite deleted file mode 100644 index 35126ba267..0000000000 --- a/sca-java-2.x/contrib/modules/binding-websocket/src/test/resources/salutes.composite +++ /dev/null @@ -1,53 +0,0 @@ -<?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="SalutesComposite">
-
- <component name="HelloComponent">
- <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="salutes.SalutServiceImpl"/>
- <service name="SalutService" >
- <tuscany:binding.websocket uri="ws://127.0.0.1:5555" />
- </service>
- </component>
-
- <component name="CiaoComponent">
- <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="salutes.Client"/>
- <reference name="hello" target="HelloComponent/HelloService" />
- <reference name="salut" target="SalutComponent/SalutService" />
- <reference name="ciao" target="CiaoComponent/CiaoService" />
- </component>
-
-</composite>
|