You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by lr...@apache.org on 2007/10/22 10:29:31 UTC
svn commit: r587029 - in /incubator/tuscany/java/sca/modules:
binding-jsonrpc/
binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/
binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/
binding-jsonrpc/src/main...
Author: lresende
Date: Mon Oct 22 01:29:29 2007
New Revision: 587029
URL: http://svn.apache.org/viewvc?rev=587029&view=rev
Log:
Adding support for JSON Databindings and other refactoring
Added:
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java (with props)
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java (with props)
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java (with props)
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory
Removed:
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingActivator.java
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCService.java
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator
Modified:
incubator/tuscany/java/sca/modules/binding-jsonrpc/pom.xml
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.java
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java (contents, props changed)
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java
incubator/tuscany/java/sca/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java (contents, props changed)
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java
incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java
Modified: incubator/tuscany/java/sca/modules/binding-jsonrpc/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/pom.xml?rev=587029&r1=587028&r2=587029&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-jsonrpc/pom.xml (original)
+++ incubator/tuscany/java/sca/modules/binding-jsonrpc/pom.xml Mon Oct 22 01:29:29 2007
@@ -43,47 +43,79 @@
<version>0.8</version>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-extension-helper</artifactId>
+ <artifactId>tuscany-assembly</artifactId>
<version>1.1-incubating-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-implementation-java-runtime</artifactId>
+ <artifactId>tuscany-interface-java</artifactId>
+ <version>1.1-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
<version>1.1-incubating-SNAPSHOT</version>
- <scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-interface-java</artifactId>
+ <artifactId>tuscany-core</artifactId>
<version>1.1-incubating-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding</artifactId>
+ <version>1.1-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding-json</artifactId>
+ <version>1.1-incubating-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-http</artifactId>
<version>1.1-incubating-SNAPSHOT</version>
</dependency>
<dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-host-jetty</artifactId>
+ <version>1.1-incubating-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version> <!-- to keep compatible with older servlet containers -->
<scope>provided</scope>
</dependency>
+
+ <!-- Test Dependencies -->
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-host-jetty</artifactId>
+ <artifactId>tuscany-host-embedded</artifactId>
<version>1.1-incubating-SNAPSHOT</version>
<scope>test</scope>
</dependency>
-
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java-runtime</artifactId>
+ <version>1.1-incubating-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Modified: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java?rev=587029&r1=587028&r2=587029&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java (original)
+++ incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java Mon Oct 22 01:29:29 2007
@@ -19,12 +19,40 @@
package org.apache.tuscany.sca.binding.jsonrpc;
+import org.apache.tuscany.sca.assembly.Binding;
/**
* A model for the JSONRPC binding.
+ *
+ * @version $Rev$ $Date$
*/
-public class JSONRPCBinding {
-
- // empty as right now the json-rpc binding has no attributes
-
+public class JSONRPCBinding implements Binding {
+ private String name;
+ private String uri;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean isUnresolved() {
+ // The binding is always resolved
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ // The binding is always resolved
+ }
+
}
Modified: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.java?rev=587029&r1=587028&r2=587029&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.java (original)
+++ incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.java Mon Oct 22 01:29:29 2007
@@ -24,17 +24,24 @@
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
-import java.text.ParseException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
-import org.json.JSONObject;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONException;
+import org.osoa.sca.ServiceRuntimeException;
import com.metaparadigm.jsonrpc.JSONRPCBridge;
-import com.metaparadigm.jsonrpc.JSONRPCResult;
import com.metaparadigm.jsonrpc.JSONRPCServlet;
/**
@@ -45,12 +52,22 @@
public class JSONRPCServiceServlet extends JSONRPCServlet {
private static final long serialVersionUID = 1L;
+ transient Binding binding;
transient String serviceName;
transient Object serviceInstance;
+ transient RuntimeComponentService componentService;
+ transient InterfaceContract serviceContract;
transient Class<?> serviceInterface;
- public JSONRPCServiceServlet(String serviceName, Class<?> serviceInterface, Object serviceInstance) {
- this.serviceName = serviceName;
+ public JSONRPCServiceServlet(Binding binding,
+ RuntimeComponentService componentService,
+ InterfaceContract serviceContract,
+ Class<?> serviceInterface,
+ Object serviceInstance) {
+ this.binding = binding;
+ this.serviceName = binding.getName();
+ this.componentService = componentService;
+ this.serviceContract = serviceContract;
this.serviceInterface = serviceInterface;
this.serviceInstance = serviceInstance;
}
@@ -65,7 +82,6 @@
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
-
if (request.getParameter("smd") != null) {
handleSMDRequest(request, response);
} else {
@@ -80,17 +96,8 @@
}
}
- private void handleServiceRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
- /*
- * Create a new bridge for every request to aviod all the problems with
- * JSON-RPC-Java storing the bridge in the session
- */
- HttpSession session = request.getSession();
-
- JSONRPCBridge jsonrpcBridge = new JSONRPCBridge();
- jsonrpcBridge.registerObject(serviceName, serviceInstance, serviceInterface);
- session.setAttribute("JSONRPCBridge", jsonrpcBridge);
-
+ private void handleServiceRequest(HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
// Encode using UTF-8, although We are actually ASCII clean as
// all unicode data is JSON escaped using backslash u. This is
// less data efficient for foreign character sets but it is
@@ -118,24 +125,26 @@
data.write(buf, 0, ret);
}
- JSONObject jsonReq = null;
- JSONRPCResult jsonResp = null;
+ org.codehaus.jettison.json.JSONObject jsonReq = null;
+ String method = null;
try {
- jsonReq = new JSONObject(data.toString());
- } catch (ParseException e) {
+ jsonReq = new org.codehaus.jettison.json.JSONObject(data.toString());
+ method = jsonReq.getString("method");
+ } catch (JSONException e) {
throw new RuntimeException("Unable to parse request", e);
}
- String method = jsonReq.getString("method");
- if ((method != null) && (method.indexOf('.') < 0)) {
- jsonReq.putOpt("method", serviceName + "." + method);
+
+ // check if it's a system request
+ // or a method invocation
+ byte[] bout;
+ if (method.startsWith("system.")) {
+ bout = handleJSONRPCSystemInvocation(request, response, data.toString());
+ } else {
+ bout = handleJSONRPCMethodInvocation(request, response, jsonReq);
}
- // invoke the request
- jsonResp = jsonrpcBridge.call(new Object[] {request}, jsonReq);
-
- byte[] bout = jsonResp.toString().getBytes("UTF-8");
-
+ // Send response to client
out.write(bout);
out.flush();
out.close();
@@ -144,7 +153,8 @@
/**
* handles requests for the SMD descriptor for a service
*/
- protected void handleSMDRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, UnsupportedEncodingException {
+ protected void handleSMDRequest(HttpServletRequest request, HttpServletResponse response) throws IOException,
+ UnsupportedEncodingException {
String serviceUrl = request.getRequestURL().toString();
String smd = JavaToSmd.interfaceToSmd(serviceInterface, serviceUrl);
@@ -156,5 +166,112 @@
out.flush();
out.close();
}
+
+ protected byte[] handleJSONRPCSystemInvocation(HttpServletRequest request, HttpServletResponse response, String requestData) throws IOException,
+ UnsupportedEncodingException {
+ /*
+ * Create a new bridge for every request to avoid all the problems with
+ * JSON-RPC-Java storing the bridge in the session
+ */
+ HttpSession session = request.getSession();
+
+ JSONRPCBridge jsonrpcBridge = new JSONRPCBridge();
+ jsonrpcBridge.registerObject(serviceName, serviceInstance, serviceInterface);
+ session.setAttribute("JSONRPCBridge", jsonrpcBridge);
+
+ org.json.JSONObject jsonReq = null;
+ com.metaparadigm.jsonrpc.JSONRPCResult jsonResp = null;
+ try {
+ jsonReq = new org.json.JSONObject(requestData);
+ } catch (java.text.ParseException e) {
+ throw new RuntimeException("Unable to parse request", e);
+ }
+
+ String method = jsonReq.getString("method");
+ if ((method != null) && (method.indexOf('.') < 0)) {
+ jsonReq.putOpt("method", serviceName + "." + method);
+ }
+
+ // invoke the request
+ jsonResp = jsonrpcBridge.call(new Object[] {request}, jsonReq);
+
+ return jsonResp.toString().getBytes("UTF-8");
+ }
+
+ protected byte[] handleJSONRPCMethodInvocation(HttpServletRequest request, HttpServletResponse response, org.codehaus.jettison.json.JSONObject jsonReq) throws IOException,
+ UnsupportedEncodingException {
+
+ String method = null;
+ Object[] args = null;
+ Object id = null;
+ try {
+ // Extract the method
+ method = jsonReq.getString("method");
+ if ((method != null) && (method.indexOf('.') < 0)) {
+ jsonReq.putOpt("method", serviceName + "." + method);
+ }
+
+ // Extract the arguments
+ JSONArray array = jsonReq.getJSONArray("params");
+ args = new Object[array.length()];
+ for (int i = 0; i < args.length; i++) {
+ args[i] = array.get(i);
+ }
+ id = jsonReq.get("id");
+
+ } catch (JSONException e) {
+ throw new RuntimeException("Unable to find json method name", e);
+ }
+
+ // invoke the request
+ RuntimeWire wire = componentService.getRuntimeWire(binding, serviceContract);
+ Operation jsonOperation = findOperation(method);
+ Object result = null;
+ org.codehaus.jettison.json.JSONObject jsonResponse = new org.codehaus.jettison.json.JSONObject();
+ try {
+ result = wire.invoke(jsonOperation, args);
+ try {
+ jsonResponse.put("result", result);
+ jsonResponse.putOpt("id", id);
+ } catch (JSONException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ } catch (InvocationTargetException e) {
+ try {
+ jsonResponse.put("error", e.getCause());
+ jsonResponse.putOpt("id", id);
+ } catch (JSONException e1) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ //get response to send to client
+ return jsonResponse.toString().getBytes("UTF-8");
+ }
+ /**
+ * Find the operation from the component service contract
+ * @param componentService
+ * @param method
+ * @return
+ */
+ private Operation findOperation(String method) {
+ if (method.contains(".")) {
+ method = method.substring(method.lastIndexOf(".") + 1);
+ }
+
+ List<Operation> operations = serviceContract.getInterface().getOperations();
+ //componentService.getBindingProvider(binding).getBindingInterfaceContract().getInterface().getOperations();
+
+
+ Operation result = null;
+ for (Operation o : operations) {
+ if (o.getName().equalsIgnoreCase(method)) {
+ result = o;
+ break;
+ }
+ }
+
+ return result;
+ }
}
Modified: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java?rev=587029&r1=587028&r2=587029&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java (original)
+++ incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java Mon Oct 22 01:29:29 2007
@@ -25,6 +25,8 @@
* from a Java class. See http://dojo.jot.com/SMD.
*
* TODO: Change to work from the Tuscany Interface instead of a Java class
+ *
+ * @version $Rev$ $Date$
*/
public class JavaToSmd {
Propchange: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java?rev=587029&r1=587028&r2=587029&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java (original)
+++ incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java Mon Oct 22 01:29:29 2007
@@ -35,6 +35,8 @@
* This script wrappers the JSON-RPC-Java jsonrpc.js script
* adding in at the bottom the JavaScript to create and initialize
* the variables representing the SCA services.
+ *
+ * @version $Rev$ $Date$
*/
public class ScaDomainScriptServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
Added: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java?rev=587029&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java (added)
+++ incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java Mon Oct 22 01:29:29 2007
@@ -0,0 +1,45 @@
+/*
+ * 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.jsonrpc.provider;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+
+/**
+ * Invoker for the JSONRPC Binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class JSONRPCBindingInvoker implements Invoker {
+ Operation operation;
+ String uri;
+
+ public JSONRPCBindingInvoker(Operation operation, String uri) {
+ this.operation = operation;
+ this.uri = uri;
+ }
+
+ public Message invoke(Message msg) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingInvoker.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java?rev=587029&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java (added)
+++ incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java Mon Oct 22 01:29:29 2007
@@ -0,0 +1,65 @@
+/*
+ * 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.jsonrpc.provider;
+
+import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.host.http.ServletHost;
+import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * JSON-RPC Provider Factory
+ *
+ * @version $Rev$ $Date$
+ */
+public class JSONRPCBindingProviderFactory implements BindingProviderFactory<JSONRPCBinding> {
+
+ private ServletHost servletHost;
+
+ public JSONRPCBindingProviderFactory(ExtensionPointRegistry extensionPoints) {
+ ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class);
+ this.servletHost = servletHosts.getServletHosts().get(0);
+ }
+
+ public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ JSONRPCBinding binding) {
+
+ throw new ServiceRuntimeException("SCA reference support not yet implemented");
+ }
+
+ public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ JSONRPCBinding binding) {
+ return new JSONRPCServiceBindingProvider(component, service, binding, servletHost);
+ }
+
+ public Class<JSONRPCBinding> getModelType() {
+ return JSONRPCBinding.class;
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCBindingProviderFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java?rev=587029&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java (added)
+++ incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java Mon Oct 22 01:29:29 2007
@@ -0,0 +1,191 @@
+/*
+ * 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.jsonrpc.provider;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding;
+import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCServiceServlet;
+import org.apache.tuscany.sca.core.invocation.JDKProxyFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;
+import org.apache.tuscany.sca.databinding.json.JSONDataBinding;
+import org.apache.tuscany.sca.host.http.ServletHost;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * Implementation of the JSONRPC Binding Provider for Services
+ *
+ * @version $Rev$ $Date$
+ */
+public class JSONRPCServiceBindingProvider implements ServiceBindingProvider {
+ private RuntimeComponentService service;
+ private InterfaceContract serviceContract;
+ private JSONRPCBinding binding;
+ private ServletHost servletHost;
+ private String uri;
+
+ public JSONRPCServiceBindingProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ JSONRPCBinding binding,
+ ServletHost servletHost) {
+ this.service = service;
+ this.binding = binding;
+ this.servletHost = servletHost;
+ uri = binding.getURI();
+
+ //clone the service contract to avoid databinding issues
+ try {
+ this.serviceContract = (InterfaceContract)service.getInterfaceContract().clone();
+ } catch(CloneNotSupportedException e) {
+ this.serviceContract = service.getInterfaceContract();
+ }
+
+ setDataBinding(serviceContract.getInterface(), false);
+ }
+
+ public InterfaceContract getBindingInterfaceContract() {
+ return service.getInterfaceContract();
+ }
+
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
+
+ public void start() {
+ RuntimeComponentService componentService = (RuntimeComponentService)service;
+
+ // Set default databinding to json
+ serviceContract.getInterface().setDefaultDataBinding(JSONDataBinding.NAME);
+
+ // Determine the service business interface
+ Class<?> serviceInterface = getTargetJavaClass(serviceContract.getInterface());
+
+ // Create a Java proxy to the target service
+ ProxyFactory proxyFactory = new JDKProxyFactory();
+ Object proxy = proxyFactory.createProxy(serviceInterface, service.getRuntimeWire(binding));
+
+ // Create and register a servlet for this service
+ JSONRPCServiceServlet serviceServlet =
+ new JSONRPCServiceServlet(binding, componentService, serviceContract, serviceInterface, proxy);
+
+ String mapping = uri;
+ if (!mapping.endsWith("/")) {
+ mapping += "/";
+ }
+ if (!mapping.endsWith("*")) {
+ mapping += "*";
+ }
+ servletHost.addServletMapping(mapping, serviceServlet);
+
+ // TODO add support for scaDomain.js
+ // register service to scaDomain.js
+
+ /*
+ * int port; servletHost.addServletMapping(binding.getURI(),
+ * serviceServlet); URI uri = URI.create(binding.getURI()); port =
+ * uri.getPort(); if (port == -1) port = 8080; // get the
+ * ScaDomainScriptServlet, if it doesn't yet exist create one // this
+ * uses removeServletMapping / addServletMapping as theres no
+ * getServletMapping facility URI domainURI =
+ * URI.create("http://localhost:" + port + SCA_DOMAIN_SCRIPT);
+ * ScaDomainScriptServlet scaDomainServlet = (ScaDomainScriptServlet)
+ * servletHost.getServletMapping(domainURI.toString()); if
+ * (scaDomainServlet == null) { scaDomainServlet = new
+ * ScaDomainScriptServlet();
+ * servletHost.addServletMapping(domainURI.toString(),
+ * scaDomainServlet); } // Add this service to the scadomain script
+ * servlet scaDomainServlet.addService(binding.getName());
+ */
+
+ }
+
+ public void stop() {
+ // remove the servlet mapping from servletHost
+ servletHost.removeServletMapping(uri);
+
+ // TODO add support for scaDomain.js
+ // unregister service from scaDomain.js
+
+ /*
+ * // Unregister from the service servlet mapping int port;
+ * servletHost.removeServletMapping(binding.getURI()); URI uri =
+ * URI.create(binding.getURI()); port = uri.getPort(); if (port == -1)
+ * port = 8080; // Unregister the service from the scaDomain script
+ * servlet URI domainURI = URI.create("http://localhost:" + port +
+ * SCA_DOMAIN_SCRIPT); ScaDomainScriptServlet scaDomainServlet =
+ * (ScaDomainScriptServlet)
+ * servletHost.getServletMapping(domainURI.toString()); if
+ * (scaDomainServlet != null) {
+ * scaDomainServlet.removeService(binding.getName()); // Remove the
+ * servlet if there's no more registered services if
+ * (scaDomainServlet.getServiceNames().isEmpty()) {
+ * servletHost.removeServletMapping(domainURI.toString()); } }
+ */
+
+ }
+
+ private Class<?> getTargetJavaClass(Interface targetInterface) {
+ // TODO: right now assume that the target is always a Java
+ // Implementation. Need to figure out how to generate Java
+ // Interface in cases where the target is not a Java Implementation
+ return ((JavaInterface)targetInterface).getJavaClass();
+ }
+
+ private void setDataBinding(Interface interfaze, boolean isReference) {
+ interfaze.setDefaultDataBinding(JSONDataBinding.NAME);
+ List<Operation> operations = interfaze.getOperations();
+ for (Operation operation : operations) {
+ operation.setDataBinding(JSONDataBinding.NAME);
+ DataType<List<DataType>> inputType = operation.getInputType();
+ if (inputType != null) {
+ List<DataType> logical = inputType.getLogical();
+ for (DataType inArg : logical) {
+ if (SimpleJavaDataBinding.NAME.equals(inArg.getDataBinding())) {
+ if (!isReference) {
+ inArg.setDataBinding(JSONDataBinding.NAME);
+ }
+ } else {
+ inArg.setDataBinding(JSONDataBinding.NAME);
+ }
+ }
+ }
+ DataType outputType = operation.getOutputType();
+ if (outputType != null) {
+ if (SimpleJavaDataBinding.NAME.equals(outputType.getDataBinding())) {
+ if (!isReference) {
+ outputType.setDataBinding(JSONDataBinding.NAME);
+ }
+ } else {
+ outputType.setDataBinding(JSONDataBinding.NAME);
+ }
+ }
+ }
+ }
+
+
+}
Propchange: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JSONRPCServiceBindingProvider.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor?rev=587029&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor (added)
+++ incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor Mon Oct 22 01:29:29 2007
@@ -0,0 +1,19 @@
+# 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.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.jsonrpc,model=org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding
Added: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory?rev=587029&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory (added)
+++ incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory Mon Oct 22 01:29:29 2007
@@ -0,0 +1,19 @@
+# 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.
+
+# Implementation class for the binding extension
+org.apache.tuscany.sca.binding.jsonrpc.provider.JSONRPCBindingProviderFactory;model=org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding
Modified: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java?rev=587029&r1=587028&r2=587029&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java Mon Oct 22 01:29:29 2007
@@ -31,7 +31,7 @@
import com.meterware.httpunit.WebResponse;
/**
- * @version $Rev: 536083 $ $Date: 2007-05-08 02:18:29 -0400 (Tue, 08 May 2007) $
+ * @version $Rev$ $Date$
*/
public class JSONRPCServiceTestCase extends TestCase {
Propchange: incubator/tuscany/java/sca/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java?rev=587029&r1=587028&r2=587029&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java (original)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java Mon Oct 22 01:29:29 2007
@@ -68,6 +68,16 @@
ServiceBindingProvider getBindingProvider(Binding binding);
/**
+ * Returns the service binding provider associated with this
+ * component service and the given binding.
+ *
+ * @param binding
+ * @param interfaceContract
+ * @return
+ */
+ RuntimeWire getRuntimeWire(Binding binding, InterfaceContract interfaceContract);
+
+ /**
* Sets the service binding provider associated with this
* component service and the given binding.
*
Modified: incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java?rev=587029&r1=587028&r2=587029&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java (original)
+++ incubator/tuscany/java/sca/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java Mon Oct 22 01:29:29 2007
@@ -56,6 +56,25 @@
return null;
}
+ public RuntimeWire getRuntimeWire(Binding binding, InterfaceContract interfaceContract) {
+ RuntimeWire wire = getRuntimeWire(binding);
+ if (wire == null) {
+ return null;
+ }
+ if (interfaceContract != null && interfaceContract != wire.getSource().getInterfaceContract()) {
+ try {
+ // FIXME: [rfeng] We could avoid clone() using a better comparison of the two interface contracts
+ wire = (RuntimeWire)wire.clone();
+ wire.getSource().setInterfaceContract(interfaceContract);
+ wire.rebuild();
+ } catch (CloneNotSupportedException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ return wire;
+ }
+
public List<RuntimeWire> getCallbackWires() {
return callbackWires;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org