Author: palin
Date: 2007-05-05 07:16:05 -0400 (Sat, 05 May 2007)
New Revision: 2968
Modified:
branches/JBWS-856/build/ant-import/build-thirdparty.xml
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/metadata/PolicyMetaExtension.java
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/MetaDataBuilder.java
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/tools/wsdl/WSDLGenerator.java
Log:
- Modified the WSDLGenerator to deal with endpoint policies when generating the wsdl
unified structure from the UMDM
- Apache Policy library added to classhpath
Modified: branches/JBWS-856/build/ant-import/build-thirdparty.xml
===================================================================
--- branches/JBWS-856/build/ant-import/build-thirdparty.xml 2007-05-05 09:03:09 UTC (rev
2967)
+++ branches/JBWS-856/build/ant-import/build-thirdparty.xml 2007-05-05 11:16:05 UTC (rev
2968)
@@ -114,6 +114,7 @@
<pathelement location="${thirdparty.dir}/xmlsec.jar"/>
<pathelement location="${thirdparty.dir}/xercesImpl.jar"/>
<pathelement location="${thirdparty.dir}/xalan.jar"/>
+ <pathelement location="${thirdparty.dir}/policy.jar"/>
</path>
<!-- The compile classpath for jboss50 integration -->
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/metadata/PolicyMetaExtension.java
===================================================================
---
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/metadata/PolicyMetaExtension.java 2007-05-05
09:03:09 UTC (rev 2967)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/extensions/policy/metadata/PolicyMetaExtension.java 2007-05-05
11:16:05 UTC (rev 2968)
@@ -1,43 +1,53 @@
package org.jboss.ws.extensions.policy.metadata;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
import org.apache.ws.policy.Policy;
import org.jboss.ws.extensions.policy.PolicyScopeLevel;
import org.jboss.ws.metadata.umdm.MetaDataExtension;
public class PolicyMetaExtension extends MetaDataExtension
{
-
- private Policy policy;
- private PolicyScopeLevel scope;
+ //Policies may be attached to a policy subject with different policy scopes
+ private Map<PolicyScopeLevel,Collection<Policy>> policies = new
HashMap<PolicyScopeLevel,Collection<Policy>>();
-
public PolicyMetaExtension(String extensionNameSpace)
{
super(extensionNameSpace);
}
-
- public Policy getPolicy()
+ public void addPolicy(PolicyScopeLevel scope, Policy policy)
{
- return policy;
+ Collection<Policy> list;
+ if (!policies.containsKey(scope))
+ {
+ list = new LinkedList<Policy>();
+ policies.put(scope,list);
+ }
+ else
+ {
+ list = policies.get(scope);
+ }
+ list.add(policy);
}
-
- public void setPolicy(Policy policy)
+
+ public Collection<Policy> getPolicies(PolicyScopeLevel scope)
{
- this.policy = policy;
+ return policies.get(scope);
}
-
-
- public PolicyScopeLevel getScope()
+
+ public Collection<Policy> getAllPolicies()
{
- return scope;
+ Collection<Policy> list = new LinkedList<Policy>();
+ for (PolicyScopeLevel scope : policies.keySet())
+ {
+ list.addAll(policies.get(scope));
+ }
+ return list;
}
-
-
- public void setScope(PolicyScopeLevel scope)
- {
- this.scope = scope;
- }
-
+
}
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/MetaDataBuilder.java
===================================================================
---
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/MetaDataBuilder.java 2007-05-05
09:03:09 UTC (rev 2967)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/MetaDataBuilder.java 2007-05-05
11:16:05 UTC (rev 2968)
@@ -526,13 +526,16 @@
private void deployPolicy(Policy policy, PolicyScopeLevel scope, ExtensibleMetaData
extMetaData)
{
- PolicyMetaExtension ext = new PolicyMetaExtension(Constants.URI_WS_POLICY);
+ PolicyMetaExtension ext =
(PolicyMetaExtension)extMetaData.getExtension(Constants.URI_WS_POLICY);
+ if (ext == null)
+ {
+ ext = new PolicyMetaExtension(Constants.URI_WS_POLICY);
+ extMetaData.addExtension(ext);
+ }
try
{
Policy deployedPolicy = PolicyDeployer.getInstance().deployServerside(policy,
extMetaData);
- ext.setPolicy(deployedPolicy);
- ext.setScope(scope);
- extMetaData.addExtension(ext);
+ ext.addPolicy(scope,deployedPolicy);
}
catch (UnsupportedPolicy e)
{
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java
===================================================================
---
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java 2007-05-05
09:03:09 UTC (rev 2967)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/metadata/builder/jaxws/JAXWSWebServiceMetaDataBuilder.java 2007-05-05
11:16:05 UTC (rev 2968)
@@ -174,9 +174,6 @@
MetaDataBuilder.replaceAddressLocation(sepMetaData);
- //POL-2
- //TODO!!!
-
processEndpointMetaDataExtensions(sepMetaData, wsdlDefinitions);
// init service endpoint id
@@ -361,17 +358,14 @@
//since we need to look for policies, eventually choose the supported
//policy alternatives and generate the final wsdl
//serviceMetaData.setWsdlLocation(wsdlLocation);
-
WSDLDefinitions wsdlDefinitions = factory.parse(wsdlLocation);
+ processPolicyMetaDataExtension(epMetaData, wsdlDefinitions);
if (policyLocation == null)
{
//process wsdl fragment with additional policies
WSDLDefinitions policyDefinitions = factory.parse(policyLocation);
+ processPolicyMetaDataExtension(epMetaData, policyDefinitions);
}
-
- //POL-1
- //TODO!!!
-
//generate the wsdl4j model again for the actual UMDM containing policy data
WSDLDefinitions actualWsdlDefinitions = generator.generate(serviceMetaData);
writeWsdl(serviceMetaData,actualWsdlDefinitions,epMetaData);
@@ -388,10 +382,7 @@
else
{
WSDLDefinitions policyDefinitions = factory.parse(policyLocation);
-
- //POL-1
- //TODO!!!
-
+ processPolicyMetaDataExtension(epMetaData, policyDefinitions);
//generate the wsdl4j model again for the actual UMDM containing policy
data
WSDLDefinitions actualWsdlDefinitions =
generator.generate(serviceMetaData);
writeWsdl(serviceMetaData,actualWsdlDefinitions,epMetaData);
Modified:
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/tools/wsdl/WSDLGenerator.java
===================================================================
---
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/tools/wsdl/WSDLGenerator.java 2007-05-05
09:03:09 UTC (rev 2967)
+++
branches/JBWS-856/jbossws-core/src/java/org/jboss/ws/tools/wsdl/WSDLGenerator.java 2007-05-05
11:16:05 UTC (rev 2968)
@@ -21,18 +21,28 @@
*/
package org.jboss.ws.tools.wsdl;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.util.Iterator;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
+import org.apache.ws.policy.Policy;
+import org.apache.ws.policy.util.PolicyFactory;
+import org.apache.ws.policy.util.PolicyWriter;
import org.jboss.ws.Constants;
import org.jboss.ws.core.jaxrpc.Style;
+import org.jboss.ws.core.utils.DOMUtils;
+import org.jboss.ws.extensions.policy.PolicyScopeLevel;
+import org.jboss.ws.extensions.policy.metadata.PolicyMetaExtension;
import org.jboss.ws.metadata.umdm.EndpointMetaData;
import org.jboss.ws.metadata.umdm.FaultMetaData;
+import org.jboss.ws.metadata.umdm.MetaDataExtension;
import org.jboss.ws.metadata.umdm.OperationMetaData;
import org.jboss.ws.metadata.umdm.ParameterMetaData;
import org.jboss.ws.metadata.umdm.ServiceMetaData;
+import org.jboss.ws.metadata.wsdl.Extendable;
import org.jboss.ws.metadata.wsdl.WSDLBinding;
import org.jboss.ws.metadata.wsdl.WSDLBindingFault;
import org.jboss.ws.metadata.wsdl.WSDLBindingOperation;
@@ -40,6 +50,7 @@
import org.jboss.ws.metadata.wsdl.WSDLBindingOperationOutput;
import org.jboss.ws.metadata.wsdl.WSDLDefinitions;
import org.jboss.ws.metadata.wsdl.WSDLEndpoint;
+import org.jboss.ws.metadata.wsdl.WSDLExtensibilityElement;
import org.jboss.ws.metadata.wsdl.WSDLImport;
import org.jboss.ws.metadata.wsdl.WSDLInterface;
import org.jboss.ws.metadata.wsdl.WSDLInterfaceFault;
@@ -47,11 +58,13 @@
import org.jboss.ws.metadata.wsdl.WSDLInterfaceOperationInput;
import org.jboss.ws.metadata.wsdl.WSDLInterfaceOperationOutfault;
import org.jboss.ws.metadata.wsdl.WSDLInterfaceOperationOutput;
+import org.jboss.ws.metadata.wsdl.WSDLProperty;
import org.jboss.ws.metadata.wsdl.WSDLRPCPart;
import org.jboss.ws.metadata.wsdl.WSDLRPCSignatureItem;
import org.jboss.ws.metadata.wsdl.WSDLSOAPHeader;
import org.jboss.ws.metadata.wsdl.WSDLService;
import org.jboss.ws.metadata.wsdl.WSDLRPCSignatureItem.Direction;
+import org.w3c.dom.Element;
/**
@@ -97,6 +110,28 @@
{
processOperation(wsdlInterface, wsdlBinding, operation);
}
+
+ //Policies
+ MetaDataExtension ext = endpoint.getExtension(Constants.URI_WS_POLICY);
+ if (ext != null)
+ {
+ PolicyMetaExtension policyExt = (PolicyMetaExtension)ext;
+ for (Policy policy : policyExt.getPolicies(PolicyScopeLevel.WSDL_PORT))
+ {
+ addPolicyDefinition(policy);
+ addPolicyReference(policy, wsdlEndpoint);
+ }
+ for (Policy policy : policyExt.getPolicies(PolicyScopeLevel.WSDL_PORT_TYPE))
+ {
+ addPolicyDefinition(policy);
+ addPolicyURIAttribute(policy, wsdlInterface);
+ }
+ for (Policy policy : policyExt.getPolicies(PolicyScopeLevel.WSDL_BINDING))
+ {
+ addPolicyDefinition(policy);
+ addPolicyReference(policy, wsdlBinding);
+ }
+ }
}
protected void processOperation(WSDLInterface wsdlInterface, WSDLBinding wsdlBinding,
OperationMetaData operation)
@@ -341,4 +376,43 @@
return wsdl;
}
+
+ protected void addPolicyDefinition(Policy policy)
+ {
+ try
+ {
+ PolicyWriter writer =
PolicyFactory.getPolicyWriter(PolicyFactory.StAX_POLICY_WRITER);
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ writer.writePolicy(policy, outputStream);
+ Element element =
DOMUtils.parse(outputStream.toString(Constants.DEFAULT_XML_CHARSET));
+ WSDLExtensibilityElement ext = new
WSDLExtensibilityElement(Constants.WSDL_ELEMENT_POLICY, element);
+ wsdl.addExtensibilityElement(ext);
+ //optional: to obtain a better looking wsdl, register ws-policy
+ //prefix in wsdl:definitions if it is not defined there yet
+ if (wsdl.getPrefix(element.getNamespaceURI())==null)
+ {
+ wsdl.registerNamespaceURI(element.getNamespaceURI(),element.getPrefix());
+ }
+ }
+ catch (IOException ioe)
+ {
+ throw new RuntimeException("Error while converting policy to
element!");
+ }
+ }
+
+ protected void addPolicyReference(Policy policy, Extendable extendable)
+ {
+ Element element = DOMUtils.createElement(Constants.WSDL_ELEMENT_POLICYREFERENCE,
+ wsdl.getPrefix(Constants.URI_WS_POLICY), Constants.URI_WS_POLICY);
+ element.setAttribute("URI", policy.getPolicyURI());
+ //TODO!! we need to understand if the policy is local or not...
+ WSDLExtensibilityElement ext = new
WSDLExtensibilityElement(Constants.WSDL_ELEMENT_POLICYREFERENCE, element);
+ extendable.addExtensibilityElement(ext);
+ }
+
+ protected void addPolicyURIAttribute(Policy policy, Extendable extendable)
+ {
+ //TODO!! we need to understand if the policy is local or not...
+ extendable.addProperty(new WSDLProperty(Constants.WSDL_PROPERTY_POLICYURIS,
policy.getPolicyURI()));
+ }
}