axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davidills...@apache.org
Subject svn commit: r615819 - in /webservices/axis2/trunk/java/modules: addressing/src/org/apache/axis2/handlers/addressing/ addressing/test-resources/ addressing/test/org/apache/axis2/handlers/addressing/ kernel/src/org/apache/axis2/addressing/
Date Mon, 28 Jan 2008 09:44:32 GMT
Author: davidillsley
Date: Mon Jan 28 01:44:31 2008
New Revision: 615819

URL: http://svn.apache.org/viewvc?rev=615819&view=rev
Log:
Add client side support for WS-A headers w/soap:role

Added:
    webservices/axis2/trunk/java/modules/addressing/test-resources/soap11roleTest.xml
    webservices/axis2/trunk/java/modules/addressing/test-resources/soap12roleTest.xml
Modified:
    webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
    webservices/axis2/trunk/java/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingOutHandlerTest.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/AddressingConstants.java

Modified: webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java?rev=615819&r1=615818&r2=615819&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
(original)
+++ webservices/axis2/trunk/java/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
Mon Jan 28 01:44:31 2008
@@ -24,6 +24,8 @@
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.util.AttributeHelper;
 import org.apache.axiom.om.util.ElementHelper;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axiom.soap.SOAPFactory;
 import org.apache.axiom.soap.SOAPFault;
@@ -92,10 +94,13 @@
         // Lets have a parameter to control that. The default behavior is you won't replace
addressing
         // headers if there are any (this was the case so far).
         boolean replaceHeaders = msgContext.isPropertyTrue(REPLACE_ADDRESSING_HEADERS);
+        
+        // Allow the user to specify the role these WS-Addressing headers should be targetted
at.
+        String role = (String) msgContext.getProperty(SOAP_ROLE_FOR_ADDRESSING_HEADERS);
 
         WSAHeaderWriter writer = new WSAHeaderWriter(msgContext, isSubmissionNamespace,
                                                      addMustUnderstandAttribute, replaceHeaders,
-                                                     includeOptionalHeaders);
+                                                     includeOptionalHeaders, role);
         writer.writeHeaders();
 
         return InvocationResponse.CONTINUE;
@@ -110,6 +115,7 @@
         private Options messageContextOptions;
         private OMNamespace addressingNamespaceObject;
         private String addressingNamespace;
+        private String addressingRole;
 
         private boolean isFinalAddressingNamespace;
         private boolean addMustUnderstandAttribute;
@@ -119,10 +125,10 @@
         private ArrayList existingWSAHeaders = null;
         
         public WSAHeaderWriter(MessageContext mc, boolean isSubmissionNamespace, boolean
addMU,
-                               boolean replace, boolean includeOptional) {
+                               boolean replace, boolean includeOptional, String role) {
             if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) {
                 log.debug("WSAHeaderWriter: isFinal=" + isSubmissionNamespace + " addMU="
+ addMU +
-                        " replace=" + replace + " includeOptional=" + includeOptional);
+                        " replace=" + replace + " includeOptional=" + includeOptional+" role="+role);
             }
 
             messageContext = mc;
@@ -143,16 +149,22 @@
             	if(addressingHeaders!=null && !addressingHeaders.isEmpty()){
             		existingWSAHeaders = new ArrayList(addressingHeaders.size());
             		for(Iterator iter=addressingHeaders.iterator();iter.hasNext();){
-            			OMElement oe = (OMElement)iter.next();
-            			existingWSAHeaders.add(oe.getLocalName());
+            			SOAPHeaderBlock oe = (SOAPHeaderBlock)iter.next();
+            			if(addressingRole == null || addressingRole.length() ==0 || addressingRole.equals(oe.getRole())){
+            				existingWSAHeaders.add(oe.getLocalName());
+            			}
             		}
             	}
+            	if(addressingHeaders != null && addressingHeaders.size() ==0){
+            		addressingHeaders = null;
+            	}
             }
             
             isFinalAddressingNamespace = !isSubmissionNamespace;
             addMustUnderstandAttribute = addMU;
             replaceHeaders = replace;
             includeOptionalHeaders = includeOptional;
+            addressingRole = role;
         }
 
         public void writeHeaders() throws AxisFault {
@@ -387,6 +399,7 @@
                                 .importOMAttribute((OMAttribute)attrIterator.next(), soapHeaderBlock);
                     }
                 }
+                addRoleToHeader(soapHeaderBlock);
                 return soapHeaderBlock;
             }
             return null;
@@ -428,6 +441,7 @@
                                                                      new QName(addressingNamespace,
                                                                                headerName,
prefix),
                                                                      addressingNamespace);
+            addRoleToHeader(soapHeaderBlock);
             header.addChild(soapHeaderBlock);
         }
 
@@ -452,6 +466,7 @@
                                                Final.WSA_TYPE_ATTRIBUTE_VALUE,
                                                addressingNamespaceObject);
                     }
+                    addRoleToHeader(newElement);
                     header.addChild(newElement);
                 }
             }
