Commit in servicemix/components/jaxws/src on MAIN
test/java/org/servicemix/TestSupport.java+103added 1.1
                        /SpringTestSupport.java+81added 1.1
main/java/org/servicemix/components/jaxws/package.html+9added 1.1
                                         /JAXWSBinding.java+199added 1.1
test/recources/org/servicemix/components/jaxws/example.xml+19added 1.1
                                              /request.xml+4added 1.1
                                              /AddNumbers.wsdl+61added 1.1
test/java/org/servicemix/components/jaxws/JAXWSTest.java+58added 1.1
+534
8 added files
Initial import of a JAX-WS binding

servicemix/components/jaxws/src/test/java/org/servicemix
TestSupport.java added at 1.1
diff -N TestSupport.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ TestSupport.java	31 Aug 2005 15:43:54 -0000	1.1
@@ -0,0 +1,103 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at 
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License. 
+ * 
+ **/
+package org.servicemix;
+
+import org.servicemix.client.ServiceMixClient;
+import org.servicemix.jbi.container.SpringJBIContainer;
+import org.servicemix.jbi.jaxp.StringSource;
+import org.servicemix.jbi.resolver.ServiceNameEndpointResolver;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+
+import java.util.Date;
+
+/**
+ * @version $Revision$
+ */
+public abstract class TestSupport extends SpringTestSupport {
+    protected ServiceMixClient client;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        client = (ServiceMixClient) getBean("client");
+
+        // TODO
+        //receiver = (Receiver) getBean("receiver");
+
+        SpringJBIContainer jbi = (SpringJBIContainer) getBean("jbi");
+    }
+
+    /**
+     * Sends the given number of messages to the given service
+     *
+     * @param service
+     * @throws javax.jbi.messaging.MessagingException
+     */
+    protected void sendMessages(QName service, int messageCount) throws Exception {
+        for (int i = 1; i <= messageCount; i++) {
+            InOnly exchange = client.createInOnlyExchange();
+
+            NormalizedMessage message = exchange.getInMessage();
+            message.setProperty("name", "James");
+            message.setProperty("id", new Integer(i));
+            message.setProperty("idText", "" + i);
+            message.setContent(new StringSource(createMessageXmlText(i)));
+
+            exchange.setService(service);
+            client.sendSync(exchange);
+            client.done(exchange);
+
+            // lets assert that we have no failure
+            Exception error = exchange.getError();
+            if (error != null) {
+                throw error;
+            }
+
+            Fault fault = exchange.getFault();
+            assertEquals("Should have no fault!", null, fault);
+        }
+    }
+
+    protected String createMessageXmlText(int index) {
+        return "<sample id='" + index + "' sent='" + new Date() + "'>hello world!</sample>";
+    }
+
+    /**
+     * Performs a request using the given file from the classpath as the request body and return the answer
+     *
+     * @param serviceName
+     * @param fileOnClassPath
+     * @return
+     * @throws JBIException
+     */
+    protected Object requestServiceWithFileRequest(QName serviceName, String fileOnClassPath) throws JBIException {
+        Source content = getSourceFromClassPath(fileOnClassPath);
+
+        ServiceNameEndpointResolver resolver = new ServiceNameEndpointResolver(serviceName);
+
+        Object answer = client.request(resolver, null, null, content);
+        return answer;
+    }
+
+}

