You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2010/09/03 01:12:00 UTC
svn commit: r992150 - in
/tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src:
main/java/sample/impl/ test/java/sample/ test/java/sample/impl/
test/resources/
Author: jsdelfino
Date: Thu Sep 2 23:12:00 2010
New Revision: 992150
URL: http://svn.apache.org/viewvc?rev=992150&view=rev
Log:
Add a SOAP Web service binding and a test case for it. Minor cleanup, remove redundant test case and refactor test WSDL namespaces.
Added:
tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/RunWSTestCase.java
Removed:
tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/InControlTestCase.java
Modified:
tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java
tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/ClientTest.java
tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/WelloTest.java
tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java
tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/Hello.wsdl
tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/Upper.wsdl
tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/test.composite
Modified: tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java?rev=992150&r1=992149&r2=992150&view=diff
==============================================================================
--- tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java (original)
+++ tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/main/java/sample/impl/SampleImplementationProcessor.java Thu Sep 2 23:12:00 2010
@@ -140,7 +140,7 @@ public class SampleImplementationProcess
static WSDLInterface resolve(final QName name, final ModelResolver res, final ProcessorContext ctx, final WSDLFactory wif) throws ContributionResolveException {
final WSDLInterface wi = res.resolveModel(WSDLInterface.class, interfaze(name, wif), ctx);
if(!wi.isUnresolved())
- return wi;
+ return domBound(wi);
final WSDLDefinition wd = res.resolveModel(WSDLDefinition.class, definition(wi.getName(), wif), ctx);
if(wd.isUnresolved())
@@ -152,11 +152,23 @@ public class SampleImplementationProcess
try {
final WSDLInterface nwi = wif.createWSDLInterface(pt.getElement(), wd, res, ctx.getMonitor());
nwi.setWsdlDefinition(wd);
- nwi.resetDataBinding(DOMDataBinding.NAME);
res.addModel(nwi, ctx);
- return nwi;
+ return domBound(nwi);
} catch(InvalidInterfaceException e) {
throw new ContributionResolveException(e);
}
}
+
+ /**
+ * Return a WSDL interface configured to use a DOM databinding.
+ */
+ static WSDLInterface domBound(WSDLInterface wi) throws ContributionResolveException {
+ try {
+ final WSDLInterface domwi = (WSDLInterface)wi.clone();
+ domwi.resetDataBinding(DOMDataBinding.NAME);
+ return domwi;
+ } catch(CloneNotSupportedException e) {
+ throw new ContributionResolveException(e);
+ }
+ }
}
Modified: tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/ClientTest.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/ClientTest.java?rev=992150&r1=992149&r2=992150&view=diff
==============================================================================
--- tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/ClientTest.java (original)
+++ tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/ClientTest.java Thu Sep 2 23:12:00 2010
@@ -46,7 +46,7 @@ public class ClientTest {
@Java(Hello.class)
Hello jello;
- @WSDL("http://sample#Hello")
+ @WSDL("http://sample/hello#Hello")
WSDLReference wello;
public String jello(String s) {
@@ -56,7 +56,7 @@ public class ClientTest {
public String wello(String s) {
out.println("ClientTest.wello(" + s + ")");
- final Element hreq = xdom("http://sample", "hello", elem("name", text(s)));
+ final Element hreq = xdom("http://sample/hello", "hello", elem("name", text(s)));
final Element hres = wello.call("hello", hreq);
Modified: tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/WelloTest.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/WelloTest.java?rev=992150&r1=992149&r2=992150&view=diff
==============================================================================
--- tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/WelloTest.java (original)
+++ tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/WelloTest.java Thu Sep 2 23:12:00 2010
@@ -40,20 +40,20 @@ import sample.api.WSDLReference;
*
* @version $Rev$ $Date$
*/
-@WSDL("http://sample#Hello")
+@WSDL("http://sample/hello#Hello")
public class WelloTest {
- @WSDL("http://sample#Upper")
+ @WSDL("http://sample/upper#Upper")
WSDLReference upper;
public Element call(String op, Element e) {
out.println("WelloTest." + op + "(" + xml(e) + ")");
final String name = xreduce(print, "", xfilter(select("name"), elems(e)));
- final Element ureq = xdom("http://sample", "upper", elem("s", text("Hello " + name)));
+ final Element ureq = xdom("http://sample/upper", "upper", elem("s", text("Hello " + name)));
final Element ures = upper.call("upper", ureq);
- final String s = xreduce(print, "", xfilter(select("result"), elems(ures)));
- return xdom("http://sample", "helloResponse", elem("result", text(s)));
+ final String s = xreduce(print, "", xfilter(select("result"), elems(ures)));
+ return xdom("http://sample/hello", "helloResponse", elem("result", text(s)));
}
}
Modified: tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java?rev=992150&r1=992149&r2=992150&view=diff
==============================================================================
--- tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java (original)
+++ tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/EmbedTestCase.java Thu Sep 2 23:12:00 2010
@@ -25,8 +25,10 @@ import static sample.impl.EmbedUtil.comp
import static sample.impl.EmbedUtil.composite;
import static sample.impl.EmbedUtil.contrib;
import static sample.impl.EmbedUtil.deploy;
+import static sample.impl.EmbedUtil.extensionPoints;
import static sample.impl.EmbedUtil.implementation;
import static sample.impl.EmbedUtil.node;
+import static sample.impl.EmbedUtil.providerFactories;
import static sample.impl.EmbedUtil.reference;
import static sample.impl.EmbedUtil.service;
import static sample.impl.EmbedUtil.wsdli;
@@ -36,6 +38,9 @@ import org.apache.tuscany.sca.assembly.C
import org.apache.tuscany.sca.contribution.Contribution;
import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface;
import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -50,7 +55,8 @@ import sample.WelloTest;
/**
* Test how to assemble a contribution, a SCDL composite and run it on an embedded
- * Tuscany runtime node.
+ * Tuscany runtime node. Also shows how pass in a ProviderFactory instead of having
+ * it loaded and constructed by the runtime node.
*
* @version $Rev$ $Date$
*/
@@ -60,12 +66,12 @@ public class EmbedTestCase {
@BeforeClass
public static void setUp() throws Exception {
- // Load the test WSDL definitions (could also construct
- // the WSDL and XSD models in code but that'd be quite
- // painful, so just load them from XML for now)
+ // Load the test WSDL definitions (could also construct the WSDL
+ // and XSD models in code but that'd be quite painful, so just
+ // load them from XML for now)
final Contribution contrib = contrib("test", here());
- WSDLInterface Hello_wsdl = wsdli("Hello.wsdl", "http://sample", "Hello", contrib);
- WSDLInterface Upper_wsdl = wsdli("Upper.wsdl", "http://sample", "Upper", contrib);
+ WSDLInterface Hello_wsdl = wsdli("Hello.wsdl", "http://sample/hello", "Hello", contrib);
+ WSDLInterface Upper_wsdl = wsdli("Upper.wsdl", "http://sample/upper", "Upper", contrib);
// Assemble a test composite model (see EmbedUtil
// for the little DSL used here, much more concise
@@ -91,12 +97,24 @@ public class EmbedTestCase {
reference("upper", "upper-test")),
component("upper-test",
implementation(UpperTest.class,
- service(Upper.class))));
+ service(Upper.class))));
+
+ // Register a test instance of our sample implementation ProviderFactory
+ providerFactories().addProviderFactory(testProviderFactory());
// Run with it
node = node(deploy(contrib, comp));
node.start();
}
+
+ static ProviderFactory<SampleImplementation> testProviderFactory() {
+ // This shows how to get called when a provider is created
+ return new SampleProviderFactory(extensionPoints()) {
+ public ImplementationProvider createImplementationProvider(RuntimeComponent comp, SampleImplementation impl) {
+ out.println("Creating a provider for component " + comp.getName());
+ return super.createImplementationProvider(comp, impl);
+ }};
+ }
@AfterClass
public static void tearDown() throws Exception {
Added: tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/RunWSTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/RunWSTestCase.java?rev=992150&view=auto
==============================================================================
--- tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/RunWSTestCase.java (added)
+++ tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/java/sample/impl/RunWSTestCase.java Thu Sep 2 23:12:00 2010
@@ -0,0 +1,120 @@
+/*
+ * 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.impl;
+
+import static java.lang.System.out;
+import static org.junit.Assert.assertTrue;
+import static sample.impl.TestUtil.here;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.net.Socket;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.http.jetty.JettyServer;
+import org.apache.tuscany.sca.node.Contribution;
+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;
+
+/**
+ * Test a component that provides and consumes SOAP Web services.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RunWSTestCase {
+ static Node node;
+ static JettyServer jetty;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ // Start test composite on a Tuscany node
+ final NodeFactory nf = NodeFactory.newInstance();
+ node = nf.createNode(new Contribution("test", here()));
+ node.start();
+
+ // Mock up a test Web service on http://localhost:8086/wsupper
+ jetty = new JettyServer((ExtensionPointRegistry)nf.getExtensionPointRegistry());
+ jetty.start();
+ jetty.addServletMapping("http://localhost:8086/wsupper", new HttpServlet() {
+ private static final long serialVersionUID = 1L;
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ assertTrue(read(req.getInputStream()).contains("Hello SOAP"));
+ final String soapresp =
+ "<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
+ "<soapenv:Body><upperResponse xmlns=\"http://sample/upper\">" +
+ "<result xmlns=\"\">HELLO SOAP</result>" +
+ "</upperResponse></soapenv:Body></soapenv:Envelope>";
+
+ write(soapresp, resp.getOutputStream());
+ }
+ });
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ jetty.stop();
+ node.stop();
+ }
+
+ @Test
+ public void wsello() throws Exception {
+ out.println("RunWSTestCase.wsello");
+ // Send a SOAP request to the Web service provided by SCA component wsello-test
+ // on http://localhost:8085/wsello
+ final Socket s = new Socket("localhost", 8085);
+ final String soapreq =
+ "POST /wsello HTTP/1.0\r\n" +
+ "Content-Type: text/xml; charset=UTF-8\r\n" +
+ "Content-length: 231\r\n\r\n" +
+ "<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
+ "<soapenv:Body><hello xmlns=\"http://sample/hello\">" +
+ "<name xmlns=\"\">SOAP</name>" +
+ "</hello></soapenv:Body></soapenv:Envelope>";
+ write(soapreq, s.getOutputStream());
+ assertTrue(read(s.getInputStream()).contains("HELLO SOAP"));
+ }
+
+ static void write(final String s, final OutputStream o) throws IOException {
+ final OutputStreamWriter w = new OutputStreamWriter(o);
+ w.write(s);
+ w.flush();
+ }
+
+ static String read(final InputStream i) throws IOException {
+ return read(new BufferedReader(new InputStreamReader(i)));
+ }
+
+ static String read(final BufferedReader r) throws IOException {
+ final String s = r.readLine();
+ return s == null? "" : s + read(r);
+ }
+}
Modified: tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/Hello.wsdl
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/Hello.wsdl?rev=992150&r1=992149&r2=992150&view=diff
==============================================================================
--- tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/Hello.wsdl (original)
+++ tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/Hello.wsdl Thu Sep 2 23:12:00 2010
@@ -17,13 +17,13 @@
* specific language governing permissions and limitations
* under the License.
-->
-<wsdl:definitions targetNamespace="http://sample" xmlns:tns="http://sample"
+<wsdl:definitions targetNamespace="http://sample/hello" xmlns:tns="http://sample/hello"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="Hello">
<wsdl:types>
- <schema elementFormDefault="qualified" targetNamespace="http://sample"
+ <schema elementFormDefault="qualified" targetNamespace="http://sample/hello"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="hello">
<complexType>
Modified: tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/Upper.wsdl
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/Upper.wsdl?rev=992150&r1=992149&r2=992150&view=diff
==============================================================================
--- tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/Upper.wsdl (original)
+++ tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/Upper.wsdl Thu Sep 2 23:12:00 2010
@@ -17,13 +17,13 @@
* specific language governing permissions and limitations
* under the License.
-->
-<wsdl:definitions targetNamespace="http://sample" xmlns:tns="http://sample"
+<wsdl:definitions targetNamespace="http://sample/upper" xmlns:tns="http://sample/upper"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="Upper">
<wsdl:types>
- <schema elementFormDefault="qualified" targetNamespace="http://sample"
+ <schema elementFormDefault="qualified" targetNamespace="http://sample/upper"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="upper">
<complexType>
Modified: tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/test.composite
URL: http://svn.apache.org/viewvc/tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/test.composite?rev=992150&r1=992149&r2=992150&view=diff
==============================================================================
--- tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/test.composite (original)
+++ tuscany/sandbox/sebastien/java/embed/samples/implementation-extension/src/test/resources/test.composite Thu Sep 2 23:12:00 2010
@@ -20,24 +20,39 @@
<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1"
targetNamespace="http://test"
- name="test">
-
+ name="wstest">
+
+ <!-- Client test component used by the JUnit tests -->
<component name="client-test">
<t:implementation.sample class="sample.ClientTest"/>
<reference name="wello" target="wello-test"/>
<reference name="jello" target="jello-test"/>
</component>
+ <!-- HelloWorld test component that uses WSDL interfaces -->
<component name="wello-test">
<t:implementation.sample class="sample.WelloTest"/>
<reference name="upper" target="upper-test"/>
</component>
+ <!-- HelloWorld test component that uses Java interfaces -->
<component name="jello-test">
<t:implementation.sample class="sample.JelloTest"/>
<reference name="upper" target="upper-test"/>
</component>
+ <!-- HelloWorld test component that uses WSDL interfaces and SOAP Web Services -->
+ <component name="Wsello-test">
+ <t:implementation.sample class="sample.WelloTest"/>
+ <service name="Hello">
+ <binding.ws uri="http://localhost:8085/wsello"/>
+ </service>
+ <reference name="upper">
+ <binding.ws uri="http://localhost:8086/wsupper"/>
+ </reference>
+ </component>
+
+ <!-- Test component converts a string to uppercase -->
<component name="upper-test">
<t:implementation.sample class="sample.UpperTest"/>
</component>