@@ -474,6 +489,7 @@
             							Final.WSA_TYPE_ATTRIBUTE_VALUE,
             							addressingNamespaceObject);
             				}
+            				addRoleToHeader(newElement);
             				header.addChild(newElement);
             			}
             		}
@@ -557,7 +573,23 @@
                 }
             }
         }
+        
+        private void addRoleToHeader(OMElement header){
+        	if(addressingRole == null || addressingRole.length()==0){
+        		return;
+        	}
+        	if(header instanceof SOAPHeaderBlock){
+        		((SOAPHeaderBlock)header).setRole(addressingRole);
+        	}else{
+        		if(messageContext.isSOAP11()){
+        			OMAttribute roleAttr = factory.createOMAttribute(SOAP11Constants.ATTR_ACTOR, envelope.getNamespace(),
addressingRole);
+        			header.addAttribute(roleAttr);
+        		}else{
+        			OMAttribute roleAttr = factory.createOMAttribute(SOAP12Constants.SOAP_ROLE, envelope.getNamespace(),
addressingRole);
+        			header.addAttribute(roleAttr);
+        		}
+        	}
+        }
     }
-
 }
 

Added: webservices/axis2/trunk/java/modules/addressing/test-resources/soap11roleTest.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/addressing/test-resources/soap11roleTest.xml?rev=615819&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/addressing/test-resources/soap11roleTest.xml (added)
+++ webservices/axis2/trunk/java/modules/addressing/test-resources/soap11roleTest.xml Mon
Jan 28 01:44:31 2008
@@ -0,0 +1,38 @@
+<!--
+  ~ 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.
+  -->
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
+    <soapenv:Header xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:myRef="http://reference.org">
+        <wsa:From soapenv:actor="urn:test:role">
+            <wsa:Address>http://www.from.org/service/</wsa:Address>
+            <wsa:ReferenceParameters>
+                <Reference2>Value 200</Reference2>
+            </wsa:ReferenceParameters>
+        </wsa:From>
+        <wsa:To soapenv:actor="urn:test:role">http://www.to.org/service/</wsa:To>
+        <wsa:MessageID soapenv:actor="urn:test:role">123456-7890</wsa:MessageID>
+        <myRef:Reference4 soapenv:actor="urn:test:role">Value 400</myRef:Reference4>
+        <myRef:Reference3 soapenv:actor="urn:test:role">Value 300</myRef:Reference3>
+        <wsa:Action soapenv:actor="urn:test:role">http://www.actions.org/action</wsa:Action>
+        <wsa:ReplyTo soapenv:actor="urn:test:role">
+            <wsa:Address>http://www.replyTo.org/service/</wsa:Address>
+        </wsa:ReplyTo>
+        <wsa:RelatesTo soapenv:actor="urn:test:role" RelationshipType="TestRelation">http://www.relatesTo.org/service/</wsa:RelatesTo>
+    </soapenv:Header>
+    <soapenv:Body></soapenv:Body>
+</soapenv:Envelope>

Added: webservices/axis2/trunk/java/modules/addressing/test-resources/soap12roleTest.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/addressing/test-resources/soap12roleTest.xml?rev=615819&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/addressing/test-resources/soap12roleTest.xml (added)
+++ webservices/axis2/trunk/java/modules/addressing/test-resources/soap12roleTest.xml Mon
Jan 28 01:44:31 2008
@@ -0,0 +1,38 @@
+<!--
+  ~ 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.
+  -->
+<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
+    <soapenv:Header xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:myRef="http://reference.org">
+        <wsa:From soapenv:role="urn:test:role">
+            <wsa:Address>http://www.from.org/service/</wsa:Address>
+            <wsa:ReferenceParameters>
+                <Reference2>Value 200</Reference2>
+            </wsa:ReferenceParameters>
+        </wsa:From>
+        <wsa:To soapenv:role="urn:test:role">http://www.to.org/service/</wsa:To>
+        <wsa:MessageID soapenv:role="urn:test:role">123456-7890</wsa:MessageID>
+        <myRef:Reference4 soapenv:role="urn:test:role">Value 400</myRef:Reference4>
+        <myRef:Reference3 soapenv:role="urn:test:role">Value 300</myRef:Reference3>
+        <wsa:Action soapenv:role="urn:test:role">http://www.actions.org/action</wsa:Action>
+        <wsa:ReplyTo soapenv:role="urn:test:role">
+            <wsa:Address>http://www.replyTo.org/service/</wsa:Address>
+        </wsa:ReplyTo>
+        <wsa:RelatesTo soapenv:role="urn:test:role" RelationshipType="TestRelation">http://www.relatesTo.org/service/</wsa:RelatesTo>
+    </soapenv:Header>
+    <soapenv:Body></soapenv:Body>
+</soapenv:Envelope>

Modified: webservices/axis2/trunk/java/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingOutHandlerTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingOutHandlerTest.java?rev=615819&r1=615818&r2=615819&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingOutHandlerTest.java
(original)
+++ webservices/axis2/trunk/java/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingOutHandlerTest.java
Mon Jan 28 01:44:31 2008
@@ -194,6 +194,96 @@
                                               .getDocumentElement()));
     }
 