servicemix/components/jaxws/src/test/java/org/servicemix
SpringTestSupport.java added at 1.1
diff -N SpringTestSupport.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ SpringTestSupport.java	31 Aug 2005 15:43:54 -0000	1.1
@@ -0,0 +1,81 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at 
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License. 
+ * 
+ **/
+package org.servicemix;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.servicemix.jbi.container.SpringJBIContainer;
+import org.servicemix.jbi.jaxp.SourceTransformer;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Revision$
+ */
+public abstract class SpringTestSupport extends TestCase {
+    protected transient Log log = LogFactory.getLog(getClass());
+
+    protected AbstractXmlApplicationContext context;
+    protected SourceTransformer transformer;
+    protected int messageCount = 20;
+    protected SpringJBIContainer jbi;
+
+    protected void setUp() throws Exception {
+        transformer = new SourceTransformer();
+
+        context = createBeanFactory();
+        context.setXmlValidating(false);
+
+        jbi = (SpringJBIContainer) context.getBean("jbi");
+    }
+
+    protected void tearDown() throws Exception {
+        if (context != null) {
+            System.out.println("Closing down the spring context");
+            context.destroy();
+        }
+    }
+
+    protected Object getBean(String name) {
+        Object answer = null;
+        if (jbi != null) {
+            answer = jbi.getBean(name);
+        }
+        if (answer == null) {
+            answer = context.getBean(name);
+        }
+        assertNotNull("Could not find object in Spring for key: " + name, answer);
+        return answer;
+    }
+
+    protected abstract AbstractXmlApplicationContext createBeanFactory();
+
+    protected Source getSourceFromClassPath(String fileOnClassPath) {
+        InputStream stream = getClass().getResourceAsStream(fileOnClassPath);
+        assertNotNull("Could not find file: " + fileOnClassPath + " on the classpath", stream);
+
+        Source content = new StreamSource(stream);
+        return content;
+    }
+}

servicemix/components/jaxws/src/main/java/org/servicemix/components/jaxws
package.html added at 1.1
diff -N package.html
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ package.html	31 Aug 2005 15:43:54 -0000	1.1
@@ -0,0 +1,9 @@
+<html>
+<head>
+</head>
+<body>
+
+Bindings for <a href="">JAX-WS</a> to expose JAX-WS based services as a JBI Binding Component.
+
+</body>
+</html>

