You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2007/10/01 11:47:52 UTC

svn commit: r580908 - in /incubator/tuscany/java/sca: modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/ modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/ modules/policy-secu...

Author: slaws
Date: Mon Oct  1 02:47:50 2007
New Revision: 580908

URL: http://svn.apache.org/viewvc?rev=580908&view=rev
Log:
TUSCANY-1822
First baby steps in creating intents to control the web service binding transport

Added:
    incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/definitions.xml
    incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/helloworldwsjmspolicy.composite
    incubator/tuscany/java/sca/samples/helloworld-ws-service/src/test/java/helloworld/HelloWorldJmsPolicyServerTestCase.java
Modified:
    incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java
    incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml
    incubator/tuscany/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/ws/Axis2ConfigParamPolicyProcessor.java

Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java?rev=580908&r1=580907&r2=580908&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java Mon Oct  1 02:47:50 2007
@@ -88,6 +88,7 @@
 import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
 import org.apache.tuscany.sca.invocation.Message;
 import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.policy.Intent;
 import org.apache.tuscany.sca.policy.PolicySet;
 import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
 import org.apache.tuscany.sca.policy.security.ws.Axis2ConfigParamPolicy;
@@ -121,8 +122,15 @@
     // TODO: what to do about the base URI?
     // This port number may be used to construct callback URIs.  The value 8085 is used
     // beacuse it matches the service port number used by the simple-callback-ws sample.
-    private static final String BASE_URI = "http://localhost:8085/";
-    private static final String DEFAULT_QUEUE_CONENCTION_FACTORY = "TuscanyQueueConnectionFactory";
+    private static final String BASE_HTTP_URI = "http://localhost:8085/";
+    private static final String BASE_JMS_URI = "jms:";
+    
+    private static final String DEFAULT_QUEUE_CONNECTION_FACTORY = "TuscanyQueueConnectionFactory";
+    
+    private static final QName TRANSPORT_JMS_QUALIFIED_INTENT = new QName("http://www.osoa.org/xmlns/sca/1.0","transport.jms");
+    
+    private PolicySet transportJmsPolicySet = null;
+        
 
     public Axis2ServiceProvider(RuntimeComponent component,
                                 AbstractContract contract,
@@ -149,7 +157,45 @@
 
         configContext.setContextRoot(servletHost.getContextPath());
 
-        String uri = computeActualURI(BASE_URI, component, contract).normalize().toString();
+        // pull out the binding intents to see what sort of transport is required
+        transportJmsPolicySet = getPolicySet(TRANSPORT_JMS_QUALIFIED_INTENT);
+        
+        String uri;
+        
+        if (transportJmsPolicySet != null){
+            uri = computeActualURI(BASE_JMS_URI, component, contract).normalize().toString();
+            
+            // construct the rest of the uri based on the policy. All the details are put
+            // into the uri here rather than being place directly into the Axis configuration 
+            // as the Axis JMS sender relies on parsing the target URI      
+            Axis2ConfigParamPolicy axis2ConfigParamPolicy = null;
+            for ( Object policy : transportJmsPolicySet.getPolicies() ) {
+                if ( policy instanceof Axis2ConfigParamPolicy ) {
+                    axis2ConfigParamPolicy = (Axis2ConfigParamPolicy)policy;
+                    Iterator paramIterator = axis2ConfigParamPolicy.getParamElements().get(DEFAULT_QUEUE_CONNECTION_FACTORY).getChildElements();
+                    
+                    if (paramIterator.hasNext()){
+                        StringBuffer uriParams = new StringBuffer("?");
+                       
+                        while (paramIterator.hasNext()){
+                            OMElement parameter = (OMElement)paramIterator.next();
+                            uriParams.append(parameter.getAttributeValue(new QName("","name")));
+                            uriParams.append("=");
+                            uriParams.append(parameter.getText());
+                            
+                            if (paramIterator.hasNext()){
+                                uriParams.append("&");
+                            }
+                        }
+                        
+                        uri = uri + uriParams;
+                    }
+                }
+            }                     
+        } else {
+            uri = computeActualURI(BASE_HTTP_URI, component, contract).normalize().toString();
+        }
+        
         if (uri.endsWith("/")) {
             uri = uri.substring(0, uri.length() - 1);
         }
@@ -191,18 +237,24 @@
                 jmsSender = new JMSSender();
                 ListenerManager listenerManager = configContext.getListenerManager();
                 TransportInDescription trsIn = configContext.getAxisConfiguration().getTransportIn(Constants.TRANSPORT_JMS);
-
+                                
+                // get JMS transport parameters from the binding uri
                 Map<String, String> jmsProps = JMSUtils.getProperties( wsBinding.getURI() );
+
+                // collect the parameters used to configure the JMS transport
                 OMFactory fac = OMAbstractFactory.getOMFactory();
-                OMElement parms = fac.createOMElement(DEFAULT_QUEUE_CONENCTION_FACTORY, null);
+                OMElement parms = fac.createOMElement(DEFAULT_QUEUE_CONNECTION_FACTORY, null);                    
+
                 for ( String key : jmsProps.keySet() ) {
                     OMElement param = fac.createOMElement("parameter", null);
                     param.addAttribute( "name", key, null );
                     param.addChild(fac.createOMText(param, jmsProps.get(key)));
                     parms.addChild(param);
                 }
-                Parameter queueConnectionFactory = new Parameter(DEFAULT_QUEUE_CONENCTION_FACTORY, parms);
+                
+                Parameter queueConnectionFactory = new Parameter(DEFAULT_QUEUE_CONNECTION_FACTORY, parms);
                 trsIn.addParameter( queueConnectionFactory );
+                
                 trsIn.setReceiver(jmsListener);
 
                 configContext.getAxisConfiguration().addTransportIn( trsIn );
@@ -222,7 +274,6 @@
         } catch (AxisFault e) {
             throw new RuntimeException(e);
         }
