Author: barrettj
Date: Fri Apr 30 19:12:58 2010
New Revision: 939784

URL: http://svn.apache.org/viewvc?rev=939784&view=rev
Log:
AXIS2-4699, patch submitted by Katherine Sanders.  Add new 
Provider.createW3CEndpointReference method for JAXWS 2.2.

Added:
    axis/axis2/java/core/trunk/modules/jaxws/test-resources/wsdl/Echo.wsdl
    axis/axis2/java/core/trunk/modules/jaxws/test-resources/wsdl/Invalid.wsdl
    
axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/spi/ProviderTests.java
Modified:
    
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/addressing/util/EndpointReferenceUtils.java
    
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/spi/Provider.java

Modified: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/addressing/util/EndpointReferenceUtils.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/addressing/util/EndpointReferenceUtils.java?rev=939784&r1=939783&r2=939784&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/addressing/util/EndpointReferenceUtils.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/addressing/util/EndpointReferenceUtils.java
 Fri Apr 30 19:12:58 2010
@@ -22,6 +22,7 @@ package org.apache.axis2.jaxws.addressin
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.addressing.EndpointReferenceHelper;
 import org.apache.axis2.addressing.metadata.InterfaceName;
@@ -39,6 +40,8 @@ import javax.xml.transform.stream.Stream
 import javax.xml.transform.stream.StreamSource;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.util.List;