servicemix/components/jaxws/src/main/java/org/servicemix/components/jaxws
JAXWSBinding.java added at 1.1
diff -N JAXWSBinding.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ JAXWSBinding.java	31 Aug 2005 15:43:54 -0000	1.1
@@ -0,0 +1,199 @@
+/**
+ * 
+ * Copyright 2005 Protique Ltd
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at 
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License. 
+ * 
+ **/
+package org.servicemix.components.jaxws;
+
+import org.servicemix.MessageExchangeListener;
+import org.servicemix.components.util.TransformComponentSupport;
+import org.springframework.core.io.Resource;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.ServiceFactory;
+import javax.xml.ws.Service.Mode;
+
+import java.io.IOException;
+import java.net.URL;
+
+/**
+ * Converts an inbound JBI message into a <a
+ * href="">JAX-WS</a> one way or a request-response where the output is
+ * replied back to the Normalized Message Router.
+ * 
+ * @version $Revision$
+ */
+public class JAXWSBinding extends TransformComponentSupport implements MessageExchangeListener {
+
+    private Dispatch<Source> dispatch;
+    private Service jaxService;
+    private ServiceFactory jaxServiceFactory;
+    private URL wsdl;
+    private QName interfaceName;
+    private Mode mode = Mode.PAYLOAD;
+    private boolean defaultInOut = true;
+    private Resource wsdlResource;
+
+    public Dispatch<Source> getDispatch() throws IOException {
+        if (dispatch == null) {
+            dispatch = createDispatch();
+        }
+        return dispatch;
+    }
+
+    public void setDispatch(Dispatch<Source> dispatch) {
+        this.dispatch = dispatch;
+    }
+
+    public Service getJaxService() throws IOException {
+        if (jaxService == null) {
+            jaxService = createJaxService();
+        }
+        return jaxService;
+    }
+
+    public void setJaxService(Service jaxService) {
+        this.jaxService = jaxService;
+    }
+
+    public ServiceFactory getJaxServiceFactory() {
+        if (jaxServiceFactory == null) {
+            jaxServiceFactory = ServiceFactory.newInstance();
+        }
+        return jaxServiceFactory;
+    }
+
+    public void setJaxServiceFactory(ServiceFactory jaxServiceFactory) {
+        this.jaxServiceFactory = jaxServiceFactory;
+    }
+
+    public URL getWsdl() throws IOException {
+        if (wsdl == null) {
+            wsdl = createWsdl();
+        }
+        return wsdl;
+    }
+
+    public void setWsdl(URL wsdl) {
+        this.wsdl = wsdl;
+    }
+
+    public Resource getWsdlResource() {
+        return wsdlResource;
+    }
+
+    public void setWsdlResource(Resource wsdlResource) {
+        this.wsdlResource = wsdlResource;
+    }
+
+    public QName getInterfaceName() {
+        return interfaceName;
+    }
+
+    public void setInterfaceName(QName interfaceName) {
+        this.interfaceName = interfaceName;
+    }
+
+    public Mode getMode() {
+        return mode;
+    }
+
+    public void setMode(Mode mode) {
+        this.mode = mode;
+    }
+
+    public boolean isDefaultInOut() {
+        return defaultInOut;
+    }
+
+    /**
+     * Sets whether an InOut (the default) or an InOnly message exchange will be
+     * used by default.
+     */
+    public void setDefaultInOut(boolean defaultInOut) {
+        this.defaultInOut = defaultInOut;
+    }
+
+    // Implementation methods
+    // -------------------------------------------------------------------------
+    protected void init() throws JBIException {
+        super.init();
+
+        // lets force the lazy initialization
+        try {
+            getDispatch();
+        }
+        catch (IOException e) {
+            throw new JBIException("Failed to create Dispatch: " + e, e);
+        }
+    }
+
+    protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out)
+            throws MessagingException {
+
+        Source content = getInMessage(exchange).getContent();
+
+        if (isInOutRequest(exchange, in, out)) {
+            copyProperties(exchange, in, out);
+            Source answer = dispatch.invoke(content);
+            out.setContent(answer);
+        }
+        else {
+            dispatch.invokeOneWay(content);
+        }
+        return true;
+    }
+
+    /**
+     * Return true if this request is an [EMAIL PROTECTED] InOut} request otherwise it will
+     * be assumed to be an [EMAIL PROTECTED] InOnly}
+     */
+    boolean isInOutRequest(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) {
+        return isDefaultInOut();
+    }
+
+    protected Dispatch<Source> createDispatch() throws IOException {
+        return getJaxService().createDispatch(getInterfaceName(), Source.class, getMode());
+    }
+
+    protected Service createJaxService() throws IOException {
+        QName serviceName = getService();
+        URL url = ""
+        if (url != null) {
+            return getJaxServiceFactory().createService(url, serviceName);
+        }
+        else {
+            return getJaxServiceFactory().createService(serviceName);
+        }
+    }
+    
+    protected URL createWsdl() throws IOException {
+        if (wsdlResource != null) {
+            return wsdlResource.getURL();
+        }
+        return null;
+    }
+
+
+}

servicemix/components/jaxws/src/test/recources/org/servicemix/components/jaxws
example.xml added at 1.1
diff -N example.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ example.xml	31 Aug 2005 15:43:54 -0000	1.1
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:foo="http://duke.org">
+
+  <container id="jbi">
+    <components>
+      <!-- START SNIPPET: jaxws -->
+      <component id="addNumbersService" service="foo:AddNumbersService" class="org.servicemix.components.jaxws.JAXWSBinding">
+        <property name="interfaceName"><qname>foo:AddNumbersPort</qname></property>
+        <property name="wsdlResource" value="classpath:org/servicemix/components/jaxws/AddNumbers.wsdl"/>
+       </component>
+      <!-- END SNIPPET: jaxws -->
+    </components>
+  </container>
+
+  <bean id="client" class="org.servicemix.client.DefaultServiceMixClient">
+    <constructor-arg ref="jbi"/>
+  </bean>
+
+</beans>

servicemix/components/jaxws/src/test/recources/org/servicemix/components/jaxws
request.xml added at 1.1
diff -N request.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ request.xml	31 Aug 2005 15:43:54 -0000	1.1
@@ -0,0 +1,4 @@
+<ns2:addNumbers xmlns:ns2="http://duke.org">
+  <arg0>10</arg0>  
+  <arg1>20</arg1>
+</ns2:addNumbers>
\ No newline at end of file

