summaryrefslogtreecommitdiffstats
path: root/java/sca/contrib/modules/implementation-web-runtime/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca/contrib/modules/implementation-web-runtime/src')
-rw-r--r--java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ComponentContextServlet.java156
-rw-r--r--java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ContextScriptProcessor.java32
-rw-r--r--java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ContextScriptProcessorExtensionPoint.java27
-rw-r--r--java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/DefaultContextScriptProcessorExtensionPoint.java51
-rw-r--r--java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/JSONRPCScripProcessor.java57
-rw-r--r--java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/ComponentContextProxy.java87
-rw-r--r--java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java78
-rw-r--r--java/sca/contrib/modules/implementation-web-runtime/src/main/resources/META-INF/sca.tld59
-rw-r--r--java/sca/contrib/modules/implementation-web-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.web.ContextScriptProcessorExtensionPoint19
-rw-r--r--java/sca/contrib/modules/implementation-web-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory19
-rw-r--r--java/sca/contrib/modules/implementation-web-runtime/src/main/resources/jsonrpc.js493
11 files changed, 1078 insertions, 0 deletions
diff --git a/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ComponentContextServlet.java b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ComponentContextServlet.java
new file mode 100644
index 0000000000..bf33f7ad9e
--- /dev/null
+++ b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ComponentContextServlet.java
@@ -0,0 +1,156 @@
+/*
+ * 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.implementation.web;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * Servlet that handles the GET request for the componentContext.js script
+ *
+ * The script is generated by calling ScriptProcessors to output the code
+ * for the SCA references, properties etc.
+ */
+public class ComponentContextServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
+ protected static final String HEADER = "/** --- Apache Tuscany componentContext.js --- */\n";
+ protected static final String FOOTER = "/** --- Apache Tuscany componentContext.js EOF --- */\n";
+
+ public static final String COMPONENT_CONTEXT_SCRIPT_URI = "org.apache.tuscany.sca.componentContext.js";
+
+ protected transient Map<String, Object> attributes = new HashMap<String, Object>();
+ protected transient ServletContext servletContext;
+ private transient List<ContextScriptProcessor> contextScriptProcessors = new ArrayList<ContextScriptProcessor>();
+
+ public ComponentContextServlet() {
+ contextScriptProcessors.add(new JSONRPCScripProcessor());
+ }
+
+ @Override
+ public void init(ServletConfig servletConfig) throws ServletException {
+ this.servletContext = servletConfig.getServletContext();
+ if (attributes.size() > 0) {
+ for (String name : attributes.keySet()) {
+ servletContext.setAttribute(name, attributes.get(name));
+ }
+ }
+ }
+
+ @Override
+ public void doGet(HttpServletRequest req, HttpServletResponse response) throws IOException {
+ response.setContentType("text/plain;charset=utf-8");
+ PrintWriter out = response.getWriter();
+
+ out.write(HEADER);
+
+ doScriptInit(req, response);
+
+ doScriptReferences(req, response);
+
+ out.write(FOOTER);
+
+ out.flush();
+ out.close();
+ }
+
+ /**
+ * Calls each ContextScriptProcessor once to insert any required initilization code into componentContext.js
+ */
+ protected void doScriptInit(HttpServletRequest req, HttpServletResponse response) throws IOException, UnsupportedEncodingException {
+
+ PrintWriter out = response.getWriter();
+
+ out.println("if (SCA == undefined) var SCA = new Object();");
+ out.println("if (SCA.componentContext == undefined) {");
+ out.println(" SCA.componentContext = new Object();");
+ out.println(" SCA.componentContext.serviceNames = [];");
+ out.println(" SCA.componentContext.serviceProxys = [];");
+ out.println(" SCA.componentContext.getService = function(serviceName){");
+ out.println(" var i = SCA.componentContext.serviceNames.indexOf(serviceName);");
+ out.println(" return SCA.componentContext.serviceProxys[i];");
+ out.println(" };");
+ out.println(" if (componentContext == undefined) var componentContext = SCA.componentContext;");
+ out.println("}");
+
+ for (ContextScriptProcessor csp : contextScriptProcessors) {
+ csp.scriptInit(req, response);
+ }
+ }
+
+ /**
+ * Calls each ContextScriptProcessor for each SCA reference to insert code for the reference into componentContext.js
+ */
+ protected void doScriptReferences(HttpServletRequest req, HttpServletResponse response) throws IOException, UnsupportedEncodingException {
+
+ PrintWriter out = response.getWriter();
+
+ out.write("// SCA References\n");
+
+ RuntimeComponent component = (RuntimeComponent)servletContext.getAttribute("org.apache.tuscany.sca.implementation.web.RuntimeComponent");
+
+ for (ComponentReference cr : component.getReferences()) {
+ String ref = "// SCA Reference " + cr.getName() + "\n";
+ out.write(ref);
+ for (ContextScriptProcessor csp : contextScriptProcessors) {
+ csp.scriptReference(cr, req, response);
+ }
+ }
+
+ out.write("\n// SCA References end.\n");
+ }
+
+ /**
+ * Calls each ContextScriptProcessor for each SCA property to insert code for the property into componentContext.js
+ */
+ protected void doScriptProperties(HttpServletRequest req, HttpServletResponse response) throws IOException, UnsupportedEncodingException {
+ // TODO: support properties
+ }
+
+ /**
+ * Set an attribute on the ServletContext
+ */
+ public void setAttribute(String name, Object value) {
+ if (servletContext != null) {
+ servletContext.setAttribute(name, value);
+ } else {
+ attributes.put(name, value);
+ }
+ }
+
+ public void addContextScriptProcessor(ContextScriptProcessor csp) {
+ contextScriptProcessors.add(csp);
+ }
+}
diff --git a/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ContextScriptProcessor.java b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ContextScriptProcessor.java
new file mode 100644
index 0000000000..02c99debb0
--- /dev/null
+++ b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ContextScriptProcessor.java
@@ -0,0 +1,32 @@
+/*
+ * 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.implementation.web;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.sca.assembly.ComponentReference;
+
+public interface ContextScriptProcessor {
+ void scriptInit(HttpServletRequest req, HttpServletResponse response) throws IOException;
+ void scriptReference(ComponentReference cr, HttpServletRequest req, HttpServletResponse response) throws IOException;
+}
diff --git a/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ContextScriptProcessorExtensionPoint.java b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ContextScriptProcessorExtensionPoint.java
new file mode 100644
index 0000000000..6d3f590309
--- /dev/null
+++ b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/ContextScriptProcessorExtensionPoint.java
@@ -0,0 +1,27 @@
+/*
+ * 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.implementation.web;
+
+
+public interface ContextScriptProcessorExtensionPoint {
+
+ void addContextScriptProcessor(ContextScriptProcessor csp);
+
+}
diff --git a/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/DefaultContextScriptProcessorExtensionPoint.java b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/DefaultContextScriptProcessorExtensionPoint.java
new file mode 100644
index 0000000000..89b951e7d2
--- /dev/null
+++ b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/DefaultContextScriptProcessorExtensionPoint.java
@@ -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.
+ */
+
+package org.apache.tuscany.sca.implementation.web;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class DefaultContextScriptProcessorExtensionPoint implements ContextScriptProcessorExtensionPoint {
+
+ protected ComponentContextServlet componentContextServlet;
+ protected List<ContextScriptProcessor> tempCSPHolder = new ArrayList<ContextScriptProcessor>();
+
+ public DefaultContextScriptProcessorExtensionPoint() {
+ }
+
+ public void addContextScriptProcessor(ContextScriptProcessor csp) {
+ if (componentContextServlet != null) {
+ componentContextServlet.addContextScriptProcessor(csp);
+ } else {
+ tempCSPHolder.add(csp);
+ }
+ }
+
+ public void setComponentContextServlet(ComponentContextServlet servlet) {
+ componentContextServlet = servlet;
+ if (tempCSPHolder.size() > 0) {
+ for (ContextScriptProcessor csp : tempCSPHolder) {
+ componentContextServlet.addContextScriptProcessor(csp);
+ }
+ }
+ }
+
+}
diff --git a/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/JSONRPCScripProcessor.java b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/JSONRPCScripProcessor.java
new file mode 100644
index 0000000000..e4ec0d71f9
--- /dev/null
+++ b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/JSONRPCScripProcessor.java
@@ -0,0 +1,57 @@
+/*
+ * 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.implementation.web;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+
+public class JSONRPCScripProcessor implements ContextScriptProcessor {
+
+ public void scriptInit(HttpServletRequest req, HttpServletResponse response) throws IOException {
+ PrintWriter out = response.getWriter();
+ InputStream is = getClass().getClassLoader().getResourceAsStream("jsonrpc.js");
+ if (is != null) {
+ int i;
+ while ((i = is.read()) != -1) {
+ out.write(i);
+ }
+ }
+
+ out.println();
+ }
+
+ public void scriptReference(ComponentReference cr, HttpServletRequest req, HttpServletResponse response) throws IOException {
+ for (Binding b : cr.getBindings()) {
+ if ("org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding".equals(b.getClass().getName())) {
+ PrintWriter out = response.getWriter();
+ out.println("SCA.componentContext.serviceNames.push('" + cr.getName() + "');");
+ out.println("SCA.componentContext.serviceProxys.push(new JSONRpcClient('" + cr.getReference().getTargets().get(0).getName() + "').Service);");
+ }
+ }
+ }
+
+}
diff --git a/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/ComponentContextProxy.java b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/ComponentContextProxy.java
new file mode 100644
index 0000000000..dba3f62d35
--- /dev/null
+++ b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/ComponentContextProxy.java
@@ -0,0 +1,87 @@
+/*
+ * 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.implementation.web.runtime;
+
+import java.util.Collection;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * Proxy ComponentContext wrappering a RuntimeComponent as the
+ * RuntimeComponent ComponentContext has not been created till later
+ */
+public class ComponentContextProxy implements ComponentContext {
+
+ protected RuntimeComponent runtimeComponent;
+
+ public ComponentContextProxy(RuntimeComponent runtimeComponent) {
+ this.runtimeComponent = runtimeComponent;
+ }
+
+ protected ComponentContext getComponentContext() {
+ return runtimeComponent.getComponentContext();
+ }
+
+ @SuppressWarnings("unchecked")
+ public <B, R extends CallableReference<B>> R cast(B arg0) throws IllegalArgumentException {
+ return (R) getComponentContext().cast(arg0);
+ }
+
+ public <B> ServiceReference<B> createSelfReference(Class<B> arg0) {
+ return getComponentContext().createSelfReference(arg0);
+ }
+
+ public <B> ServiceReference<B> createSelfReference(Class<B> arg0, String arg1) {
+ return getComponentContext().createSelfReference(arg0, arg1);
+ }
+
+ public <B> B getProperty(Class<B> arg0, String arg1) {
+ return getComponentContext().getProperty(arg0, arg1);
+ }
+
+ public RequestContext getRequestContext() {
+ return getComponentContext().getRequestContext();
+ }
+
+ public <B> B getService(Class<B> arg0, String arg1) {
+ return getComponentContext().getService(arg0, arg1);
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B> arg0, String arg1) {
+ return getComponentContext().getServiceReference(arg0, arg1);
+ }
+
+ public String getURI() {
+ return getComponentContext().getURI();
+ }
+
+ public <B> Collection<ServiceReference<B>> getServiceReferences(Class<B> businessInterface, String referenceName) {
+ return getComponentContext().getServiceReferences(businessInterface, referenceName);
+ }
+
+ public <B> Collection<B> getServices(Class<B> businessInterface, String referenceName) {
+ return getComponentContext().getServices(businessInterface, referenceName);
+ }
+
+}
diff --git a/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java
new file mode 100644
index 0000000000..2518ba5381
--- /dev/null
+++ b/java/sca/contrib/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/WebImplementationProviderFactory.java
@@ -0,0 +1,78 @@
+/*
+ * 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.implementation.web.runtime;
+
+import java.util.List;
+
+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.implementation.web.ComponentContextServlet;
+import org.apache.tuscany.sca.implementation.web.ContextScriptProcessorExtensionPoint;
+import org.apache.tuscany.sca.implementation.web.DefaultContextScriptProcessorExtensionPoint;
+import org.apache.tuscany.sca.implementation.web.WebImplementation;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+public class WebImplementationProviderFactory implements ImplementationProviderFactory<WebImplementation> {
+
+ private ServletHost servletHost;
+ private ComponentContextServlet contextServlet;
+
+ public WebImplementationProviderFactory(ExtensionPointRegistry extensionPoints) {
+ ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class);
+ List<ServletHost> hosts = servletHosts.getServletHosts();
+ if (!hosts.isEmpty()) {
+ this.servletHost = hosts.get(0);
+ }
+
+ contextServlet = new ComponentContextServlet();
+
+ DefaultContextScriptProcessorExtensionPoint dcspep = (DefaultContextScriptProcessorExtensionPoint)extensionPoints.getExtensionPoint(ContextScriptProcessorExtensionPoint.class);
+ dcspep.setComponentContextServlet(contextServlet);
+ }
+
+ public ImplementationProvider createImplementationProvider(RuntimeComponent component, WebImplementation implementation) {
+
+ servletHost.addServletMapping("org.osoa.sca.componentContext.js", contextServlet);
+ contextServlet.setAttribute("org.osoa.sca.ComponentContext", new ComponentContextProxy(component));
+ contextServlet.setAttribute("org.apache.tuscany.sca.implementation.web.RuntimeComponent", component);
+
+ return new ImplementationProvider() {
+ public Invoker createInvoker(RuntimeComponentService arg0, Operation arg1) {
+ throw new UnsupportedOperationException("Components using implementation.web have no services");
+ }
+ public void start() {
+ }
+ public void stop() {
+ }
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
+ };
+ }
+
+ public Class<WebImplementation> getModelType() {
+ return WebImplementation.class;
+ }
+
+}
diff --git a/java/sca/contrib/modules/implementation-web-runtime/src/main/resources/META-INF/sca.tld b/java/sca/contrib/modules/implementation-web-runtime/src/main/resources/META-INF/sca.tld
new file mode 100644
index 0000000000..4807ba517a
--- /dev/null
+++ b/java/sca/contrib/modules/implementation-web-runtime/src/main/resources/META-INF/sca.tld
@@ -0,0 +1,59 @@
+<?xml version = '1.0' encoding = 'ISO-8859-1'?>
+<!--
+ * 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.
+ -->
+
+<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">
+
+<taglib version="2.1">
+
+ <tlib-version>1.0</tlib-version>
+ <short-name>SCA-JSP</short-name>
+ <uri>http://www.osog.org/sca/sca.tld</uri>
+ <description>A tag library for integrating sca components with jsp</description>
+
+ <tag>
+
+ <name>reference</name>
+
+ <tag-class>org.apache.tuscany.sca.implementation.web.taglib.ReferenceTag</tag-class>
+ <tei-class>org.apache.tuscany.sca.implementation.web.taglib.ReferenceTEI</tei-class>
+
+ <attribute>
+ <name>name</name>
+ <required>true</required>
+ <type>java.lang.String</type>
+ </attribute>
+
+ <attribute>
+ <name>type</name>
+ <required>true</required>
+ <type>java.lang.String</type>
+ </attribute>
+
+ <attribute>
+ <name>scope</name>
+ <required>false</required>
+ <type>java.lang.Integer</type>
+ </attribute>
+
+ <body-content>empty</body-content>
+
+ </tag>
+
+</taglib>
diff --git a/java/sca/contrib/modules/implementation-web-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.web.ContextScriptProcessorExtensionPoint b/java/sca/contrib/modules/implementation-web-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.web.ContextScriptProcessorExtensionPoint
new file mode 100644
index 0000000000..960ae30552
--- /dev/null
+++ b/java/sca/contrib/modules/implementation-web-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.web.ContextScriptProcessorExtensionPoint
@@ -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 ModuleActivator
+org.apache.tuscany.sca.implementation.web.DefaultContextScriptProcessorExtensionPoint
+
diff --git a/java/sca/contrib/modules/implementation-web-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/java/sca/contrib/modules/implementation-web-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
new file mode 100644
index 0000000000..9b769c9b10
--- /dev/null
+++ b/java/sca/contrib/modules/implementation-web-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
@@ -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 implementation extension
+org.apache.tuscany.sca.implementation.web.runtime.WebImplementationProviderFactory;model=org.apache.tuscany.sca.implementation.web.WebImplementation
diff --git a/java/sca/contrib/modules/implementation-web-runtime/src/main/resources/jsonrpc.js b/java/sca/contrib/modules/implementation-web-runtime/src/main/resources/jsonrpc.js
new file mode 100644
index 0000000000..8eb477c2e5
--- /dev/null
+++ b/java/sca/contrib/modules/implementation-web-runtime/src/main/resources/jsonrpc.js
@@ -0,0 +1,493 @@
+/*
+ * JSON-RPC JavaScript client
+ *
+ * $Id: jsonrpc.js,v 1.36.2.3 2006/03/08 15:09:37 mclark Exp $
+ *
+ * Copyright (c) 2003-2004 Jan-Klaas Kollhof
+ * Copyright (c) 2005 Michael Clark, Metaparadigm Pte Ltd
+ *
+ * This code is based on Jan-Klaas' JavaScript o lait library (jsolait).
+ *
+ * Licensed 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.
+ *
+ */
+
+/*
+ * Modifications for Apache Tuscany:
+ * - JSONRpcClient_createMethod changed so callback is last arg
+ */
+
+/* escape a character */
+
+escapeJSONChar =
+function escapeJSONChar(c)
+{
+ if(c == "\"" || c == "\\") return "\\" + c;
+ else if (c == "\b") return "\\b";
+ else if (c == "\f") return "\\f";
+ else if (c == "\n") return "\\n";
+ else if (c == "\r") return "\\r";
+ else if (c == "\t") return "\\t";
+ var hex = c.charCodeAt(0).toString(16);
+ if(hex.length == 1) return "\\u000" + hex;
+ else if(hex.length == 2) return "\\u00" + hex;
+ else if(hex.length == 3) return "\\u0" + hex;
+ else return "\\u" + hex;
+};
+
+
+/* encode a string into JSON format */
+
+escapeJSONString =
+function escapeJSONString(s)
+{
+ /* The following should suffice but Safari's regex is b0rken
+ (doesn't support callback substitutions)
+ return "\"" + s.replace(/([^\u0020-\u007f]|[\\\"])/g,
+ escapeJSONChar) + "\"";
+ */
+
+ /* Rather inefficient way to do it */
+ var parts = s.split("");
+ for(var i=0; i < parts.length; i++) {
+ var c =parts[i];
+ if(c == '"' ||
+ c == '\\' ||
+ c.charCodeAt(0) < 32 ||
+ c.charCodeAt(0) >= 128)
+ parts[i] = escapeJSONChar(parts[i]);
+ }
+ return "\"" + parts.join("") + "\"";
+};
+
+
+/* Marshall objects to JSON format */
+
+toJSON = function toJSON(o)
+{
+ if(o == null) {
+ return "null";
+ } else if(o.constructor == String) {
+ return escapeJSONString(o);
+ } else if(o.constructor == Number) {
+ return o.toString();
+ } else if(o.constructor == Boolean) {
+ return o.toString();
+ } else if(o.constructor == Date) {
+ return '{javaClass: "java.util.Date", time: ' + o.valueOf() +'}';
+ } else if(o.constructor == Array) {
+ var v = [];
+ for(var i = 0; i < o.length; i++) v.push(toJSON(o[i]));
+ return "[" + v.join(", ") + "]";
+ } else {
+ var v = [];
+ for(attr in o) {
+ if(o[attr] == null) v.push("\"" + attr + "\": null");
+ else if(typeof o[attr] == "function"); /* skip */
+ else v.push(escapeJSONString(attr) + ": " + toJSON(o[attr]));
+ }
+ return "{" + v.join(", ") + "}";
+ }
+};
+
+
+/* JSONRpcClient constructor */
+
+JSONRpcClient =
+function JSONRpcClient_ctor(serverURL, user, pass, objectID)
+{
+ this.serverURL = serverURL;
+ this.user = user;
+ this.pass = pass;
+ this.objectID = objectID;
+
+ /* Add standard methods */
+ if(this.objectID) {
+ this._addMethods(["listMethods"]);
+ var req = this._makeRequest("listMethods", []);
+ } else {
+ this._addMethods(["system.listMethods"]);
+ var req = this._makeRequest("system.listMethods", []);
+ }
+ var m = this._sendRequest(req);
+ this._addMethods(m);
+};
+
+
+/* JSONRpcCLient.Exception */
+
+JSONRpcClient.Exception =
+function JSONRpcClient_Exception_ctor(code, message, javaStack)
+{
+ this.code = code;
+ var name;
+ if(javaStack) {
+ this.javaStack = javaStack;
+ var m = javaStack.match(/^([^:]*)/);
+ if(m) name = m[0];
+ }
+ if(name) this.name = name;
+ else this.name = "JSONRpcClientException";
+ this.message = message;
+};
+
+JSONRpcClient.Exception.CODE_REMOTE_EXCEPTION = 490;
+JSONRpcClient.Exception.CODE_ERR_CLIENT = 550;
+JSONRpcClient.Exception.CODE_ERR_PARSE = 590;
+JSONRpcClient.Exception.CODE_ERR_NOMETHOD = 591;
+JSONRpcClient.Exception.CODE_ERR_UNMARSHALL = 592;
+JSONRpcClient.Exception.CODE_ERR_MARSHALL = 593;
+
+JSONRpcClient.Exception.prototype = new Error();
+
+JSONRpcClient.Exception.prototype.toString =
+function JSONRpcClient_Exception_toString(code, msg)
+{
+ return this.name + ": " + this.message;
+};
+
+
+/* Default top level exception handler */
+
+JSONRpcClient.default_ex_handler =
+function JSONRpcClient_default_ex_handler(e) { alert(e); };
+
+
+/* Client settable variables */
+
+JSONRpcClient.toplevel_ex_handler = JSONRpcClient.default_ex_handler;
+JSONRpcClient.profile_async = false;
+JSONRpcClient.max_req_active = 1;
+JSONRpcClient.requestId = 1;
+
+
+/* JSONRpcClient implementation */
+
+JSONRpcClient.prototype._createMethod =
+function JSONRpcClient_createMethod(methodName)
+{
+ var fn=function()
+ {
+ var args = [];
+ var callback = null;
+ for(var i=0;i<arguments.length;i++) args.push(arguments[i]);
+
+/* TUSCANY change callback to be last arg instead of first to match binding.ajax
+ if(typeof args[0] == "function") callback = args.shift();
+*/
+ if(typeof args[arguments.length-1] == "function") callback = args.pop();
+
+ var req = fn.client._makeRequest.call(fn.client, fn.methodName,
+ args, callback);
+ if(callback == null) {
+ return fn.client._sendRequest.call(fn.client, req);
+ } else {
+ JSONRpcClient.async_requests.push(req);
+ JSONRpcClient.kick_async();
+ return req.requestId;
+ }
+ };
+ fn.client = this;
+ fn.methodName = methodName;
+ return fn;
+};
+
+JSONRpcClient.prototype._addMethods =
+function JSONRpcClient_addMethods(methodNames)
+{
+ for(var i=0; i<methodNames.length; i++) {
+ var obj = this;
+ var names = methodNames[i].split(".");
+ for(var n=0; n<names.length-1; n++) {
+ var name = names[n];
+ if(obj[name]) {
+ obj = obj[name];
+ } else {
+ obj[name] = new Object();
+ obj = obj[name];
+ }
+ }
+ var name = names[names.length-1];
+ if(!obj[name]) {
+ var method = this._createMethod(methodNames[i]);
+ obj[name] = method;
+ }
+ }
+};
+
+JSONRpcClient._getCharsetFromHeaders =
+function JSONRpcClient_getCharsetFromHeaders(http)
+{
+ try {
+ var contentType = http.getResponseHeader("Content-type");
+ var parts = contentType.split(/\s*;\s*/);
+ for(var i =0; i < parts.length; i++) {
+ if(parts[i].substring(0, 8) == "charset=")
+ return parts[i].substring(8, parts[i].length);
+ }
+ } catch (e) {}
+ return "UTF-8"; /* default */
+};
+
+/* Async queue globals */
+JSONRpcClient.async_requests = [];
+JSONRpcClient.async_inflight = {};
+JSONRpcClient.async_responses = [];
+JSONRpcClient.async_timeout = null;
+JSONRpcClient.num_req_active = 0;
+
+JSONRpcClient._async_handler =
+function JSONRpcClient_async_handler()
+{
+ JSONRpcClient.async_timeout = null;
+
+ while(JSONRpcClient.async_responses.length > 0) {
+ var res = JSONRpcClient.async_responses.shift();
+ if(res.canceled) continue;
+ if(res.profile) res.profile.dispatch = new Date();
+ try {
+ res.cb(res.result, res.ex, res.profile);
+ } catch(e) {
+ JSONRpcClient.toplevel_ex_handler(e);
+ }
+ }
+
+ while(JSONRpcClient.async_requests.length > 0 &&
+ JSONRpcClient.num_req_active < JSONRpcClient.max_req_active) {
+ var req = JSONRpcClient.async_requests.shift();
+ if(req.canceled) continue;
+ req.client._sendRequest.call(req.client, req);
+ }
+};
+
+JSONRpcClient.kick_async =
+function JSONRpcClient_kick_async()
+{
+ if(JSONRpcClient.async_timeout == null)
+ JSONRpcClient.async_timeout =
+ setTimeout(JSONRpcClient._async_handler, 0);
+};
+
+JSONRpcClient.cancelRequest =
+function JSONRpcClient_cancelRequest(requestId)
+{
+ /* If it is in flight then mark it as canceled in the inflight map
+ and the XMLHttpRequest callback will discard the reply. */
+ if(JSONRpcClient.async_inflight[requestId]) {
+ JSONRpcClient.async_inflight[requestId].canceled = true;
+ return true;
+ }
+
+ /* If its not in flight yet then we can just mark it as canceled in
+ the the request queue and it will get discarded before being sent. */
+ for(var i in JSONRpcClient.async_requests) {
+ if(JSONRpcClient.async_requests[i].requestId == requestId) {
+ JSONRpcClient.async_requests[i].canceled = true;
+ return true;
+ }
+ }
+
+ /* It may have returned from the network and be waiting for its callback
+ to be dispatched, so mark it as canceled in the response queue
+ and the response will get discarded before calling the callback. */
+ for(var i in JSONRpcClient.async_responses) {
+ if(JSONRpcClient.async_responses[i].requestId == requestId) {
+ JSONRpcClient.async_responses[i].canceled = true;
+ return true;
+ }
+ }
+
+ return false;
+};
+
+JSONRpcClient.prototype._makeRequest =
+function JSONRpcClient_makeRequest(methodName, args, cb)
+{
+ var req = {};
+ req.client = this;
+ req.requestId = JSONRpcClient.requestId++;
+
+ var obj = {};
+ obj.id = req.requestId;
+ if (this.objectID)
+ obj.method = ".obj#" + this.objectID + "." + methodName;
+ else
+ obj.method = methodName;
+ obj.params = args;
+
+ if (cb) req.cb = cb;
+ if (JSONRpcClient.profile_async)
+ req.profile = { "submit": new Date() };
+ req.data = toJSON(obj);
+
+ return req;
+};
+
+JSONRpcClient.prototype._sendRequest =
+function JSONRpcClient_sendRequest(req)
+{
+ if(req.profile) req.profile.start = new Date();
+
+ /* Get free http object from the pool */
+ var http = JSONRpcClient.poolGetHTTPRequest();
+ JSONRpcClient.num_req_active++;
+
+ /* Send the request */
+ if (typeof(this.user) == "undefined") {
+ http.open("POST", this.serverURL, (req.cb != null));
+ } else {
+ http.open("POST", this.serverURL, (req.cb != null), this.user, this.pass);
+ }
+
+ /* setRequestHeader is missing in Opera 8 Beta */
+ try { http.setRequestHeader("Content-type", "text/plain"); } catch(e) {}
+
+ /* Construct call back if we have one */
+ if(req.cb) {
+ var self = this;
+ http.onreadystatechange = function() {
+ if(http.readyState == 4) {
+ http.onreadystatechange = function () {};
+ var res = { "cb": req.cb, "result": null, "ex": null};
+ if (req.profile) {
+ res.profile = req.profile;
+ res.profile.end = new Date();
+ }
+ try { res.result = self._handleResponse(http); }
+ catch(e) { res.ex = e; }
+ if(!JSONRpcClient.async_inflight[req.requestId].canceled)
+ JSONRpcClient.async_responses.push(res);
+ delete JSONRpcClient.async_inflight[req.requestId];
+ JSONRpcClient.kick_async();
+ }
+ };
+ } else {
+ http.onreadystatechange = function() {};
+ }
+
+ JSONRpcClient.async_inflight[req.requestId] = req;
+
+ try {
+ http.send(req.data);
+ } catch(e) {
+ JSONRpcClient.poolReturnHTTPRequest(http);
+ JSONRpcClient.num_req_active--;
+ throw new JSONRpcClient.Exception
+ (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed");
+ }
+
+ if(!req.cb) return this._handleResponse(http);
+};
+
+JSONRpcClient.prototype._handleResponse =
+function JSONRpcClient_handleResponse(http)
+{
+ /* Get the charset */
+ if(!this.charset) {
+ this.charset = JSONRpcClient._getCharsetFromHeaders(http);
+ }
+
+ /* Get request results */
+ var status, statusText, data;
+ try {
+ status = http.status;
+ statusText = http.statusText;
+ data = http.responseText;
+ } catch(e) {
+ JSONRpcClient.poolReturnHTTPRequest(http);
+ JSONRpcClient.num_req_active--;
+ JSONRpcClient.kick_async();
+ throw new JSONRpcClient.Exception
+ (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed");
+ }
+
+ /* Return http object to the pool; */
+ JSONRpcClient.poolReturnHTTPRequest(http);
+ JSONRpcClient.num_req_active--;
+
+ /* Unmarshall the response */
+ if(status != 200) {
+ throw new JSONRpcClient.Exception(status, statusText);
+ }
+ var obj;
+ try {
+ eval("obj = " + data);
+ } catch(e) {
+ throw new JSONRpcClient.Exception(550, "error parsing result");
+ }
+ if(obj.error)
+ throw new JSONRpcClient.Exception(obj.error.code, obj.error.msg,
+ obj.error.trace);
+ var res = obj.result;
+
+ /* Handle CallableProxy */
+ if(res && res.objectID && res.JSONRPCType == "CallableReference")
+ return new JSONRpcClient(this.serverURL, this.user,
+ this.pass, res.objectID);
+
+ return res;
+};
+
+
+/* XMLHttpRequest wrapper code */
+
+/* XMLHttpRequest pool globals */
+JSONRpcClient.http_spare = [];
+JSONRpcClient.http_max_spare = 8;
+
+JSONRpcClient.poolGetHTTPRequest =
+function JSONRpcClient_pool_getHTTPRequest()
+{
+ if(JSONRpcClient.http_spare.length > 0) {
+ return JSONRpcClient.http_spare.pop();
+ }
+ return JSONRpcClient.getHTTPRequest();
+};
+
+JSONRpcClient.poolReturnHTTPRequest =
+function JSONRpcClient_poolReturnHTTPRequest(http)
+{
+ if(JSONRpcClient.http_spare.length >= JSONRpcClient.http_max_spare)
+ delete http;
+ else
+ JSONRpcClient.http_spare.push(http);
+};
+
+JSONRpcClient.msxmlNames = [ "MSXML2.XMLHTTP.5.0",
+ "MSXML2.XMLHTTP.4.0",
+ "MSXML2.XMLHTTP.3.0",
+ "MSXML2.XMLHTTP",
+ "Microsoft.XMLHTTP" ];
+
+JSONRpcClient.getHTTPRequest =
+function JSONRpcClient_getHTTPRequest()
+{
+ /* Mozilla XMLHttpRequest */
+ try {
+ JSONRpcClient.httpObjectName = "XMLHttpRequest";
+ return new XMLHttpRequest();
+ } catch(e) {}
+
+ /* Microsoft MSXML ActiveX */
+ for (var i=0;i < JSONRpcClient.msxmlNames.length; i++) {
+ try {
+ JSONRpcClient.httpObjectName = JSONRpcClient.msxmlNames[i];
+ return new ActiveXObject(JSONRpcClient.msxmlNames[i]);
+ } catch (e) {}
+ }
+
+ /* None found */
+ JSONRpcClient.httpObjectName = null;
+ throw new JSONRpcClient.Exception(0, "Can't create XMLHttpRequest object");
+};
+