You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by pr...@apache.org on 2008/01/21 11:45:02 UTC

svn commit: r613838 - in /webservices/axis2/branches/java/jaxws21/modules/jaxws: src/org/apache/axis2/jaxws/addressing/util/ src/org/apache/axis2/jaxws/context/utils/ test-resources/xml/ test/org/apache/axis2/jaxws/addressing/util/ test/org/apache/axis...

Author: pradine
Date: Mon Jan 21 02:45:01 2008
New Revision: 613838

URL: http://svn.apache.org/viewvc?rev=613838&view=rev
Log:
Update support for the new MessageContext property to return the reference parameters from an incoming request message.

Added:
    webservices/axis2/branches/java/jaxws21/modules/jaxws/src/org/apache/axis2/jaxws/addressing/util/ReferenceParameterList.java
    webservices/axis2/branches/java/jaxws21/modules/jaxws/test-resources/xml/referenceparameters.xml
    webservices/axis2/branches/java/jaxws21/modules/jaxws/test/org/apache/axis2/jaxws/addressing/util/ReferenceParameterListTests.java
Modified:
    webservices/axis2/branches/java/jaxws21/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java
    webservices/axis2/branches/java/jaxws21/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java

Added: webservices/axis2/branches/java/jaxws21/modules/jaxws/src/org/apache/axis2/jaxws/addressing/util/ReferenceParameterList.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/jaxws/src/org/apache/axis2/jaxws/addressing/util/ReferenceParameterList.java?rev=613838&view=auto
==============================================================================
--- webservices/axis2/branches/java/jaxws21/modules/jaxws/src/org/apache/axis2/jaxws/addressing/util/ReferenceParameterList.java (added)
+++ webservices/axis2/branches/java/jaxws21/modules/jaxws/src/org/apache/axis2/jaxws/addressing/util/ReferenceParameterList.java Mon Jan 21 02:45:01 2008
@@ -0,0 +1,121 @@
+/*
+ * 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 org.apache.axis2.jaxws.addressing.util;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.handler.MessageContext;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.util.XMLUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Element;
+
+/**
+ * This class is used to provide a read-only list of reference parameters
+ * via the JAX-WS 2.1 api.
+ *
+ * @see MessageContext#REFERENCE_PARAMETERS
+ */
+public class ReferenceParameterList extends AbstractList<Element> {
+    private static final Log log = LogFactory.getLog(ReferenceParameterList.class);
+    private static final Element[] EMPTY_ARRAY = new Element[0];
+    
+    private String namespace = AddressingConstants.Final.WSA_NAMESPACE;
+    private SOAPHeader header;
+    private Element[] referenceParameters;
+
+    public ReferenceParameterList() {
+        super();
+    }
+    
+    public ReferenceParameterList(SOAPHeader header) {
+        super();
+        this.header = header;
+    }
+
+    @Override
+    public Element get(int index) {
+        if (referenceParameters == null)
+            initialize();
+        
+        return referenceParameters[index];
+    }
+
+    @Override
+    public int size() {
+        if (referenceParameters == null)
+            initialize();
+        
+        return referenceParameters.length;
+    }
+    
+    private void initialize() {
+        if (header == null) {
+            if (log.isTraceEnabled()) {
+                log.trace("initialize: No SOAP header to check for reference parameters.");
+            }
+            
+            referenceParameters = EMPTY_ARRAY;            
+        }
+        else {
+            if (log.isTraceEnabled()) {
+                log.trace("initialize: Checking SOAP header for reference parameters.");
+            }
+            
+            List<Element> list = new ArrayList<Element>();
+            Iterator headerBlocks = header.getChildElements();
+            while (headerBlocks.hasNext()) {
+                OMElement headerElement = (OMElement)headerBlocks.next();
+                OMAttribute isRefParamAttr =
+                        headerElement.getAttribute(new QName(namespace, "IsReferenceParameter"));
+                if (log.isTraceEnabled()) {
+                    log.trace("initialize: Checking header element: " + headerElement.getQName());
+                }
+                
+                if (isRefParamAttr != null && "true".equals(isRefParamAttr.getAttributeValue())) {
+                    try {
+                        Element element = XMLUtils.toDOM(headerElement);
+                        list.add(element);
+                    }
+                    catch (Exception e) {
+                        //TODO NLS enable.
+                        throw ExceptionFactory.makeWebServiceException("A problem occured during the building of the reference parameter list. See the nested exception for details.", e);
+                    }
+                    
+                    if (log.isTraceEnabled()) {
+                        log.trace("initialize: Header: " + headerElement.getQName() +
+                                " has IsReferenceParameter attribute. Adding to toEPR.");
+                    }
+                }
+            }
+            
+            referenceParameters = list.toArray(EMPTY_ARRAY);
+        }
+    }
+}