+import java.util.Map;
 
 public final class EndpointReferenceUtils {
     
@@ -164,6 +167,34 @@ public final class EndpointReferenceUtil
     /**
      * 
      * @param axis2EPR
+     * @param elements
+     * @throws Exception
+     */
+    public static void addExtensibleElements(EndpointReference axis2EPR, 
Element... elements)
+    throws Exception {
+        if (elements != null) {
+            for (Element element : elements) {
+                OMElement omElement = XMLUtils.toOM(element);
+                axis2EPR.addExtensibleElement(omElement);
+            }
+        }
+    }
+    
+    public static void addExtensibleAttributes(EndpointReference axis2EPR, 
Map<QName, String> attributes)
+    throws Exception {
+        if (attributes != null) {
+            OMFactory fac = OMAbstractFactory.getOMFactory();
+            for (Map.Entry<QName, String> attribute : attributes.entrySet()) {
+                QName qName = attribute.getKey();
+                OMNamespace omNamespace = 
fac.createOMNamespace(qName.getNamespaceURI(), qName.getPrefix());
+                axis2EPR.addAttribute(qName.getLocalPart(), omNamespace, 
attribute.getValue());
+            }
+        }
+    }
+    
+    /**
+     * 
+     * @param axis2EPR
      * @param metadata
      * @throws Exception
      */

Modified: 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/spi/Provider.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/spi/Provider.java?rev=939784&r1=939783&r2=939784&view=diff
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/spi/Provider.java
 (original)
+++ 
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/spi/Provider.java
 Fri Apr 30 19:12:58 2010
@@ -40,6 +40,7 @@ import javax.xml.ws.spi.ServiceDelegate;
 import javax.xml.ws.wsaddressing.W3CEndpointReference;
 import java.net.URL;
 import java.util.List;
+import java.util.Map;
 
 public class Provider extends javax.xml.ws.spi.Provider {
     private static final Log log = LogFactory.getLog(Provider.class);
@@ -114,6 +115,51 @@ public class Provider extends javax.xml.
         
         return w3cEPR;
     }
+    
+    @Override
+    public W3CEndpointReference createW3CEndpointReference(String address,
+            QName interfaceName, 
+            QName serviceName,
+            QName portName,
+            List<Element> metadata,
+            String wsdlDocumentLocation,
+            List<Element> referenceParameters,
+            List<Element> elements,
+            Map<QName, String> attributes) {
+        String addressingNamespace =
+            
EndpointReferenceUtils.getAddressingNamespace(W3CEndpointReference.class);      
+        org.apache.axis2.addressing.EndpointReference axis2EPR =
+            EndpointReferenceUtils.createAxis2EndpointReference(address, 
serviceName, portName, wsdlDocumentLocation, addressingNamespace);
+        
+        W3CEndpointReference w3cEPR = null;
+        
+        try {
+            if (interfaceName != null)
+                EndpointReferenceUtils.addInterface(axis2EPR, interfaceName, 
addressingNamespace);
+            
+            if (metadata != null)
+                EndpointReferenceUtils.addMetadata(axis2EPR, 
metadata.toArray(ZERO_LENGTH_ARRAY));
+            
+            if (referenceParameters != null)
+                EndpointReferenceUtils.addReferenceParameters(axis2EPR, 
referenceParameters.toArray(ZERO_LENGTH_ARRAY));
+            
+            if (elements != null)
+                EndpointReferenceUtils.addExtensibleElements(axis2EPR, 
elements.toArray(ZERO_LENGTH_ARRAY));
+            
+            if (attributes != null)
+                EndpointReferenceUtils.addExtensibleAttributes(axis2EPR, 
attributes);
+            
+            w3cEPR =
+                (W3CEndpointReference) 
EndpointReferenceUtils.convertFromAxis2(axis2EPR, addressingNamespace);
+        }
+        catch (Exception e) {
+            throw ExceptionFactory.
+              
makeWebServiceException(Messages.getMessage("referenceParameterConstructionErr"),
+                                    e);
+        }
+        
+        return w3cEPR;
+    }
 
     @Override
     public <T> T getPort(EndpointReference jaxwsEPR, Class<T> sei, 
WebServiceFeature... features) {

Added: axis/axis2/java/core/trunk/modules/jaxws/test-resources/wsdl/Echo.wsdl
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/test-resources/wsdl/Echo.wsdl?rev=939784&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws/test-resources/wsdl/Echo.wsdl 
(added)
+++ axis/axis2/java/core/trunk/modules/jaxws/test-resources/wsdl/Echo.wsdl Fri 
Apr 30 19:12:58 2010
@@ -0,0 +1,82 @@
+<?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.
+  -->
+<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
+                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
+                  xmlns:tns="http://org/apache/axis2/jaxws/samples/echo/";
+                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
name="EchoService"
+                  
targetNamespace="http://org/apache/axis2/jaxws/samples/echo/";>
+    <wsdl:types>
+        <xsd:schema
+                targetNamespace="http://org/apache/axis2/jaxws/samples/echo/";
+                xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
+
+
+            <xsd:element name="echoStringResponse">
+                <xsd:complexType>
+                    <xsd:sequence>
+                        <xsd:element name="echoResponse"
+                                     type="xsd:string"/>
+                    </xsd:sequence>
+                </xsd:complexType>
+            </xsd:element>
+
+            <xsd:element name="echoStringInput">
+                <xsd:complexType>
+                    <xsd:sequence>
+                        <xsd:element name="echoInput" type="xsd:string"/>
+                    </xsd:sequence>
+                </xsd:complexType>
+            </xsd:element>
+
+        </xsd:schema>
+    </wsdl:types>
+    <wsdl:message name="echoOperationRequest">
+        <wsdl:part element="tns:echoStringInput" name="parameter"/>
+    </wsdl:message>
+    <wsdl:message name="echoOperationResponse">
+        <wsdl:part element="tns:echoStringResponse" name="parameter"/>
+    </wsdl:message>
+    <wsdl:portType name="EchoServicePortType">
+
+        <wsdl:operation name="echoOperation">
+            <wsdl:input message="tns:echoOperationRequest"/>
+            <wsdl:output message="tns:echoOperationResponse"/>
+        </wsdl:operation>
+    </wsdl:portType>
+    <wsdl:binding name="EchoSOAP" type="tns:EchoServicePortType">
+        <soap:binding style="document"
+                      transport="http://schemas.xmlsoap.org/soap/http"/>
+        <wsdl:operation name="echoOperation">
+            <soap:operation soapAction="echoOperation" style="document"/>
+            <wsdl:input>
+                <soap:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap:body use="literal"/>
+            </wsdl:output>
+        </wsdl:operation>
+    </wsdl:binding>
+    <wsdl:service name="EchoService">
+        <wsdl:port binding="tns:EchoSOAP" name="EchoServicePort">
+            <soap:address
+                    
location="http://localhost:8080/jaxws-samples/services/EchoService"/>
+        </wsdl:port>
+    </wsdl:service>
+</wsdl:definitions>

Added: axis/axis2/java/core/trunk/modules/jaxws/test-resources/wsdl/Invalid.wsdl
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/test-resources/wsdl/Invalid.wsdl?rev=939784&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws/test-resources/wsdl/Invalid.wsdl 
(added)
+++ axis/axis2/java/core/trunk/modules/jaxws/test-resources/wsdl/Invalid.wsdl 
Fri Apr 30 19:12:58 2010
@@ -0,0 +1,26 @@
+<?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.
+  -->
+<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/";
+                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/";
+                  xmlns:tns="http://org/apache/axis2/jaxws/samples/echo/";
+                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"; 
name="EchoService"
+                  
targetNamespace="http://org/apache/axis2/jaxws/samples/echo/";>
+
+</wsdl:definitions>

Added: 
axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/spi/ProviderTests.java
URL: 
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/spi/ProviderTests.java?rev=939784&view=auto
==============================================================================
--- 
axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/spi/ProviderTests.java
 (added)
+++ 
axis/axis2/java/core/trunk/modules/jaxws/test/org/apache/axis2/jaxws/spi/ProviderTests.java
 Fri Apr 30 19:12:58 2010
@@ -0,0 +1,191 @@
+/*
+ * 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.spi;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.ws.wsaddressing.W3CEndpointReference;
+
+import org.apache.axis2.util.XMLUtils;
+import org.custommonkey.xmlunit.XMLTestCase;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class ProviderTests  extends XMLTestCase {
+    Provider provider = new Provider();
+    W3CEndpointReference w3cEpr;
+    String address = 
"http://localhost:8080/jaxws-samples/services/EchoService";;
+    QName interfaceName = new 
QName("http://org/apache/axis2/jaxws/samples/echo/";, "EchoServicePortType", 
"tns");
+    QName serviceName = new 
QName("http://org/apache/axis2/jaxws/samples/echo/";, "EchoService", "tns");
+    QName portName = new QName("http://org/apache/axis2/jaxws/samples/echo/";, 
"EchoServicePort", "tns");
+    String wsdlDocumentLocation = 
getClass().getResource("/wsdl/Echo.wsdl").toExternalForm();
+    
+    List<Element> metadata = new ArrayList<Element>();
+    List<Element> referenceParameters = new ArrayList<Element>();
+    List<Element> elements = new ArrayList<Element>();
+    Map<QName,String> attributes = new HashMap<QName,String>();
+    
+    /* Test the new createW3CEndpointReference method added for JAX-WS 2.2 */
+    
+    public void test22CreateW3CEndpointReferenceAllNull() {
+        try {
+            w3cEpr = provider.createW3CEndpointReference(null, null, null, 
null, null, null, null, null, null);
+        } catch (IllegalStateException e) {
+            // Expected Exception - address, serviceName and portName are all 
null
+            return;
+        }
+        fail("Did not catch expected IllegalStateException");
+    }
+       
+    public void test22CreateW3CEndpointReferenceServiceAndPortName() {
+        try {
+            w3cEpr = provider.createW3CEndpointReference(null, null, 
serviceName, portName, null, null, null, null, null);
+        } catch (IllegalStateException e) {
+            // Expected Exception - address property is null and the 
serviceName and portName do not specify a valid endpoint published by the same 
Java EE application. 
+            return;
+        }
+        fail("Did not catch expected IllegalStateException");
+    }
+    
+    public void test22CreateW3CEndpointReferenceAddressPortName() {
+        try {
+            w3cEpr = provider.createW3CEndpointReference(address, null, null, 
portName, null, null, null, null, null);
+        } catch (IllegalStateException e) {
+            // Expected Exception - serviceName service is null and the 
portName is NOT null
+            return;
+        }
+        fail("Did not catch expected IllegalStateException");
+    }
+    
+    public void test22CreateW3CEndpointReferenceServiceNotInWSDL() {
+        try {
+            w3cEpr = provider.createW3CEndpointReference(address, 
interfaceName, new QName("UnknownService"), portName, null, 
wsdlDocumentLocation, null, null, null);
+        } catch (IllegalStateException e) {
+            // Expected Exception - serviceName is NOT null and is not present 
in the specified WSDL
+            return;
+        }
+        fail("Did not catch expected IllegalStateException");
+    }
+    
+    public void test22CreateW3CEndpointReferencePortNameNotInWSDL() {
+        try {
+            w3cEpr = provider.createW3CEndpointReference(address, 
interfaceName, serviceName, new QName("UnknownPort"), null, 
wsdlDocumentLocation, null, null, null);
+        } catch (IllegalStateException e) {
+            // Expected Exception - portName port is not null and it is not 
present in serviceName service in the WSDL
+            return;
+        }
+        fail("Did not catch expected IllegalStateException");
+    }
+    
+    public void test22CreateW3CEndpointReferenceInvalidWSDL() {
+        try {
+            w3cEpr = provider.createW3CEndpointReference(address, 
interfaceName, serviceName, portName, null, 
getClass().getResource("/wsdl/Invalid.wsdl").toExternalForm(), null, null, 
null);
+        } catch (IllegalStateException e) {
+            // Expected Exception - wsdlDocumentLocation is NOT null and does 
not represent a valid WSDL
+            return;
+        }
+        fail("Did not catch expected IllegalStateException");
+    }
+    
+    public void test22CreateW3CEndpointReferenceMissingWSDLLocationNamespace() 
{
+        try {
+            w3cEpr = provider.createW3CEndpointReference(address, null, new 
QName("EchoService"), new QName("EchoServicePort"), null, wsdlDocumentLocation, 
null, null, null);
+            System.out.println(w3cEpr);
+        } catch (IllegalStateException e) {
+            // Expected Exception - wsdlDocumentLocation is NOT null but 
wsdli:wsdlLocation's namespace name cannot be got from the available metadata
+            return;
+        }
+        fail("Did not catch expected IllegalStateException");
+    }
+    
+    public void test22CreateW3CEndpointReferenceOnlyAddress() throws Exception 
{
+        XMLUnit.setIgnoreWhitespace(true);
+        try {
+            w3cEpr = provider.createW3CEndpointReference(address, null, null, 
null, null, null, null, null, null);
+            
+            String expectedEPR = "<EndpointReference 
xmlns=\"http://www.w3.org/2005/08/addressing\";>" +
+                                     
"<Address>http://localhost:8080/jaxws-samples/services/EchoService</Address>"+
+                                 "</EndpointReference>";
+            
+            assertXMLEqual(expectedEPR, w3cEpr.toString());
+        } finally {
+            XMLUnit.setIgnoreWhitespace(false);
+        }
+    }
+    
+    public void test22CreateW3CEndpointReference() throws Exception {
+        XMLUnit.setIgnoreWhitespace(true);
+        try {
+            Document doc = XMLUtils.newDocument();
+            
+            // Create metadata
+            Element metadata1 = doc.createElementNS("http://test.com";, 
"test:testMetadata1");
+            metadata.add(metadata1);
+            Element metadata2 = doc.createElementNS("http://test.com";, 
"test:testMetadata2");
+            metadata.add(metadata2);
+            
+            // Create reference parameters
+            Element key = doc.createElementNS("http://example.com/fabrikam";, 
"fabrikam:CustomerKey");
+            key.appendChild(doc.createTextNode("123456789"));
+            referenceParameters.add(key);
+            Element cart = doc.createElementNS("http://example.com/fabrikam";, 
"fabrikam:ShoppingCart");
+            cart.appendChild(doc.createTextNode("ABCDEFG"));
+            referenceParameters.add(cart);
+            
+            // Create elements
+            Element element1 = doc.createElementNS("http://test.com";, 
"test:testElement1");
+            elements.add(element1);
+            Element element2 = doc.createElementNS("http://test.com";, 
"test:testElement2");
+            elements.add(element2);
+            
+            // Create attributes
+            attributes.put(new QName("http://test.com";, "attribute1", "test"), 
"value1");
+            attributes.put(new QName("http://test.com";, "attribute2", "test"), 
"value2");
+            
+            w3cEpr = provider.createW3CEndpointReference(address, 
interfaceName, serviceName, portName, metadata, wsdlDocumentLocation, 
referenceParameters, elements, attributes);
+            
+            // Cannot put EPR in an external file since absolute WSDL location 
cannot be hard coded
+            String expectedEPR = "<EndpointReference 
test:attribute1=\"value1\" test:attribute2=\"value2\" 
xmlns=\"http://www.w3.org/2005/08/addressing\"; xmlns:test=\"http://test.com\";>" 
+
+                                     
"<Address>http://localhost:8080/jaxws-samples/services/EchoService</Address>" +
+                                     "<ReferenceParameters 
xmlns:fabrikam=\"http://example.com/fabrikam\";>" +
+                                         
"<fabrikam:CustomerKey>123456789</fabrikam:CustomerKey>" +
+                                         
"<fabrikam:ShoppingCart>ABCDEFG</fabrikam:ShoppingCart>" +
+                                     "</ReferenceParameters>" +
+                                     "<Metadata 
xmlns:wsam=\"http://www.w3.org/2007/05/addressing/metadata\"; 
xmlns:tns=\"http://org/apache/axis2/jaxws/samples/echo/\"; 
xmlns:wsdli=\"http://www.w3.org/ns/wsdl-instance\"; 
wsdli:wsdlLocation=\"http://org/apache/axis2/jaxws/samples/echo/ " + 
wsdlDocumentLocation + "\">" +
+                                         "<wsam:ServiceName 
EndpointName=\"EchoServicePort\">tns:EchoService</wsam:ServiceName>" +
+                                         
"<wsam:InterfaceName>tns:EchoServicePortType</wsam:InterfaceName>" +
+                                         "<test:testMetadata1/>" +
+                                         "<test:testMetadata2/>" +
+                                     "</Metadata>" +
+                                     "<test:testElement1/>" +
+                                     "<test:testElement2/>" +
+                                 "</EndpointReference>";
+            
+            assertXMLEqual(expectedEPR, w3cEpr.toString());
+        } finally {
+            XMLUnit.setIgnoreWhitespace(false);
+        }
+    }
+}


Reply via email to