From 03006fa715a2b2109b0cc7837da6c41f2a56c22f Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 12 May 2010 05:29:01 +0000 Subject: Adding RPC Operation Selector to binding.rest git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@943376 13f79535-47bb-0310-9956-ffa450edef68 --- .../provider/RPCOperationSelectorInterceptor.java | 156 +++++++++++++++++++++ .../RPCOperationSelectorProviderFactory.java | 52 +++++++ .../RPCOperationSelectorReferenceProvider.java | 50 +++++++ .../RPCOperationSelectorServiceProvider.java | 57 ++++++++ 4 files changed, 315 insertions(+) create mode 100644 sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorInterceptor.java create mode 100644 sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorProviderFactory.java create mode 100644 sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorReferenceProvider.java create mode 100644 sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorServiceProvider.java (limited to 'sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc') diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorInterceptor.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorInterceptor.java new file mode 100644 index 0000000000..9d9edaaf6f --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorInterceptor.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.binding.rest.operationselector.rpc.provider; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.QueryParam; + +import org.apache.tuscany.sca.common.http.HTTPContext; +import org.apache.tuscany.sca.common.http.HTTPUtil; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaOperation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; + +/** + * RPC operation selector Interceptor. + * + * @version $Rev$ $Date$ +*/ +public class RPCOperationSelectorInterceptor implements Interceptor { + private ExtensionPointRegistry extensionPoints; + private RuntimeEndpoint endpoint; + + private RuntimeComponentService service; + private InterfaceContract interfaceContract; + private List serviceOperations; + + private Invoker next; + + public RPCOperationSelectorInterceptor(ExtensionPointRegistry extensionPoints, RuntimeEndpoint endpoint) { + this.extensionPoints = extensionPoints; + this.endpoint = endpoint; + + this.service = (RuntimeComponentService)endpoint.getService(); + this.interfaceContract = service.getInterfaceContract(); + this.serviceOperations = service.getInterfaceContract().getInterface().getOperations(); + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public Message invoke(Message msg) { + try { + HTTPContext bindingContext = (HTTPContext)msg.getBindingContext(); + + String path = URLDecoder.decode(HTTPUtil.getRequestPath(bindingContext.getHttpRequest()), "UTF-8"); + + if (path.startsWith("/")) { + path = path.substring(1); + } + + String operationName = bindingContext.getHttpRequest().getParameter("method"); + Operation operation = findOperation( operationName ); + + if (operation == null) { + throw new RuntimeException("Invalid Operation '" + operationName + "'" ); + } + + final JavaOperation javaOperation = (JavaOperation)operation; + final Method method = javaOperation.getJavaMethod(); + + List operationInputType = operation.getInputType().getLogical(); + int size = operationInputType.size(); + for (int i = 0; i < size; i++) { + System.out.println(operationInputType.get(i)); + } + + List messageParameters = new ArrayList(); + for(int i=0; i operations = endpoint.getComponentServiceInterfaceContract().getInterface().getOperations(); + + Operation result = null; + for (Operation o : operations) { + if (o.getName().equalsIgnoreCase(method)) { + result = o; + break; + } + } + + return result; + } +} diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorProviderFactory.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorProviderFactory.java new file mode 100644 index 0000000000..011e89e7cc --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorProviderFactory.java @@ -0,0 +1,52 @@ +/* + * 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.rest.operationselector.rpc.provider; + +import org.apache.tuscany.sca.binding.rest.operationselector.rpc.RPCOperationSelector; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.OperationSelectorProvider; +import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + +/** + * RPC operation selector Provider Factory. + * + * @version $Rev$ $Date$ +*/ +public class RPCOperationSelectorProviderFactory implements OperationSelectorProviderFactory{ + private ExtensionPointRegistry extensionPoints; + + public RPCOperationSelectorProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + } + public OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeEndpointReference endpointReference) { + return new RPCOperationSelectorReferenceProvider(extensionPoints, endpointReference); + } + + public OperationSelectorProvider createServiceOperationSelectorProvider(RuntimeEndpoint endpoint) { + return new RPCOperationSelectorServiceProvider(extensionPoints, endpoint); + } + + public Class getModelType() { + return RPCOperationSelector.class; + } + +} diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorReferenceProvider.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorReferenceProvider.java new file mode 100644 index 0000000000..c87b2fc21d --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorReferenceProvider.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.rest.operationselector.rpc.provider; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.OperationSelectorProvider; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + +/** + * RPC operation selector Reference Provider. + * + * @version $Rev$ $Date$ +*/ +public class RPCOperationSelectorReferenceProvider implements OperationSelectorProvider { + private ExtensionPointRegistry extensionPoints; + private RuntimeEndpointReference endpointReference; + + public RPCOperationSelectorReferenceProvider(ExtensionPointRegistry extensionPoints, RuntimeEndpointReference endpointReference ) { + this.extensionPoints = extensionPoints; + this.endpointReference = endpointReference; + } + + public Interceptor createInterceptor() { + return null; + } + + public String getPhase() { + return Phase.SERVICE_BINDING_OPERATION_SELECTOR; + } + +} diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorServiceProvider.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorServiceProvider.java new file mode 100644 index 0000000000..e4a003d4b5 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/rpc/provider/RPCOperationSelectorServiceProvider.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.binding.rest.operationselector.rpc.provider; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.rest.operationselector.rpc.RPCOperationSelector; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Phase; +import org.apache.tuscany.sca.provider.OperationSelectorProvider; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; + +/** + * RPC operation selector Service Provider. + * + * @version $Rev$ $Date$ +*/ +public class RPCOperationSelectorServiceProvider implements OperationSelectorProvider { + private ExtensionPointRegistry extensionPoints; + private RuntimeEndpoint endpoint; + + private Binding binding; + + public RPCOperationSelectorServiceProvider(ExtensionPointRegistry extensionPoints, RuntimeEndpoint endpoint) { + this.extensionPoints = extensionPoints; + this.endpoint = endpoint; + this.binding = endpoint.getBinding(); + } + + public Interceptor createInterceptor() { + if(binding.getOperationSelector() != null && binding.getOperationSelector() instanceof RPCOperationSelector) { + return new RPCOperationSelectorInterceptor(extensionPoints, endpoint); + } + return null; + } + + public String getPhase() { + return Phase.SERVICE_BINDING_OPERATION_SELECTOR; + } +} -- cgit v1.2.3