Modified: webservices/axis2/branches/java/jaxws21/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java?rev=613838&r1=613837&r2=613838&view=diff
==============================================================================
--- webservices/axis2/branches/java/jaxws21/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java (original)
+++ webservices/axis2/branches/java/jaxws21/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java Mon Jan 21 02:45:01 2008
@@ -18,10 +18,9 @@
  */
 package org.apache.axis2.jaxws.context.utils;
 
-import org.apache.axiom.om.OMElement;
-import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axiom.soap.SOAPHeader;
 import org.apache.axis2.context.ServiceContext;
-import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.addressing.util.ReferenceParameterList;
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.description.EndpointDescription;
 import org.apache.axis2.jaxws.description.EndpointInterfaceDescription;
@@ -30,7 +29,6 @@
 import org.apache.axis2.jaxws.description.ServiceDescriptionWSDL;
 import org.apache.axis2.jaxws.i18n.Messages;
 import org.apache.axis2.transport.http.HTTPConstants;
-import org.apache.axis2.util.XMLUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.w3c.dom.Element;
@@ -44,15 +42,12 @@
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
 
 
 public class ContextUtils {
     private static final Log log = LogFactory.getLog(ContextUtils.class);
     private static final String WEBSERVICE_MESSAGE_CONTEXT = "javax.xml.ws.WebServiceContext";
-    private static final OMElement[] ZERO_LENGTH_ARRAY = new OMElement[0];
 
     /**
      * Adds the appropriate properties to the MessageContext that the user will see
@@ -99,41 +94,19 @@
             }
         }
 
-        //Retrieve any reference parameters from the axis2 message context, and set
-        //them on the soap message context.
+        //Lazily provide a list of available reference parameters.
         org.apache.axis2.context.MessageContext msgContext =
             jaxwsMessageContext.getAxisMessageContext();
-        EndpointReference epr = msgContext.getTo();
-        Map<String, OMElement> referenceParameters = epr.getAllReferenceParameters();
+        SOAPHeader header = msgContext.getEnvelope().getHeader();
+        List<Element> list = new ReferenceParameterList(header);
         
-        if (referenceParameters != null) {
-        	OMElement[] omElements = referenceParameters.values().toArray(ZERO_LENGTH_ARRAY);
-        	List<Element> list = new ArrayList<Element>();
-        	
-        	try {
-        		for (OMElement omElement : omElements) {
-        			Element element = XMLUtils.toDOM(omElement);
-        			list.add(element);
-        		}
-        	}
-        	catch (Exception e) {
-                //TODO NLS enable.
-                throw ExceptionFactory.makeWebServiceException("Error during processing of reference parameters.", e);
-        	}
-        	            
-            soapMessageContext
-                    .put(javax.xml.ws.handler.MessageContext.REFERENCE_PARAMETERS, list);
-            soapMessageContext
-                    .setScope(javax.xml.ws.handler.MessageContext.REFERENCE_PARAMETERS, Scope.APPLICATION);
-
-            if (log.isDebugEnabled()) {
-                log.debug("Reference Parameters set.");
-            }
-        }
-        else {
-        	if (log.isDebugEnabled()) {
-      			log.debug("No Reference Parameters found.");
-        	}
+        soapMessageContext
+        .put(javax.xml.ws.handler.MessageContext.REFERENCE_PARAMETERS, list);
+        soapMessageContext
+        .setScope(javax.xml.ws.handler.MessageContext.REFERENCE_PARAMETERS, Scope.APPLICATION);
+        
+        if (log.isDebugEnabled()) {
+            log.debug("Added reference parameter list.");
         }
         
         // If we are running within a servlet container, then JAX-WS requires that the

Added: webservices/axis2/branches/java/jaxws21/modules/jaxws/test-resources/xml/referenceparameters.xml
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/jaxws/test-resources/xml/referenceparameters.xml?rev=613838&view=auto
==============================================================================
--- webservices/axis2/branches/java/jaxws21/modules/jaxws/test-resources/xml/referenceparameters.xml (added)
+++ webservices/axis2/branches/java/jaxws21/modules/jaxws/test-resources/xml/referenceparameters.xml Mon Jan 21 02:45:01 2008
@@ -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.
+  -->
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
+        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xmlns:wsa="http://www.w3.org/2005/08/addressing">
+    <soapenv:Header xmlns:fabrikam="http://example.com/fabrikam" xmlns:axis2="http://ws.apache.org/namespaces/axis2">
+        <wsa:MessageID axis2:AttrExt="123456789" soapenv:mustUnderstand="0">
+            uuid:920C5190-0B8F-11D9-8CED-F22EDEEBF7E5</wsa:MessageID>
+        <wsa:To axis2:AttrExt="123456789" soapenv:mustUnderstand="0">http://localhost:8081/axis/services/BankPort</wsa:To>
+        <axis2:ParamOne wsa:IsReferenceParameter='true'>0123456789</axis2:ParamOne>
+        <axis2:ParamTwo wsa:IsReferenceParameter='true'>ABCDEFG</axis2:ParamTwo>
+        <axis2:ParamThree wsa:IsReferenceParameter='true'>abcdefg</axis2:ParamThree>
+        <wsa:Action axis2:AttrExt="123456789">http://ws.apache.org/tests/action</wsa:Action>
+        <wsa:ReplyTo axis2:AttrExt="123456789">
+            <wsa:Address>http://example.com/fabrikam/acct</wsa:Address>
+            <wsa:ReferenceParameters>
+                <fabrikam:CustomerKey>123456789</fabrikam:CustomerKey>
+                <fabrikam:ShoppingCart>ABCDEFG</fabrikam:ShoppingCart>
+            </wsa:ReferenceParameters>
+            <wsa:Metadata>
+                <axis2:MetaExt axis2:AttrExt="123456789">123456789</axis2:MetaExt>
+            </wsa:Metadata>
+            <axis2:EPRExt axis2:AttrExt="123456789">123456789</axis2:EPRExt>
+        </wsa:ReplyTo>
+    </soapenv:Header>
+    <soapenv:Body>
+        <ns1:getBalance soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
+                xmlns:ns1="http://localhost:8081/axis/services/BankPort">
+            <accountNo href="#id0"/>
+        </ns1:getBalance>
+        <multiRef id="id0" soapenc:root="0"
+                soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
+                xsi:type="xsd:int" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
+            1001</multiRef>
+    </soapenv:Body>
+</soapenv:Envelope>
\ No newline at end of file

Added: webservices/axis2/branches/java/jaxws21/modules/jaxws/test/org/apache/axis2/jaxws/addressing/util/ReferenceParameterListTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/jaxws/test/org/apache/axis2/jaxws/addressing/util/ReferenceParameterListTests.java?rev=613838&view=auto
==============================================================================
--- webservices/axis2/branches/java/jaxws21/modules/jaxws/test/org/apache/axis2/jaxws/addressing/util/ReferenceParameterListTests.java (added)
+++ webservices/axis2/branches/java/jaxws21/modules/jaxws/test/org/apache/axis2/jaxws/addressing/util/ReferenceParameterListTests.java Mon Jan 21 02:45:01 2008
@@ -0,0 +1,76 @@
+/*
+ * 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 org.apache.axis2.jaxws.addressing.util;
+
+import java.io.File;
+import java.io.FileReader;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.axis2.jaxws.addressing.util.ReferenceParameterList;
+import org.w3c.dom.Element;
+
+public class ReferenceParameterListTests extends TestCase {
+    private String testResourceDir = System.getProperty("basedir", ".") + "/test-resources";
+    private String resourceFileName = "xml/referenceparameters.xml";
+    private SOAPHeader header;
+
+    public void setUp() throws Exception {
+        File resourceFile = new File(testResourceDir, resourceFileName);
+        XMLStreamReader parser = StAXUtils.createXMLStreamReader(new FileReader(resourceFile));
+        StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(parser, null);
+        header = ((SOAPEnvelope)builder.getDocumentElement()).getHeader();
+    }
+    
+    public void testReferenceParameterList() throws Exception {
+        List<Element> emptyList = new ReferenceParameterList();
+        assertTrue(emptyList.isEmpty());
+        assertEquals(0, emptyList.size());
+        
+        Set<String>results = new HashSet<String>();
+        results.add("0123456789");
+        results.add("ABCDEFG");
+        results.add("abcdefg");
+        
+        List<Element> rpList = new ReferenceParameterList(header);
+        assertFalse(rpList.isEmpty());
+        assertEquals(results.size(), rpList.size());
+
+        for (Element rp : rpList) {
+            String value = rp.getTextContent();
+            if (results.contains(value)) {
+                results.remove(value);
+            }
+            else {
+                fail("Value not recognized: " + value);
+            }
+        }
+        
+        assertEquals(0, results.size());
+    }
+}

Modified: webservices/axis2/branches/java/jaxws21/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/jaxws21/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java?rev=613838&r1=613837&r2=613838&view=diff
==============================================================================
--- webservices/axis2/branches/java/jaxws21/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java (original)
+++ webservices/axis2/branches/java/jaxws21/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java Mon Jan 21 02:45:01 2008
@@ -24,6 +24,7 @@
 import junit.framework.TestSuite;
 
 import org.apache.axis2.jaxws.addressing.util.EndpointReferenceUtilsTests;
+import org.apache.axis2.jaxws.addressing.util.ReferenceParameterListTests;
 import org.apache.axis2.jaxws.anytype.tests.AnyTypeTests;
 import org.apache.axis2.jaxws.attachments.MTOMSerializationTests;
 import org.apache.axis2.jaxws.client.ClientConfigTests;
@@ -138,6 +139,7 @@
         
         // ------ Addressing Tests ------
         //suite.addTestSuite(EndpointReferenceUtilsTests.class);
+        suite.addTestSuite(ReferenceParameterListTests.class);
         
         // ------ Metadata Tests ------
         suite.addTestSuite(WSDLTests.class);



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