cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r992684 - in /cxf/trunk/rt/frontend/jaxws/src: main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java test/java/org/apache/cxf/jaxws/spi/ProviderImplTest.java
Date Sat, 04 Sep 2010 21:31:02 GMT
Author: sergeyb
Date: Sat Sep  4 21:31:02 2010
New Revision: 992684

URL: http://svn.apache.org/viewvc?rev=992684&view=rev
Log:
Dropping empty Metadata elements from EPRs

Modified:
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java
    cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spi/ProviderImplTest.java

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java?rev=992684&r1=992683&r2=992684&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java Sat
Sep  4 21:31:02 2010
@@ -212,83 +212,92 @@ public class ProviderImpl extends javax.
                 writer.writeEndElement();
             }
 
-            writer.writeStartElement(JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_METADATA_NAME,
-                                     JAXWSAConstants.NS_WSA);
-            writer.writeNamespace(JAXWSAConstants.WSAW_PREFIX, JAXWSAConstants.NS_WSAW);
-            writer.writeNamespace(JAXWSAConstants.WSAM_PREFIX, JAXWSAConstants.NS_WSAM);
-            if (wsdlDocumentLocation != null) {
-                boolean includeLocationOnly = false;
-                org.apache.cxf.message.Message message = PhaseInterceptorChain.getCurrentMessage();
-                if (message != null) {
-                    includeLocationOnly = MessageUtils.isTrue(
-                        message.getContextualProperty("org.apache.cxf.wsa.metadata.wsdlLocationOnly"));
-                }
-                String attrubuteValue = serviceName != null && !includeLocationOnly

-                        ? serviceName.getNamespaceURI() + " " + wsdlDocumentLocation
-                        : wsdlDocumentLocation;
-                writer.writeNamespace(JAXWSAConstants.WSDLI_PFX,
-                                      JAXWSAConstants.NS_WSDLI);
-                writer.writeAttribute(JAXWSAConstants.WSDLI_PFX,
-                                      JAXWSAConstants.NS_WSDLI,
-                                      JAXWSAConstants.WSDLI_WSDLLOCATION,
-                                      attrubuteValue);
-            }
-            if (interfaceName != null) {
-                writer.writeStartElement(JAXWSAConstants.WSAM_PREFIX,
-                                         JAXWSAConstants.WSAM_INTERFACE_NAME,
-                                         JAXWSAConstants.NS_WSAM);
-                String portTypePrefix = interfaceName.getPrefix();
-                if (portTypePrefix == null || portTypePrefix.equals("")) {
-                    portTypePrefix = "ns1";
-                }
-                writer.writeNamespace(portTypePrefix, interfaceName.getNamespaceURI());
-                writer.writeCharacters(portTypePrefix + ":" + interfaceName.getLocalPart());
-                writer.writeEndElement();
-            }
-
-            
-            String serviceNamePrefix = null;
-
-            if (serviceName != null) {
-                serviceNamePrefix = (serviceName.getPrefix() == null || serviceName.getPrefix().length()
== 0)
-                    ? "ns2" : serviceName.getPrefix();
-
-                writer.writeStartElement(JAXWSAConstants.WSAM_PREFIX,
-                                         JAXWSAConstants.WSAM_SERVICENAME_NAME,
-                                         JAXWSAConstants.NS_WSAM);
-
-                if (portName != null) {
-                    writer.writeAttribute(JAXWSAConstants.WSAM_ENDPOINT_NAME, portName.getLocalPart());
-                }
-                writer.writeNamespace(serviceNamePrefix, serviceName.getNamespaceURI());
-                writer.writeCharacters(serviceNamePrefix + ":" + serviceName.getLocalPart());
-
-                writer.writeEndElement();
-            }
-
-            if (wsdlDocumentLocation != null) {
-
-                writer.writeStartElement(WSDLConstants.WSDL_PREFIX, WSDLConstants.QNAME_DEFINITIONS
-                    .getLocalPart(), WSDLConstants.NS_WSDL11);
-                writer.writeNamespace(WSDLConstants.WSDL_PREFIX, WSDLConstants.NS_WSDL11);
-                writer.writeStartElement(WSDLConstants.WSDL_PREFIX,
-                                         WSDLConstants.QNAME_IMPORT.getLocalPart(),
-                                         WSDLConstants.QNAME_IMPORT.getNamespaceURI());
+            if (wsdlDocumentLocation != null
+                || interfaceName != null
+                || serviceName != null
+                || metadata != null) {
+                
+                        
+                writer.writeStartElement(JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_METADATA_NAME,
+                                         JAXWSAConstants.NS_WSA);
+                writer.writeNamespace(JAXWSAConstants.WSAW_PREFIX, JAXWSAConstants.NS_WSAW);
+                writer.writeNamespace(JAXWSAConstants.WSAM_PREFIX, JAXWSAConstants.NS_WSAM);
+                
+                if (wsdlDocumentLocation != null) {
+                    boolean includeLocationOnly = false;
+                    org.apache.cxf.message.Message message = PhaseInterceptorChain.getCurrentMessage();
+                    if (message != null) {
+                        includeLocationOnly = MessageUtils.isTrue(
+                            message.getContextualProperty("org.apache.cxf.wsa.metadata.wsdlLocationOnly"));
+                    }
+                    String attrubuteValue = serviceName != null && !includeLocationOnly

+                            ? serviceName.getNamespaceURI() + " " + wsdlDocumentLocation
+                            : wsdlDocumentLocation;
+                    writer.writeNamespace(JAXWSAConstants.WSDLI_PFX,
+                                          JAXWSAConstants.NS_WSDLI);
+                    writer.writeAttribute(JAXWSAConstants.WSDLI_PFX,
+                                          JAXWSAConstants.NS_WSDLI,
+                                          JAXWSAConstants.WSDLI_WSDLLOCATION,
+                                          attrubuteValue);
+                }
+                if (interfaceName != null) {
+                    writer.writeStartElement(JAXWSAConstants.WSAM_PREFIX,
+                                             JAXWSAConstants.WSAM_INTERFACE_NAME,
+                                             JAXWSAConstants.NS_WSAM);
+                    String portTypePrefix = interfaceName.getPrefix();
+                    if (portTypePrefix == null || portTypePrefix.equals("")) {
+                        portTypePrefix = "ns1";
+                    }
+                    writer.writeNamespace(portTypePrefix, interfaceName.getNamespaceURI());
+                    writer.writeCharacters(portTypePrefix + ":" + interfaceName.getLocalPart());
+                    writer.writeEndElement();
+                }
+    
+                
+                String serviceNamePrefix = null;
+    
                 if (serviceName != null) {
-                    writer.writeAttribute(WSDLConstants.ATTR_NAMESPACE, serviceName.getNamespaceURI());
+                    serviceNamePrefix = 
+                        (serviceName.getPrefix() == null || serviceName.getPrefix().length()
== 0)
+                        ? "ns2" : serviceName.getPrefix();
+    
+                    writer.writeStartElement(JAXWSAConstants.WSAM_PREFIX,
+                                             JAXWSAConstants.WSAM_SERVICENAME_NAME,
+                                             JAXWSAConstants.NS_WSAM);
+    
+                    if (portName != null) {
+                        writer.writeAttribute(JAXWSAConstants.WSAM_ENDPOINT_NAME, portName.getLocalPart());
+                    }
+                    writer.writeNamespace(serviceNamePrefix, serviceName.getNamespaceURI());
+                    writer.writeCharacters(serviceNamePrefix + ":" + serviceName.getLocalPart());
+    
+                    writer.writeEndElement();
+                }
+    
+                if (wsdlDocumentLocation != null) {
+    
+                    writer.writeStartElement(WSDLConstants.WSDL_PREFIX, WSDLConstants.QNAME_DEFINITIONS
+                        .getLocalPart(), WSDLConstants.NS_WSDL11);
+                    writer.writeNamespace(WSDLConstants.WSDL_PREFIX, WSDLConstants.NS_WSDL11);
+                    writer.writeStartElement(WSDLConstants.WSDL_PREFIX,
+                                             WSDLConstants.QNAME_IMPORT.getLocalPart(),
+                                             WSDLConstants.QNAME_IMPORT.getNamespaceURI());
+                    if (serviceName != null) {
+                        writer.writeAttribute(WSDLConstants.ATTR_NAMESPACE, serviceName.getNamespaceURI());
+                    }
+                    writer.writeAttribute(WSDLConstants.ATTR_LOCATION, wsdlDocumentLocation);
+                    writer.writeEndElement();
+                    writer.writeEndElement();
+                }
+    
+                if (metadata != null) {
+                    for (Element e : metadata) {
+                        StaxUtils.writeElement(e, writer, true);
+                    }
                 }
-                writer.writeAttribute(WSDLConstants.ATTR_LOCATION, wsdlDocumentLocation);
-                writer.writeEndElement();
+    
                 writer.writeEndElement();
             }
-
-            if (metadata != null) {
-                for (Element e : metadata) {
-                    StaxUtils.writeElement(e, writer, true);
-                }
-            }
-
-            writer.writeEndElement();
             
             if (elements != null) {
                 for (Element e : elements) {

Modified: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spi/ProviderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spi/ProviderImplTest.java?rev=992684&r1=992683&r2=992684&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spi/ProviderImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spi/ProviderImplTest.java
Sat Sep  4 21:31:02 2010
@@ -19,15 +19,24 @@
 
 package org.apache.cxf.jaxws.spi;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.ws.wsaddressing.W3CEndpointReference;
 
+import org.w3c.dom.Element;
+
 import org.apache.cxf.BusFactory;
+
 import org.junit.After;
 
 
 public class ProviderImplTest extends org.junit.Assert {
+    
     @org.junit.Test
     public void testCreateW3CEpr() throws Exception {
         QName serviceName = new QName("http://cxf.apache.org", "ServiceName");
@@ -46,6 +55,72 @@ public class ProviderImplTest extends or
                    sw.toString().contains("wsdli:wsdlLocation=\"http://cxf.apache.org wsdlLoc\""));
     }
 
+    @org.junit.Test
+    public void testCreateW3CEprNoMetadata() throws Exception {
+        ProviderImpl impl = new ProviderImpl();
+        W3CEndpointReference w3Epr = impl.createW3CEndpointReference(
+                         "http://myaddress", null, null, null, null, null, null, null, null);
+        
+        java.io.StringWriter sw = new java.io.StringWriter();
+        StreamResult result = new StreamResult(sw);
+        w3Epr.writeTo(result);
+        assertTrue("Address is expected", sw.toString().contains("Address"));
+        assertFalse("empty Metadata element should be dropped", sw.toString().contains("Metadata"));
+    }
+    
+    @org.junit.Test
+    public void testCreateW3CEprMetadataInterfaceNameOnly() throws Exception {
+        QName serviceName = new QName("http://cxf.apache.org", "IntfName");
+        ProviderImpl impl = new ProviderImpl();
+        W3CEndpointReference w3Epr = impl.createW3CEndpointReference(
+                         "http://myaddress", serviceName, null, null, null, null, null, null,
null);
+        
+        java.io.StringWriter sw = new java.io.StringWriter();
+        StreamResult result = new StreamResult(sw);
+        w3Epr.writeTo(result);
+        assertTrue("Address is expected", sw.toString().contains("Address"));
+        assertTrue("Metadata element expected", sw.toString().contains("Metadata"));
+        assertTrue("Interface element expected", sw.toString().contains("Interface"));
+        assertFalse("ServiceName is unexpected", sw.toString().contains("ServiceName"));
+    }
+    
+    @org.junit.Test
+    public void testCreateW3CEprMetadataServiceNameOnly() throws Exception {
+        QName serviceName = new QName("http://cxf.apache.org", "ServiceName");
+        ProviderImpl impl = new ProviderImpl();
+        W3CEndpointReference w3Epr = impl.createW3CEndpointReference(
+                         "http://myaddress", null, serviceName, null, null, null, null, null,
null);
+        
+        java.io.StringWriter sw = new java.io.StringWriter();
+        StreamResult result = new StreamResult(sw);
+        w3Epr.writeTo(result);
+        assertTrue("Address is expected", sw.toString().contains("Address"));
+        assertTrue("Metadata element expected", sw.toString().contains("Metadata"));
+        assertFalse("Interface element unexpected", sw.toString().contains("Interface"));
+        assertTrue("ServiceName is expected", sw.toString().contains("ServiceName"));
+    }
+    
+    @org.junit.Test
+    public void testCreateW3CEprMetadataMetadataOnly() throws Exception {
+        ProviderImpl impl = new ProviderImpl();
+        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+        Element element = builder.newDocument().createElement("customMetadata");
+        List<Element> metadata = new ArrayList<Element>();
+        metadata.add(element);
+        W3CEndpointReference w3Epr = impl.createW3CEndpointReference(
+                         "http://myaddress", null, null, 
+                         metadata, null, null);
+        
+        java.io.StringWriter sw = new java.io.StringWriter();
+        StreamResult result = new StreamResult(sw);
+        w3Epr.writeTo(result);
+        assertTrue("Address is expected", sw.toString().contains("Address"));
+        assertTrue("Metadata element expected", sw.toString().contains("Metadata"));
+        assertTrue("Custom Metadata element expected", sw.toString().contains("customMetadata"));
+        assertFalse("Interface element unexpected", sw.toString().contains("Interface"));
+        assertFalse("ServiceName unexpected", sw.toString().contains("ServiceName"));
+    }
+    
     @After
     public void tearDown() {
         BusFactory.setDefaultBus(null);



Mime
View raw message