servicemix/components/jaxws/src/test/recources/org/servicemix/components/jaxws
AddNumbers.wsdl added at 1.1
diff -N AddNumbers.wsdl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ AddNumbers.wsdl	31 Aug 2005 15:43:54 -0000	1.1
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<definitions
+    name="AddNumbers"
+    targetNamespace="http://duke.org"
+    xmlns:tns="http://duke.org"
+    xmlns="http://schemas.xmlsoap.org/wsdl/"
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
+    <types>
+        <xsd:schema
+            xmlns="http://www.w3.org/2001/XMLSchema"
+            targetNamespace="http://duke.org"
+			elementFormDefault="qualified">
+
+            <complexType name="addNumbersResponse">
+                <sequence>
+                    <element name="return" type="xsd:int" />
+                </sequence>
+            </complexType>
+            <element name="addNumbersResponse" type="tns:addNumbersResponse"/>
+
+            <complexType name="addNumbers">
+                <sequence>
+                    <element name="arg0" type="xsd:int" />
+                    <element name="arg1" type="xsd:int" />
+                </sequence>
+            </complexType>
+            <element name="addNumbers" type="tns:addNumbers"/>
+        </xsd:schema>
+    </types>
+    <message name="addNumbers">
+        <part name="parameters" element="tns:addNumbers" />
+    </message>
+    <message name="addNumbersResponse">
+        <part name="result" element="tns:addNumbersResponse" />
+    </message>
+    <portType name="AddNumbersPortType">
+        <operation name="addNumbers">
+            <input message="tns:addNumbers" />
+            <output message="tns:addNumbersResponse" />
+        </operation>
+    </portType>
+    <binding name="AddNumbersBinding" type="tns:AddNumbersPortType">
+        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
+        <operation name="addNumbers">
+            <soap:operation soapAction="" />
+            <input>
+                <soap:body use="literal" />
+            </input>
+            <output>
+                <soap:body use="literal" />
+            </output>
+        </operation>
+    </binding>
+    <service name="AddNumbersService">
+        <port name="AddNumbersPort" binding="tns:AddNumbersBinding">
+            <soap:address location="REPLACE_WITH_ACTUAL_URL" />
+        </port>
+    </service>
+</definitions>

servicemix/components/jaxws/src/test/java/org/servicemix/components/jaxws
JAXWSTest.java added at 1.1
diff -N JAXWSTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ JAXWSTest.java	31 Aug 2005 15:43:54 -0000	1.1
@@ -0,0 +1,58 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); 
+ * you may not use this file except in compliance with the License. 
+ * You may obtain a copy of the License at 
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, 
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
+ * See the License for the specific language governing permissions and 
+ * limitations under the License. 
+ * 
+ **/
+package org.servicemix.components.jaxws;
+
+import org.servicemix.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.w3c.dom.Node;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision$
+ */
+public class JAXWSTest extends TestSupport {
+
+    protected String quote = "SUNW";
+
+    public void testCurrencyQuotes() throws Exception {
+        QName serviceName = new QName("http://duke.org", "AddNumbersService");
+        String file = "request.xml";
+
+        Object answer = requestServiceWithFileRequest(serviceName, file);
+
+        assertTrue("Should return a DOM Node: " + answer, answer instanceof Node);
+
+        Node node = (Node) answer;
+        System.out.println(transformer.toString(node));
+
+        /*
+        String text = textValueOfXPath(node, "//Result").trim();
+
+        System.out.println("Found price: " + text);
+
+        assertTrue("price text should not be empty", text.length() > 0);
+        */
+
+    }
+
+    protected AbstractXmlApplicationContext createBeanFactory() {
+        return new ClassPathXmlApplicationContext("org/servicemix/components/jaxws/example.xml");
+    }
+}
CVSspam 0.2.8



Reply via email to