cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r946823 - in /cxf/trunk: api/src/main/java/org/apache/cxf/ws/addressing/ common/common/src/main/java/org/apache/cxf/staxutils/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/
Date Thu, 20 May 2010 23:34:15 GMT
Author: dkulp
Date: Thu May 20 23:34:15 2010
New Revision: 946823

URL: http://svn.apache.org/viewvc?rev=946823&view=rev
Log:
JAX-WS 2.2 spec mandates use of addressing metadata spec.   Add those
extensors along with the older extensors

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java
    cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java?rev=946823&r1=946822&r2=946823&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java Thu May
20 23:34:15 2010
@@ -34,6 +34,7 @@ public final class JAXWSAConstants {
     public static final String NS_WSAM = "http://www.w3.org/2007/05/addressing/metadata";
 
     public static final QName WSAW_ACTION_QNAME = new QName(NS_WSAW,  "Action");
+    public static final QName WSAM_ACTION_QNAME = new QName(NS_WSAM,  "Action");
     
     public static final QName WSAW_USINGADDRESSING_QNAME = new QName(NS_WSAW, "UsingAddressing");
     

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java?rev=946823&r1=946822&r2=946823&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
(original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/staxutils/W3CDOMStreamWriter.java
Thu May 20 23:34:15 2010
@@ -142,8 +142,8 @@ public class W3CDOMStreamWriter implemen
         writeEndElement();
     }
 
-    public void writeEmptyElement(String prefix, String namespace, String local) throws XMLStreamException
{
-        writeStartElement(prefix, namespace, local);
+    public void writeEmptyElement(String prefix, String local, String namespace) throws XMLStreamException
{
+        writeStartElement(prefix, local, namespace);
         writeEndElement();
     }
 

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java?rev=946823&r1=946822&r2=946823&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsEndpointImpl.java
Thu May 20 23:34:15 2010
@@ -22,9 +22,9 @@ package org.apache.cxf.jaxws.support;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import javax.wsdl.WSDLException;
 import javax.wsdl.extensions.ExtensibilityElement;
 import javax.wsdl.extensions.ExtensionRegistry;
+import javax.wsdl.extensions.UnknownExtensibilityElement;
 import javax.xml.ws.Binding;
 import javax.xml.ws.Service.Mode;
 import javax.xml.ws.WebServiceFeature;
@@ -33,6 +33,8 @@ import javax.xml.ws.soap.AddressingFeatu
 import javax.xml.ws.soap.MTOMFeature;
 import javax.xml.ws.soap.SOAPBinding;
 
+import org.w3c.dom.Element;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.binding.soap.SoapBinding;
 import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
@@ -41,6 +43,7 @@ import org.apache.cxf.binding.xml.XMLBin
 import org.apache.cxf.endpoint.EndpointException;
 import org.apache.cxf.endpoint.EndpointImpl;
 import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.jaxws.binding.DefaultBindingImpl;
@@ -64,9 +67,12 @@ import org.apache.cxf.jaxws.interceptors
 import org.apache.cxf.message.Message;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.model.BindingInfo;
+import org.apache.cxf.service.model.DescriptionInfo;
 import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.staxutils.W3CDOMStreamWriter;
 import org.apache.cxf.ws.addressing.JAXWSAConstants;
 import org.apache.cxf.ws.addressing.WSAddressingFeature;
+import org.apache.cxf.ws.policy.PolicyConstants;
 import org.apache.cxf.wsdl.WSDLManager;
 
 /**
@@ -230,22 +236,93 @@ public class JaxWsEndpointImpl extends E
                                                                             WSAW_USINGADDRESSING_QNAME);
                 el.setRequired(addressing.required());
                 bindingInfo.addExtensor(el);
-            } catch (WSDLException e) {
-                // TODO Auto-generated catch block
+                
+                StringBuilder polRefId = new StringBuilder(bindingInfo.getName().getLocalPart());
+                polRefId.append("_WSAM_Addressing_Policy");
+                UnknownExtensibilityElement uel = new UnknownExtensibilityElement();
+                
+                W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
+                writer.writeStartElement("wsp", "PolicyReference", PolicyConstants.NAMESPACE_WS_POLICY);
+                writer.writeAttribute("URI", "#" + polRefId.toString());
+                writer.writeEndElement();
+                Element pr = writer.getDocument().getDocumentElement();
+                uel.setElement(pr);
+                uel.setElementType(DOMUtils.getElementQName(pr));
+                bindingInfo.addExtensor(uel);
+                
+                writer = new W3CDOMStreamWriter();
+                writer.writeStartElement("wsp", "Policy", PolicyConstants.NAMESPACE_WS_POLICY);
+                writer.writeAttribute("wsu", PolicyConstants.WSU_NAMESPACE_URI,
+                                      PolicyConstants.WSU_ID_ATTR_NAME, polRefId.toString());
+                writer.writeStartElement("wsam", "Addressing", JAXWSAConstants.NS_WSAM);
+                if (!addressing.required()) {
+                    writer.writeAttribute("wsp", PolicyConstants.NAMESPACE_WS_POLICY,
+                                          "Optional", "true");
+                }
+                writer.writeStartElement("wsp", "Policy", PolicyConstants.NAMESPACE_WS_POLICY);
+                
+                String s = getAddressingRequirement(addressing);
+                if (s != null) {
+                    writer.writeEmptyElement("wsam", s, JAXWSAConstants.NS_WSAM);
+                }
+                
+                writer.writeEndElement();
+                writer.writeEndElement();
+                writer.writeEndElement();
+                
+                pr = writer.getDocument().getDocumentElement();
+                
+                uel = new UnknownExtensibilityElement();
+                uel.setElement(pr);
+                uel.setElementType(DOMUtils.getElementQName(pr));
+                if (bindingInfo.getService().getDescription() == null) {
+                    DescriptionInfo description = new DescriptionInfo();
+                    description.setName(bindingInfo.getService().getName());
+                    bindingInfo.getService().setDescription(description);
+                }
+                bindingInfo.getService().getDescription().addExtensor(uel);
+                
+            } catch (Exception e) {
+                //ignore
                 e.printStackTrace();
             }
         }        
     }
 
+    private String getAddressingRequirement(Addressing addressing) {
+        try {
+            Object o = Addressing.class.getMethod("responses").invoke(addressing);
+            if (o != null) {
+                String s = o.toString();
+                if ("ANONYMOUS".equals(s)) {
+                    return "AnonymousResponses";
+                } else if ("NON_ANONYMOUS".equals(s)) {
+                    return "NonAnonymousResponses";
+                }
+            }
+        } catch (Throwable ex) {
+            //ignore - probably JAX-WS 2.1
+        }
+        return null;
+    }
+
     private Addressing getAddressing() {
-        Class<?> serviceClass = implInfo.getSEIClass();
-        if (serviceClass == null) {
-            serviceClass = implInfo.getImplementorClass();
+        Class<?> serviceClass = implInfo.getImplementorClass();
+        if (serviceClass != null) {
+            Addressing ad = serviceClass.getAnnotation(Addressing.class);
+            if (ad != null) {
+                return ad;
+            }
         }
-        if (serviceClass == null) {
-            return null;
+        
+        serviceClass = implInfo.getSEIClass();
+        if (serviceClass != null) {
+            Addressing ad = serviceClass.getAnnotation(Addressing.class);
+            if (ad != null) {
+                return ad;
+            }
         }
-        return serviceClass.getAnnotation(Addressing.class);
+        return null;
     }
 
     public Binding getJaxwsBinding() {

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java?rev=946823&r1=946822&r2=946823&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
Thu May 20 23:34:15 2010
@@ -488,11 +488,19 @@ public class JaxWsServiceFactoryBean ext
         MessageInfo input = operation.getInput();
         if (!StringUtils.isEmpty(action.input())) {
             input.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, action.input());
+            input.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, action.input());
+        } else {
+            input.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, 
+                                        computeAction(operation, "Request"));
         }
         
         MessageInfo output = operation.getOutput();
         if (output != null && !StringUtils.isEmpty(action.output())) {
             output.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, action.output());
+            output.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, action.output());
+        } else if (output != null) {
+            output.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, 
+                                         computeAction(operation, "Response"));         
  
         }
         
         FaultAction[] faultActions = action.fault();
@@ -503,15 +511,41 @@ public class JaxWsServiceFactoryBean ext
                 FaultInfo faultInfo = getFaultInfo(operation, faultAction.className());
                 faultInfo.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, 
                                                 faultAction.value());
+                faultInfo.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, 
+                                                faultAction.value());
                 if (operation.isUnwrappedCapable()) {
                     faultInfo = getFaultInfo(operation.getUnwrappedOperation(), faultAction.className());
                     faultInfo.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, 
                                                     faultAction.value());
+                    faultInfo.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, 
+                                                    faultAction.value());
                 }
             }
-        }        
+        } 
+        for (FaultInfo fi : operation.getFaults()) {
+            if (fi.getExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME) == null) {
+                String f = "/Fault/" + fi.getName().getLocalPart();
+                fi.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, 
+                                         computeAction(operation, f));
+                if (operation.isUnwrappedCapable()) {
+                    fi = operation.getUnwrappedOperation().getFault(fi.getName());
+                    fi.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, 
+                                             computeAction(operation, f));
+                }                
+            }
+        }
     }
     
+    private Object computeAction(OperationInfo op, String postFix) {
+        StringBuilder s = new StringBuilder(op.getName().getNamespaceURI());
+        if (s.charAt(s.length() - 1) != '/') {
+            s.append('/');
+        }
+        s.append(op.getInterface().getName().getLocalPart())
+            .append('/').append(op.getName().getLocalPart()).append(postFix);
+        return s.toString();
+    }
+
     @Override
     protected OperationInfo createOperation(ServiceInfo serviceInfo, InterfaceInfo intf,
Method m) {
         OperationInfo op = super.createOperation(serviceInfo, intf, m);



Mime
View raw message