diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-21 07:03:47 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-21 07:03:47 +0000 |
commit | ab6904bc2f622129bc548391745b08eb0c219e57 (patch) | |
tree | 5c7599119182bfa8e65c0d6605e933396aedffd2 /java/sca/modules/binding-jsonp-runtime | |
parent | 8d70ef6d556ad29b93d5d40e91c4c9304638c9e9 (diff) |
Fix svn:eol-style and svn:keywords properties for java/xml files
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@796166 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/binding-jsonp-runtime')
8 files changed, 478 insertions, 478 deletions
diff --git a/java/sca/modules/binding-jsonp-runtime/pom.xml b/java/sca/modules/binding-jsonp-runtime/pom.xml index 503ebadd1a..7906a2d4c3 100644 --- a/java/sca/modules/binding-jsonp-runtime/pom.xml +++ b/java/sca/modules/binding-jsonp-runtime/pom.xml @@ -1,85 +1,85 @@ -<?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.
--->
-<project>
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-modules</artifactId>
- <version>2.0-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
- <artifactId>tuscany-binding-jsonp-runtime</artifactId>
- <name>Apache Tuscany SCA JSONP Binding Runtime</name>
-
- <dependencies>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-binding-jsonp</artifactId>
- <version>2.0-SNAPSHOT</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-host-http</artifactId>
- <version>2.0-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-core-asl</artifactId>
- <version>1.0.1</version>
- </dependency>
- <dependency>
- <groupId>org.codehaus.jackson</groupId>
- <artifactId>jackson-mapper-asl</artifactId>
- <version>1.0.1</version>
- </dependency>
-
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-host-jetty</artifactId>
- <version>2.0-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-node-impl</artifactId>
- <version>2.0-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-implementation-java-runtime</artifactId>
- <version>2.0-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-
-</project>
+<?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. +--> +<project> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-modules</artifactId> + <version>2.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>tuscany-binding-jsonp-runtime</artifactId> + <name>Apache Tuscany SCA JSONP Binding Runtime</name> + + <dependencies> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-jsonp</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-http</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-core-asl</artifactId> + <version>1.0.1</version> + </dependency> + <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-mapper-asl</artifactId> + <version>1.0.1</version> + </dependency> + + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.5</version> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-host-jetty</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-node-impl</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-implementation-java-runtime</artifactId> + <version>2.0-SNAPSHOT</version> + <scope>test</scope> + </dependency> + + </dependencies> + +</project> diff --git a/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPBindingProviderFactory.java b/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPBindingProviderFactory.java index 0954935098..f686d9d771 100644 --- a/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPBindingProviderFactory.java +++ b/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPBindingProviderFactory.java @@ -1,59 +1,59 @@ -/*
- * 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.jsonp.runtime;
-
-import java.util.List;
-
-import org.apache.tuscany.sca.assembly.Endpoint;
-import org.apache.tuscany.sca.assembly.EndpointReference;
-import org.apache.tuscany.sca.binding.jsonp.JSONPBinding;
-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;
-
-public class JSONPBindingProviderFactory implements BindingProviderFactory<JSONPBinding> {
-
- private ServletHost servletHost;
-
- public JSONPBindingProviderFactory(ExtensionPointRegistry extensionPoints) {
- ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class);
- List<ServletHost> hosts = servletHosts.getServletHosts();
- if (!hosts.isEmpty()) {
- this.servletHost = hosts.get(0);
- }
- }
-
- public Class<JSONPBinding> getModelType() {
- return JSONPBinding.class;
- }
-
- public ReferenceBindingProvider createReferenceBindingProvider(EndpointReference arg0) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public ServiceBindingProvider createServiceBindingProvider(Endpoint endpoint) {
- return new JSONPServiceBindingProvider(endpoint, servletHost);
- }
-
-}
+/* + * 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.jsonp.runtime; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.binding.jsonp.JSONPBinding; +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; + +public class JSONPBindingProviderFactory implements BindingProviderFactory<JSONPBinding> { + + private ServletHost servletHost; + + public JSONPBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + List<ServletHost> hosts = servletHosts.getServletHosts(); + if (!hosts.isEmpty()) { + this.servletHost = hosts.get(0); + } + } + + public Class<JSONPBinding> getModelType() { + return JSONPBinding.class; + } + + public ReferenceBindingProvider createReferenceBindingProvider(EndpointReference arg0) { + // TODO Auto-generated method stub + return null; + } + + public ServiceBindingProvider createServiceBindingProvider(Endpoint endpoint) { + return new JSONPServiceBindingProvider(endpoint, servletHost); + } + +} diff --git a/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java b/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java index dfd2faef7f..2876db430a 100644 --- a/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java +++ b/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java @@ -1,71 +1,71 @@ -/*
- * 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.jsonp.runtime;
-
-import org.apache.tuscany.sca.assembly.ComponentService;
-import org.apache.tuscany.sca.assembly.Endpoint;
-import org.apache.tuscany.sca.host.http.ServletHost;
-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.provider.ServiceBindingProvider;
-import org.apache.tuscany.sca.runtime.RuntimeComponentService;
-import org.apache.tuscany.sca.runtime.RuntimeWire;
-
-public class JSONPServiceBindingProvider implements ServiceBindingProvider {
-
- private Endpoint endpoint;
- private ServletHost servletHost;
-
- public JSONPServiceBindingProvider(Endpoint endpoint, ServletHost servletHost) {
- this.endpoint = endpoint;
- this.servletHost = servletHost;
- }
-
- public void start() {
- ComponentService service = endpoint.getService();
- RuntimeWire wire = ((RuntimeComponentService)service).getRuntimeWire(endpoint.getBinding());
- Interface serviceInterface = service.getInterfaceContract().getInterface();
- for (Operation op : serviceInterface.getOperations()) {
- JSONPServlet servlet = new JSONPServlet(wire, op);
- String path = service.getName() + "/" + op.getName();
- servletHost.addServletMapping(path, servlet);
- }
- }
-
- public void stop() {
- ComponentService service = endpoint.getService();
- Interface serviceInterface = service.getInterfaceContract().getInterface();
- for (Operation op : serviceInterface.getOperations()) {
- String path = service.getName() + "/" + op.getName();
- servletHost.removeServletMapping(path);
- }
- }
-
- // TODO: Why are these two still on the ServiceBindingProvider interface?
- public InterfaceContract getBindingInterfaceContract() {
- return null;
- }
-
- public boolean supportsOneWayInvocation() {
- return false;
- }
-
-}
+/* + * 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.jsonp.runtime; + +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.host.http.ServletHost; +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.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class JSONPServiceBindingProvider implements ServiceBindingProvider { + + private Endpoint endpoint; + private ServletHost servletHost; + + public JSONPServiceBindingProvider(Endpoint endpoint, ServletHost servletHost) { + this.endpoint = endpoint; + this.servletHost = servletHost; + } + + public void start() { + ComponentService service = endpoint.getService(); + RuntimeWire wire = ((RuntimeComponentService)service).getRuntimeWire(endpoint.getBinding()); + Interface serviceInterface = service.getInterfaceContract().getInterface(); + for (Operation op : serviceInterface.getOperations()) { + JSONPServlet servlet = new JSONPServlet(wire, op); + String path = service.getName() + "/" + op.getName(); + servletHost.addServletMapping(path, servlet); + } + } + + public void stop() { + ComponentService service = endpoint.getService(); + Interface serviceInterface = service.getInterfaceContract().getInterface(); + for (Operation op : serviceInterface.getOperations()) { + String path = service.getName() + "/" + op.getName(); + servletHost.removeServletMapping(path); + } + } + + // TODO: Why are these two still on the ServiceBindingProvider interface? + public InterfaceContract getBindingInterfaceContract() { + return null; + } + + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServlet.java b/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServlet.java index 6521e336e6..6eb323527c 100644 --- a/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServlet.java +++ b/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServlet.java @@ -1,114 +1,114 @@ -/*
- * 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.jsonp.runtime;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Enumeration;
-
-import javax.servlet.GenericServlet;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-
-import org.apache.tuscany.sca.interfacedef.Operation;
-import org.apache.tuscany.sca.runtime.RuntimeWire;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.JsonMappingException;
-import org.codehaus.jackson.map.ObjectMapper;
-
-public class JSONPServlet extends GenericServlet {
- private static final long serialVersionUID = 1L;
-
- protected transient RuntimeWire wire;
- protected transient Operation operation;
- protected transient ObjectMapper mapper;
-
- public JSONPServlet(RuntimeWire wire, Operation operation) {
- this.wire = wire;
- this.operation = operation;
- this.mapper = new ObjectMapper();
- }
-
- @Override
- public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
- String jsonRequest = getJSONRequest(servletRequest);
- Object[] args = jsonToObjects(jsonRequest);
- Object response = invokeService(args);
- String jsonResponse = getJSONResponse(servletRequest, response);
- servletResponse.getOutputStream().println(jsonResponse);
- }
-
- /**
- * Turn the request into JSON
- */
- protected String getJSONRequest(ServletRequest servletRequest) throws IOException, JsonParseException, JsonMappingException {
- String jsonRequest = "[";
- for (Enumeration<?> ns = servletRequest.getParameterNames(); ns.hasMoreElements(); ) {
- String name = (String) ns.nextElement();
- if (!name.startsWith("_") && !"callback".equals(name)) {
- if (jsonRequest.length() > 1) {
- jsonRequest += ", ";
- }
- //jsonRequest += name + ":" + servletRequest.getParameter(name);
- jsonRequest += "\""+ servletRequest.getParameter(name) + "\"";
- }
- }
- jsonRequest += "]";
- return jsonRequest;
- }
-
- /**
- * Turn the response object into JSON
- */
- protected String getJSONResponse(ServletRequest servletRequest, Object response) throws IOException, JsonParseException {
- ByteArrayOutputStream os = new ByteArrayOutputStream();
- mapper.writeValue(os , response);
- String jsonResponse = os.toString();
-
- String callback = servletRequest.getParameter("callback");
- if (callback != null && callback.length() > 1) {
- jsonResponse = callback + "(" + jsonResponse + ");";
- }
-
- return jsonResponse;
- }
-
- /**
- * Turn the request JSON into objects
- */
- protected Object[] jsonToObjects(String jsonRequest) throws IOException, JsonParseException, JsonMappingException {
- Class<?> c = new Object[0].getClass();
- Object[] args = (Object[])mapper.readValue(jsonRequest, c);
- return args;
- }
-
- /**
- * Send the request down the wire to invoke the service
- */
- protected Object invokeService(Object[] args) {
- try {
- return wire.invoke(operation, args);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
+/* + * 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.jsonp.runtime; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.Enumeration; + +import javax.servlet.GenericServlet; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.codehaus.jackson.JsonParseException; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; + +public class JSONPServlet extends GenericServlet { + private static final long serialVersionUID = 1L; + + protected transient RuntimeWire wire; + protected transient Operation operation; + protected transient ObjectMapper mapper; + + public JSONPServlet(RuntimeWire wire, Operation operation) { + this.wire = wire; + this.operation = operation; + this.mapper = new ObjectMapper(); + } + + @Override + public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { + String jsonRequest = getJSONRequest(servletRequest); + Object[] args = jsonToObjects(jsonRequest); + Object response = invokeService(args); + String jsonResponse = getJSONResponse(servletRequest, response); + servletResponse.getOutputStream().println(jsonResponse); + } + + /** + * Turn the request into JSON + */ + protected String getJSONRequest(ServletRequest servletRequest) throws IOException, JsonParseException, JsonMappingException { + String jsonRequest = "["; + for (Enumeration<?> ns = servletRequest.getParameterNames(); ns.hasMoreElements(); ) { + String name = (String) ns.nextElement(); + if (!name.startsWith("_") && !"callback".equals(name)) { + if (jsonRequest.length() > 1) { + jsonRequest += ", "; + } + //jsonRequest += name + ":" + servletRequest.getParameter(name); + jsonRequest += "\""+ servletRequest.getParameter(name) + "\""; + } + } + jsonRequest += "]"; + return jsonRequest; + } + + /** + * Turn the response object into JSON + */ + protected String getJSONResponse(ServletRequest servletRequest, Object response) throws IOException, JsonParseException { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + mapper.writeValue(os , response); + String jsonResponse = os.toString(); + + String callback = servletRequest.getParameter("callback"); + if (callback != null && callback.length() > 1) { + jsonResponse = callback + "(" + jsonResponse + ");"; + } + + return jsonResponse; + } + + /** + * Turn the request JSON into objects + */ + protected Object[] jsonToObjects(String jsonRequest) throws IOException, JsonParseException, JsonMappingException { + Class<?> c = new Object[0].getClass(); + Object[] args = (Object[])mapper.readValue(jsonRequest, c); + return args; + } + + /** + * Send the request down the wire to invoke the service + */ + protected Object invokeService(Object[] args) { + try { + return wire.invoke(operation, args); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + } }
\ No newline at end of file diff --git a/java/sca/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java b/java/sca/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java index 16bf1db7ab..25a5cb24e0 100644 --- a/java/sca/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java +++ b/java/sca/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java @@ -1,28 +1,28 @@ -/*
- * 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 helloworld;
-
-
-public class HelloWorldImpl implements HelloWorldService {
-
- public String sayHello(String name) {
- return "Hello " + 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 helloworld; + + +public class HelloWorldImpl implements HelloWorldService { + + public String sayHello(String name) { + return "Hello " + name; + } + +} diff --git a/java/sca/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java b/java/sca/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java index 064d615c45..59b4bd0d57 100644 --- a/java/sca/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java +++ b/java/sca/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java @@ -1,28 +1,28 @@ -/*
- * 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 helloworld;
-
-import org.oasisopen.sca.annotation.Remotable;
-
-@Remotable
-public interface HelloWorldService {
-
- String sayHello(String 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 helloworld; + +import org.oasisopen.sca.annotation.Remotable; + +@Remotable +public interface HelloWorldService { + + String sayHello(String name); + +} diff --git a/java/sca/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java b/java/sca/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java index 5bd52db1dc..d817aff0ff 100644 --- a/java/sca/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java +++ b/java/sca/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java @@ -1,62 +1,62 @@ -/*
- * 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.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.MalformedURLException;
-import java.net.URL;
-
-import junit.framework.Assert;
-
-import org.apache.tuscany.sca.http.jetty.JettyServer;
-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;
-
-public class BindingTestCase {
-
- private static Node node;
-
- @Test
- public void testService() throws MalformedURLException, IOException {
- URL url = new URL("http://localhost:8085/HelloWorldService/sayHello?name=petra&callback=foo");
- BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
- String response = br.readLine();
- Assert.assertEquals("foo(\"Hello petra\");", response);
-
- }
-
- @BeforeClass
- public static void init() throws Exception {
- JettyServer.portDefault = 8085;
- node = NodeFactory.newInstance().createNode("helloworld.composite").start();
- }
-
- @AfterClass
- public static void destroy() throws Exception {
- if (node != null) {
- node.stop();
- }
- }
-
-}
+/* + * 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.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.http.jetty.JettyServer; +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; + +public class BindingTestCase { + + private static Node node; + + @Test + public void testService() throws MalformedURLException, IOException { + URL url = new URL("http://localhost:8085/HelloWorldService/sayHello?name=petra&callback=foo"); + BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream())); + String response = br.readLine(); + Assert.assertEquals("foo(\"Hello petra\");", response); + + } + + @BeforeClass + public static void init() throws Exception { + JettyServer.portDefault = 8085; + node = NodeFactory.newInstance().createNode("helloworld.composite").start(); + } + + @AfterClass + public static void destroy() throws Exception { + if (node != null) { + node.stop(); + } + } + +} diff --git a/java/sca/modules/binding-jsonp-runtime/src/test/resources/helloworld.composite b/java/sca/modules/binding-jsonp-runtime/src/test/resources/helloworld.composite index cbfa8a204d..3ca0b4763e 100644 --- a/java/sca/modules/binding-jsonp-runtime/src/test/resources/helloworld.composite +++ b/java/sca/modules/binding-jsonp-runtime/src/test/resources/helloworld.composite @@ -1,32 +1,32 @@ -<?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/200903"
- xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
- targetNamespace="http://itest"
- name="HelloWorldComposite">
-
- <component name="HelloWorldComponent">
- <implementation.java class="helloworld.HelloWorldImpl"/>
- <service name="HelloWorldService" >
- <tuscany:binding.jsonp />
- </service>
- </component>
-
-</composite>
+<?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/200903" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" + targetNamespace="http://itest" + name="HelloWorldComposite"> + + <component name="HelloWorldComponent"> + <implementation.java class="helloworld.HelloWorldImpl"/> + <service name="HelloWorldService" > + <tuscany:binding.jsonp /> + </service> + </component> + +</composite> |