diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-25 23:30:28 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-25 23:30:28 +0000 |
commit | 875e50908c2630d263661af492654cd44bef2d65 (patch) | |
tree | 30cc749cb9d25fd84b67fa086394735601782409 /sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src | |
parent | 1456632c03944d54a5f059fe54e49b3014bc7fea (diff) |
Sandbox to experiment with dynamic mass virtual hosting and running a different composite per vhost.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1063520 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
18 files changed, 673 insertions, 0 deletions
diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/SampleBinding.java b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/SampleBinding.java new file mode 100644 index 0000000000..174a32fce4 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/SampleBinding.java @@ -0,0 +1,49 @@ +/* + * 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 sample.binding; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.provider.BaseBindingImpl; + +/** + * Represents a binding to a Sample service. + */ +public class SampleBinding extends BaseBindingImpl { + + public static final QName TYPE = new QName(SCA11_TUSCANY_NS, "binding.sample"); + + private String someAttr; + + public SampleBinding() { + } + + public QName getType() { + return TYPE; + } + + public String getSomeAttr() { + return someAttr; + } + + public void setSomeAttr(String someAttr) { + this.someAttr = someAttr; + } + +} diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/SampleBindingFactory.java b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/SampleBindingFactory.java new file mode 100644 index 0000000000..6f4920448c --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/SampleBindingFactory.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 sample.binding; + + +/** + * Factory implementation to create Sample Models + */ +public class SampleBindingFactory { + + public SampleBinding createSampleBinding() { + return new SampleBinding(); + } + +} diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleBindingProviderFactory.java b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleBindingProviderFactory.java new file mode 100644 index 0000000000..4fb966138d --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleBindingProviderFactory.java @@ -0,0 +1,47 @@ +/* + * 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 sample.binding.runtime; + +import sample.binding.SampleBinding; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; + +public class SampleBindingProviderFactory implements BindingProviderFactory<SampleBinding> { + + public SampleBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + } + + public Class<SampleBinding> getModelType() { + return SampleBinding.class; + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeEndpointReference endpoint) { + return new SampleReferenceBindingProvider(endpoint); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeEndpoint endpoint) { + return new SampleServiceBindingProvider(endpoint); + } + +} diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleReferenceBindingProvider.java b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleReferenceBindingProvider.java new file mode 100644 index 0000000000..b1edf6c729 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleReferenceBindingProvider.java @@ -0,0 +1,55 @@ +/* + * 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 sample.binding.runtime; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; + +public class SampleReferenceBindingProvider implements ReferenceBindingProvider { + + private EndpointReference endpoint; + private InterfaceContract contract; + + public SampleReferenceBindingProvider(EndpointReference endpoint) { + this.endpoint = endpoint; + } + + public Invoker createInvoker(Operation operation) { + return new SampleReferenceInvoker(operation, endpoint); + } + + public void start() { + } + + public void stop() { + } + + public InterfaceContract getBindingInterfaceContract() { + return contract; + } + + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleReferenceInvoker.java b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleReferenceInvoker.java new file mode 100644 index 0000000000..31cb339818 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleReferenceInvoker.java @@ -0,0 +1,53 @@ +/* + * 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 sample.binding.runtime; + +import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +public class SampleReferenceInvoker implements Invoker { + + protected Operation operation; + protected EndpointReference endpoint; + + public SampleReferenceInvoker(Operation operation, EndpointReference endpoint) { + this.operation = operation; + this.endpoint = endpoint; + } + + public Message invoke(Message msg) { + try { + + return doInvoke(msg); + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public Message doInvoke(Message msg) { + // Add some code here to make an invocation over the Sample binding protocol + // For this sample we'll just get it from the static stash + SampleServiceInvoker fi = SampleStash.getService(endpoint.getBinding().getURI()); + return fi.invokeService(msg); + } +} diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleServiceBindingProvider.java b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleServiceBindingProvider.java new file mode 100644 index 0000000000..f8aab77fde --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleServiceBindingProvider.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 sample.binding.runtime; + +import sample.binding.SampleBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; + +public class SampleServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeEndpoint endpoint; + private InterfaceContract contract; + + public SampleServiceBindingProvider(RuntimeEndpoint endpoint) { + this.endpoint = endpoint; + } + + public void start() { + // add some code here to start the service + + // For this sample we'll just share it in a static + SampleStash.addService(endpoint.getBinding().getURI(), new SampleServiceInvoker(endpoint)); + + System.out.println("someAttr=" + ((SampleBinding)endpoint.getBinding()).getSomeAttr()); + } + + public void stop() { + SampleStash.removeService(endpoint.getBinding().getURI()); + } + + public InterfaceContract getBindingInterfaceContract() { + return contract; + } + + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleServiceInvoker.java b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleServiceInvoker.java new file mode 100644 index 0000000000..bfbfe80966 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleServiceInvoker.java @@ -0,0 +1,40 @@ +/* + * 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 sample.binding.runtime; + +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeEndpoint; + +public class SampleServiceInvoker { + + private RuntimeEndpoint wire; + + public SampleServiceInvoker(RuntimeEndpoint wire) { + this.wire = wire; + } + + /** + * Send the request down the wire to invoke the service + */ + public Message invokeService(Message msg) { + return wire.invoke(msg); + } + +} diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleStash.java b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleStash.java new file mode 100644 index 0000000000..cbebe77cf6 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/java/sample/binding/runtime/SampleStash.java @@ -0,0 +1,44 @@ +/* + * 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 sample.binding.runtime; + +import java.util.HashMap; +import java.util.Map; + +/** + * Simplistic static Map to share service endpoints with references + */ +public class SampleStash { + + private static Map<String, SampleServiceInvoker> services = new HashMap<String, SampleServiceInvoker>(); + + public static void addService(String uri, SampleServiceInvoker SampleServiceInvoker) { + services.put(uri, SampleServiceInvoker); + } + + public static SampleServiceInvoker getService(String uri) { + return services.get(uri); + } + + public static void removeService(String uri) { + services.remove(uri); + } + +} diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..91c49a69e0 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#binding.sample,model=sample.binding.SampleBinding,factory=sample.binding.SampleBindingFactory
+
diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema new file mode 100644 index 0000000000..dda33eb075 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema @@ -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.
+#
+binding-sample.xsd
+
diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..e6b86ac871 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the binding extension
+sample.binding.runtime.SampleBindingProviderFactory;model=sample.binding.SampleBinding
+
diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/META-INF/services/sample.binding.SampleBindingFactory b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/META-INF/services/sample.binding.SampleBindingFactory new file mode 100644 index 0000000000..ec8c4b9936 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/META-INF/services/sample.binding.SampleBindingFactory @@ -0,0 +1,20 @@ +# 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 model factory
+sample.binding.SampleBindingFactory
+
diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/binding-sample.xsd b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/binding-sample.xsd new file mode 100644 index 0000000000..26f4f80ea4 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/main/resources/binding-sample.xsd @@ -0,0 +1,37 @@ +<?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. +--> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://tuscany.apache.org/xmlns/sca/1.1" + xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1" + elementFormDefault="qualified"> + + <import namespace="http://docs.oasis-open.org/ns/opencsa/sca/200912" /> + + <element name="binding.sample" type="t:SampleBinding" substitutionGroup="sca:binding"/> + + <complexType name="SampleBinding"> + <complexContent> + <extension base="sca:Binding"> + <attribute name="someAttr" type="string" use="optional"/> + </extension> + </complexContent> + </complexType> +</schema> diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/java/helloworld/HelloWorldClient.java b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/java/helloworld/HelloWorldClient.java new file mode 100644 index 0000000000..bafb453a30 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/java/helloworld/HelloWorldClient.java @@ -0,0 +1,33 @@ +/* + * 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.Reference; + +public class HelloWorldClient implements HelloWorldService { + + @Reference + public HelloWorldService ref; + + public String sayHello(String name) { + return ref.sayHello(name); + } + +} diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/java/helloworld/HelloWorldImpl.java b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/java/helloworld/HelloWorldImpl.java new file mode 100644 index 0000000000..98989e6e49 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/java/helloworld/HelloWorldImpl.java @@ -0,0 +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; + } + +} diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/java/helloworld/HelloWorldService.java b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..59b4bd0d57 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/java/helloworld/HelloWorldService.java @@ -0,0 +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); + +} diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/java/test/SampleBindingTestCase.java b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/java/test/SampleBindingTestCase.java new file mode 100644 index 0000000000..f3274a7fcb --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/java/test/SampleBindingTestCase.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 test; + +import helloworld.HelloWorldService; +import junit.framework.Assert; + +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class SampleBindingTestCase { + + private static Node node; + + @Test + public void testSayHello() { + HelloWorldService service = node.getService(HelloWorldService.class, "HelloWorldClient/HelloWorldService"); + Assert.assertEquals("Hello boo", service.sayHello("boo")); + } + + @BeforeClass + public static void init() throws Exception { + node = NodeFactory.newInstance().createNode("helloworld.composite").start(); + } + + @AfterClass + public static void destroy() throws Exception { + if (node != null) { + node.stop(); + } + } + +} diff --git a/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/resources/helloworld.composite b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/resources/helloworld.composite new file mode 100644 index 0000000000..9bb69bae65 --- /dev/null +++ b/sandbox/sebastien/java/vhost/samples/extending-tuscany/binding-sample/src/test/resources/helloworld.composite @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ -->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ targetNamespace="http://itest"
+ name="HelloWorldComposite">
+
+ <component name="HelloWorldComponent">
+ <implementation.java class="helloworld.HelloWorldImpl"/>
+ <service name="HelloWorldService" >
+ <tuscany:binding.sample someAttr="bla" />
+ </service>
+ </component>
+
+ <component name="HelloWorldClient">
+ <implementation.java class="helloworld.HelloWorldClient"/>
+ <reference name="ref" >
+ <tuscany:binding.sample uri="HelloWorldComponent/HelloWorldService"/>
+ </reference>
+ </component>
+
+</composite>
|