+    public void testSOAPRoleSupport() throws Exception {
+        ConfigurationContext cfgCtx =
+                ConfigurationContextFactory.createDefaultConfigurationContext();
+        msgCtxt = cfgCtx.createMessageContext();
+
+        msgCtxt.setProperty(AddressingConstants.SOAP_ROLE_FOR_ADDRESSING_HEADERS,
+                            "urn:test:role");
+
+        EndpointReference epr = new EndpointReference("http://www.from.org/service/");
+        epr.addReferenceParameter(new QName("Reference2"),
+                                  "Value 200");
+        msgCtxt.setFrom(epr);
+
+        epr = new EndpointReference("http://www.to.org/service/");
+        epr.addReferenceParameter(
+                new QName("http://reference.org", "Reference4", "myRef"),
+                "Value 400");
+        epr.addReferenceParameter(
+                new QName("http://reference.org", "Reference3", "myRef"),
+                "Value 300");
+
+        msgCtxt.setTo(epr);
+        msgCtxt.setProperty(WS_ADDRESSING_VERSION, Submission.WSA_NAMESPACE);
+
+        epr = new EndpointReference("http://www.replyTo.org/service/");
+        msgCtxt.setReplyTo(epr);
+
+        msgCtxt.setMessageID("123456-7890");
+        msgCtxt.setWSAAction("http://www.actions.org/action");
+
+        org.apache.axis2.addressing.RelatesTo relatesTo = new org.apache.axis2.addressing.RelatesTo(
+                "http://www.relatesTo.org/service/", "TestRelation");
+        msgCtxt.addRelatesTo(relatesTo);
+
+        msgCtxt.setEnvelope(
+                OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope());
+        outHandler.invoke(msgCtxt);
+
+        XMLComparator xmlComparator = new XMLComparator();
+        assertTrue(
+                xmlComparator.compare(msgCtxt.getEnvelope(),
+                                      testUtil.getOMBuilder("soap11roleTest.xml")
+                                              .getDocumentElement()));
+    }
+    
+    public void testSOAP12RoleSupport() throws Exception {
+        ConfigurationContext cfgCtx =
+                ConfigurationContextFactory.createDefaultConfigurationContext();
+        msgCtxt = cfgCtx.createMessageContext();
+
+        msgCtxt.setProperty(AddressingConstants.SOAP_ROLE_FOR_ADDRESSING_HEADERS,
+                            "urn:test:role");
+
+        EndpointReference epr = new EndpointReference("http://www.from.org/service/");
+        epr.addReferenceParameter(new QName("Reference2"),
+                                  "Value 200");
+        msgCtxt.setFrom(epr);
+
+        epr = new EndpointReference("http://www.to.org/service/");
+        epr.addReferenceParameter(
+                new QName("http://reference.org", "Reference4", "myRef"),
+                "Value 400");
+        epr.addReferenceParameter(
+                new QName("http://reference.org", "Reference3", "myRef"),
+                "Value 300");
+
+        msgCtxt.setTo(epr);
+        msgCtxt.setProperty(WS_ADDRESSING_VERSION, Submission.WSA_NAMESPACE);
+
+        epr = new EndpointReference("http://www.replyTo.org/service/");
+        msgCtxt.setReplyTo(epr);
+
+        msgCtxt.setMessageID("123456-7890");
+        msgCtxt.setWSAAction("http://www.actions.org/action");
+
+        org.apache.axis2.addressing.RelatesTo relatesTo = new org.apache.axis2.addressing.RelatesTo(
+                "http://www.relatesTo.org/service/", "TestRelation");
+        msgCtxt.addRelatesTo(relatesTo);
+
+        msgCtxt.setEnvelope(
+                OMAbstractFactory.getSOAP12Factory().getDefaultEnvelope());
+        outHandler.invoke(msgCtxt);
+
+        XMLComparator xmlComparator = new XMLComparator();
+        assertTrue(
+                xmlComparator.compare(msgCtxt.getEnvelope(),
+                                      testUtil.getOMBuilder("soap12roleTest.xml")
+                                              .getDocumentElement()));
+    }
+    
     public void testDuplicateHeaders() throws Exception {
 
         // this will check whether we can add to epr, if there is one already.

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/AddressingConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/AddressingConstants.java?rev=615819&r1=615818&r2=615819&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/AddressingConstants.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/addressing/AddressingConstants.java
Mon Jan 28 01:44:31 2008
@@ -77,6 +77,8 @@
     static final String ADD_MUST_UNDERSTAND_TO_ADDRESSING_HEADERS =
             "addMustUnderstandToAddressingHeaders";
 
+    static final String SOAP_ROLE_FOR_ADDRESSING_HEADERS = "wsaddressingRole";
+    
     /**
      * A property pointing to an ArrayList of OMAttribute objects representing any attributes
      * of the wsa:Action header.



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


Mime
View raw message