-
     }
 
     public void stop() {
@@ -416,7 +467,7 @@
             AxisEndpoint ae = (AxisEndpoint)i.next();
             if (endpointURL.startsWith("jms") ) {
                 Parameter qcf = new Parameter(JMSConstants.CONFAC_PARAM, null);
-                qcf.setValue(DEFAULT_QUEUE_CONENCTION_FACTORY);
+                qcf.setValue(DEFAULT_QUEUE_CONNECTION_FACTORY);
                 axisService.addParameter(qcf);
                 break;
             }
@@ -548,6 +599,24 @@
     protected Binding getBinding() {
         return wsBinding;
     }
+    
+    private PolicySet getPolicySet(QName intentName){
+        PolicySet returnPolicySet = null;
+        
+        if ( wsBinding instanceof PolicySetAttachPoint ) {
+            PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)wsBinding; 
+            for ( PolicySet policySet : policiedBinding.getPolicySets() ) {
+                for (Intent intent : policySet.getProvidedIntents()){
+                    if ( intent.getName().equals(intentName) ){
+                        returnPolicySet = policySet;
+                        break;
+                    }
+                }
+            }
+        }
+        
+        return returnPolicySet;
+    } 
     
     private void configureSecurity() throws AxisFault {
         if ( wsBinding instanceof PolicySetAttachPoint ) {

Modified: incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml?rev=580908&r1=580907&r2=580908&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml (original)
+++ incubator/tuscany/java/sca/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml Mon Oct  1 02:47:50 2007
@@ -202,6 +202,26 @@
     
      <!-- Added by Tuscany -->
      <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">
+        <!--  These configuation parameters now come from the binding.ws uri
+              or from a policy set
+        <parameter name="myTopicConnectionFactory">
+            <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
+            <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
+            <parameter name="transport.jms.ConnectionFactoryJNDIName">TopicConnectionFactory</parameter>
+        </parameter>
+
+        <parameter name="myQueueConnectionFactory">
+            <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
+            <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
+            <parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter>
+        </parameter>
+
+        <parameter name="default">
+            <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
+            <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
+            <parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter>
+        </parameter>
+        -->
      </transportReceiver>
 
     <!-- ================================================= -->

Modified: incubator/tuscany/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/ws/Axis2ConfigParamPolicyProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/ws/Axis2ConfigParamPolicyProcessor.java?rev=580908&r1=580907&r2=580908&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/ws/Axis2ConfigParamPolicyProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/ws/Axis2ConfigParamPolicyProcessor.java Mon Oct  1 02:47:50 2007
@@ -106,7 +106,7 @@
         while (true) {
             switch (reader.next()) {
                 case XMLStreamConstants.START_ELEMENT:
-                	//since the axis2 code checks against a no namespace we need to generate accordingly
+                    //since the axis2 code checks against a no namespace we need to generate accordingly
                     QName name = new QName(reader.getName().getLocalPart());
                     OMElement child = fac.createOMElement(name, current);
 
@@ -129,9 +129,11 @@
                         String qname = reader.getAttributeLocalName(i);
                         String value = reader.getAttributeValue(i);
                         
-                        child.addAttribute(qname, value, fac.createOMNamespace(ns, prefix));
                         if (ns != null) {
+                            child.addAttribute(qname, value, fac.createOMNamespace(ns, prefix));
                             child.declareNamespace(ns, prefix);
+                        } else {
+                            child.addAttribute(qname, value, null);
                         }
                     }
                     current = child;

Added: incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/definitions.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/definitions.xml?rev=580908&view=auto
==============================================================================
--- incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/definitions.xml (added)
+++ incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/definitions.xml Mon Oct  1 02:47:50 2007
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * 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.    
+-->
+<sca:definitions xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ 			targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ 			xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ 			xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0">
+
+ <sca:intent name="transport"  
+ 			 constrains="sca:binding.ws">
+ 			 <sca:description>
+ 			 The general intent that a transport is available over which SOAP messages flow 
+ 			 </sca:description>
+ </sca:intent>
+
+ <sca:intent name="transport.jms">
+ 			 <sca:description>
+ 			 A JMS transport is required
+ 			 </sca:description>
+ </sca:intent>
+ 
+ <sca:intent name="transport.http">
+             <sca:description>
+             An HTTP transport is required
+             </sca:description>
+ </sca:intent>
+ 
+ <!-- 
+   how does the following relate to confidentiality intents 
+   does confidentiality become a profile intent?
+ -->
+ <sca:intent name="transport.https">
+             <sca:description>
+             An HTTPS transport is required
+             </sca:description>
+ </sca:intent>
+
+ <sca:policySet name="wsJMSTransportPolicy"
+ 	provides="transport.jms"
+ 	appliesTo="sca:binding.ws">
+ 	<tuscany:wsConfigParam>
+        <parameter name="TuscanyQueueConnectionFactory">
+            <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
+            <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter>
+            <parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter>
+        </parameter>
+ 	</tuscany:wsConfigParam>
+ </sca:policySet>
+ 
+ </sca:definitions>
\ No newline at end of file

Added: incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/helloworldwsjmspolicy.composite
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/helloworldwsjmspolicy.composite?rev=580908&view=auto
==============================================================================
--- incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/helloworldwsjmspolicy.composite (added)
+++ incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/helloworldwsjmspolicy.composite Mon Oct  1 02:47:50 2007
@@ -0,0 +1,33 @@
+<?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://www.osoa.org/xmlns/sca/1.0"
+	targetNamespace="http://helloworld"
+	xmlns:hw="http://helloworld"
+    name="helloworldws">
+
+    <component name="HelloWorldServiceComponent">
+        <implementation.java class="helloworld.HelloWorldImpl" />
+	    <service name="HelloWorldService">
+	        <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" />
+            <binding.ws wsdlElement="http://helloworld#wsdl.binding(HelloWorldSoapJmsBinding)" requires="transport.jms"/>
+        </service>
+    </component>
+
+</composite>

Added: incubator/tuscany/java/sca/samples/helloworld-ws-service/src/test/java/helloworld/HelloWorldJmsPolicyServerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/helloworld-ws-service/src/test/java/helloworld/HelloWorldJmsPolicyServerTestCase.java?rev=580908&view=auto
==============================================================================
--- incubator/tuscany/java/sca/samples/helloworld-ws-service/src/test/java/helloworld/HelloWorldJmsPolicyServerTestCase.java (added)
+++ incubator/tuscany/java/sca/samples/helloworld-ws-service/src/test/java/helloworld/HelloWorldJmsPolicyServerTestCase.java Mon Oct  1 02:47:50 2007
@@ -0,0 +1,61 @@
+/*
+ * 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 static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.net.Socket;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.apache.activemq.broker.BrokerService;
+
+/**
+ * Tests that the helloworld server is available
+ */
+public class HelloWorldJmsPolicyServerTestCase{
+
+    private SCADomain scaDomain;
+    private BrokerService broker = new BrokerService();
+
+    @Before
+    public void startServer() throws Exception {
+        broker.addConnector("tcp://localhost:61616");
+        broker.start();            
+        scaDomain = SCADomain.newInstance("helloworldwsjmspolicy.composite");
+    }
+
+    
+    @Test
+    public void testServiceCall() throws IOException {
+        HelloWorldService helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldServiceComponent/HelloWorldService");
+        assertNotNull(helloWorldService);
+        assertEquals("Hello Smith", helloWorldService.getGreetings("Smith"));
+    }
+ 
+    @After
+    public void stopServer() throws Exception {
+        scaDomain.close();
+        broker.stop();
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org