Ajith, Can you pls review and apply this patch which provides proper serialization of policy elements which can either be an ExtElement or an ExtAttribute.
Thanks, Sanka
Index: src/org/apache/axis2/wsdl/builder/wsdl4j/WSDLPump.java =================================================================== --- src/org/apache/axis2/wsdl/builder/wsdl4j/WSDLPump.java (revision 365527) +++ src/org/apache/axis2/wsdl/builder/wsdl4j/WSDLPump.java (working copy) @@ -18,10 +18,14 @@ import com.ibm.wsdl.extensions.soap.SOAPConstants; import org.apache.axis2.wsdl.builder.WSDLComponentFactory; +import org.apache.ws.policy.util.DOMPolicyReader; +import org.apache.ws.policy.util.OMPolicyReader; +import org.apache.ws.policy.util.PolicyFactory; import org.apache.wsdl.*; import org.apache.wsdl.extensions.DefaultExtensibilityElement; import org.apache.wsdl.extensions.ExtensionConstants; import org.apache.wsdl.extensions.ExtensionFactory; +import org.apache.wsdl.extensions.PolicyExtensibilityElement; import org.apache.wsdl.impl.WSDLProcessingException; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -1035,6 +1039,19 @@ Element element = unknown.getElement(); soapAddressExtensibiltyElement.setLocationURI(element.getAttribute("location")); component.addExtensibilityElement(soapAddressExtensibiltyElement); + + } else if (ExtensionConstants.POLICY.equals(unknown.getElementType())) { + PolicyExtensibilityElement policyExtensibilityElement = (PolicyExtensibilityElement) extensionFactory.getExtensionElement(wsdl4jElement.getElementType()); + DOMPolicyReader policyReader = (DOMPolicyReader) PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER); + policyExtensibilityElement.setPolicyElement(policyReader.readPolicy(unknown.getElement())); + component.addExtensibilityElement(policyExtensibilityElement); + + } else if (ExtensionConstants.POLICY_REFERENCE.equals(unknown.getElementType())) { + PolicyExtensibilityElement policyExtensibilityElement = (PolicyExtensibilityElement) extensionFactory.getExtensionElement(wsdl4jElement.getElementType()); + DOMPolicyReader policyReader = (DOMPolicyReader) PolicyFactory.getPolicyReader(PolicyFactory.DOM_POLICY_READER); + policyExtensibilityElement.setPolicyElement(policyReader.readPolicyReference(unknown.getElement())); + component.addExtensibilityElement(policyExtensibilityElement); + }else{ DefaultExtensibilityElement defaultExtensibilityElement = (DefaultExtensibilityElement) extensionFactory Index: src/org/apache/axis2/wsdl/writer/WOMtoWSDL11Writer.java =================================================================== --- src/org/apache/axis2/wsdl/writer/WOMtoWSDL11Writer.java (revision 365527) +++ src/org/apache/axis2/wsdl/writer/WOMtoWSDL11Writer.java (working copy) @@ -6,6 +6,10 @@ import org.apache.axis2.om.OMFactory; import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder; import org.apache.axis2.wsdl.WSDLVersionWrapper; +import org.apache.ws.policy.Policy; +import org.apache.ws.policy.PolicyReference; +import org.apache.ws.policy.util.PolicyFactory; +import org.apache.ws.policy.util.StAXPolicyWriter; import org.apache.wsdl.*; import org.apache.wsdl.extensions.*; import org.w3c.dom.Element; @@ -15,6 +19,7 @@ import javax.wsdl.xml.WSDLWriter; import javax.xml.namespace.QName; import javax.xml.stream.*; + import java.io.*; import java.util.HashMap; import java.util.Iterator; @@ -120,7 +125,10 @@ findSOAPNsPrefix(wsdlDescription); //write the imports writeImports(wsdlDescription); - //write the types + //write extensibility elements + handleExtensibiltyElements(wsdlDescription.getExtensibilityElements()); + + //write the types writeTypes(wsdlDescription); //write the messages writeMessages(wsdlDescription); @@ -155,6 +163,7 @@ service = (WSDLService) serviceIterator.next(); writer.writeStartElement(defaultWSDLPrefix, "service", WSDL1_1_NAMESPACE_URI); writer.writeAttribute("name", service.getName().getLocalPart()); + handleExtensibiltyElements(service.getExtensibilityElements()); //wrtie the porttypes Map endPointMap = service.getEndpoints(); if (endPointMap != null && !endPointMap.isEmpty()) { @@ -410,8 +419,10 @@ /** * @param desc + * @throws XMLStreamException + * @throws IOException */ - protected void writePortTypes(WSDLDescription desc) throws XMLStreamException { + protected void writePortTypes(WSDLDescription desc) throws XMLStreamException, IOException { Map interfaceMap = desc.getWsdlInterfaces(); if (!interfaceMap.isEmpty()) { Iterator interfaceIterator = interfaceMap.values().iterator(); @@ -421,7 +432,8 @@ writer.writeStartElement(defaultWSDLPrefix, PORTTYPE_NAME, WSDL1_1_NAMESPACE_URI); writer.writeAttribute("name", wsdlInterface.getName() == null ? "" : wsdlInterface.getName().getLocalPart()); - + //write extensibility attributes + handleExtensibilityAttributes(wsdlInterface.getExtensibilityAttributes()); //write the operations writePorttypeOperations(wsdlInterface); @@ -437,8 +449,10 @@ * Writes the operation. * * @param wsdlInterface + * @throws XMLStreamException + * @throws IOException */ - protected void writePorttypeOperations(WSDLInterface wsdlInterface) throws XMLStreamException { + protected void writePorttypeOperations(WSDLInterface wsdlInterface) throws XMLStreamException, IOException { Map operationsMap = wsdlInterface.getOperations(); if (!operationsMap.isEmpty()) { Iterator opIterator = operationsMap.values().iterator(); @@ -449,12 +463,16 @@ writer.writeAttribute("name", operation.getName() == null ? "" : operation.getName().getLocalPart()); // writer.writeEndElement(); //write the inputs + //write extensibility elements + handleExtensibiltyElements(operation.getExtensibilityElements()); WSDL11Message message; MessageReference inputMessage = operation.getInputMessage(); if (inputMessage != null) { message = (WSDL11Message) messageMap.get(inputMessage.getElementQName()); writer.writeStartElement(defaultWSDLPrefix, INPUT_NAME, WSDL1_1_NAMESPACE_URI); writer.writeAttribute("message", targetNamespacePrefix + ":" + message.getMessageName()); + //write extensibility attributes + handleExtensibilityAttributes(inputMessage.getExtensibilityAttributes()); writer.writeEndElement(); } @@ -464,6 +482,8 @@ message = (WSDL11Message) messageMap.get(outputMessage.getElementQName()); writer.writeStartElement(defaultWSDLPrefix, OUTPUT_NAME, WSDL1_1_NAMESPACE_URI); writer.writeAttribute("message", targetNamespacePrefix + ":" + message.getMessageName()); +// write extensibility attributes + handleExtensibilityAttributes(outputMessage.getExtensibilityAttributes()); writer.writeEndElement(); } @@ -531,6 +551,13 @@ writer.writeEndElement(); } + protected void handleExtensibilityAttributes(List extAttributeList) throws XMLStreamException { + int extAttributeCount = extAttributeList.size(); + for (int i = 0; i < extAttributeCount; i++) { + writeExtensibilityAttribute((WSDLExtensibilityAttribute) extAttributeList.get(i)); + } + } + protected void handleExtensibiltyElements(List extElementList) throws XMLStreamException, IOException { int extensibilityElementCount = extElementList.size(); for (int i = 0; i < extensibilityElementCount; i++) { @@ -551,6 +578,13 @@ OMElement scheamElement = staxOMBuilder.getDocumentElement(); scheamElement.serialize(writer); } + + protected void writeExtensibilityAttribute(WSDLExtensibilityAttribute extAttribute) throws XMLStreamException { + QName qname = extAttribute.getKey(); + QName value = extAttribute.getValue(); + + writer.writeAttribute(qname.getPrefix(), qname.getNamespaceURI(), qname.getLocalPart(), value.getLocalPart()); + } /** * @param extElement @@ -574,6 +608,8 @@ writeSOAPOpextensibilityElement((SOAPOperation) extElement); } else if (extElement instanceof SOAPBody) { writeSOAPBodyExtensibilityElement((SOAPBody) extElement); + } else if (extElement instanceof PolicyExtensibilityElement) { + writePolicyExtensibilityElement((PolicyExtensibilityElement) extElement); } else { writer.writeComment(" Unknown extensibility element" + extElement.toString()); } @@ -616,6 +652,18 @@ writer.writeAttribute("style", soapop.getStyle()); writer.writeEndElement(); } + + protected void writePolicyExtensibilityElement(PolicyExtensibilityElement policyExtensibilityElement) throws XMLStreamException { + StAXPolicyWriter policyWriter = (StAXPolicyWriter) PolicyFactory.getPolicyWriter(PolicyFactory.StAX_POLICY_WRITER); + Object policyElement = policyExtensibilityElement.getPolicyElement(); + + if (policyElement instanceof Policy) { + policyWriter.writePolicy((Policy) policyElement, writer); + + } else if (policyElement instanceof PolicyReference) { + policyWriter.writePolicyReference((PolicyReference) policyElement, writer); + } + } /** * Since we have no proper way to represent a WSDL 1.1 message, here's a simple bean class to Index: src/org/apache/wsdl/extensions/impl/PolicyExtensitbilityElementImpl.java =================================================================== --- src/org/apache/wsdl/extensions/impl/PolicyExtensitbilityElementImpl.java (revision 365527) +++ src/org/apache/wsdl/extensions/impl/PolicyExtensitbilityElementImpl.java (working copy) @@ -24,20 +24,21 @@ * @author Sanka Samaranayake ([EMAIL PROTECTED]) */ public class PolicyExtensitbilityElementImpl extends WSDLExtensibilityElementImpl implements PolicyExtensibilityElement { - private Policy policy; + private Object policyElement; public PolicyExtensitbilityElementImpl() { } - public PolicyExtensitbilityElementImpl(Policy policy) { - setPolicy(policy); + + public PolicyExtensitbilityElementImpl(Object policyElement) { + setPolicyElement(policyElement); } - public void setPolicy(Policy policy) { - this.policy = policy; + public void setPolicyElement(Object policyElement) { + this.policyElement = policyElement; } - public Policy getPolicy() { - return policy; + public Object getPolicyElement() { + return policyElement; } } Index: src/org/apache/wsdl/extensions/PolicyExtensibilityElement.java =================================================================== --- src/org/apache/wsdl/extensions/PolicyExtensibilityElement.java (revision 365527) +++ src/org/apache/wsdl/extensions/PolicyExtensibilityElement.java (working copy) @@ -16,7 +16,6 @@ package org.apache.wsdl.extensions; -import org.apache.ws.policy.Policy; import org.apache.wsdl.WSDLExtensibilityElement; /** @@ -24,7 +23,7 @@ */ public interface PolicyExtensibilityElement extends WSDLExtensibilityElement { - public void setPolicy(Policy policy); + public void setPolicyElement(Object policyElement); - public Policy getPolicy(); + public Object getPolicyElement(); } Index: src/org/apache/wsdl/extensions/ExtensionConstants.java =================================================================== --- src/org/apache/wsdl/extensions/ExtensionConstants.java (revision 365527) +++ src/org/apache/wsdl/extensions/ExtensionConstants.java (working copy) @@ -54,5 +54,6 @@ public static final QName POLICY = new QName( "http://schemas.xmlsoap.org/ws/2004/09/policy", "Policy"); - + public static final QName POLICY_REFERENCE = new QName( + "http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyReference"); }