On 12/22/05, Sanjiva Weerawarana <[EMAIL PROTECTED]> wrote:
> Hi Sanka,
>
> > > I would like to propose the following patch which allow the
> > > AxisConfiguration to hold policy information define in axis2.xml
> > >
> > > Thoughts ?
>
> Can you send a brief explanation of how this is integrated and how it
> works please?
We should allow the system administrator to define policies which are
valid for the entire system. That information should be written in
axis2.xml
We should also allow the service author to define policies which are valid for a
a) Service
b) Operation
c) Message
That information should be written in services.xml
Module authors should also be allowed to define policies and that
information should be written in module.xml
To hold Policy information at deployment time I suggest the followings:
(1) Added: PolicyInclude class
This class holds a Policy which is the current effective policy and a
PolicyRegistry which holds Policies with distinct URIs. It provides
methods to add a Policy which is merged to its effective policy
(which also being stored in the PolicyRegistry if the added policy has
a URI) and to add a PolicyReference (which is resolved to a known
Policy and then is merged to the current effective policy).
PolicyInclude provices a constructor which takes a PolicyInclude
object as the parent. If a PolicyRefernece can not be resolved using
the local registry it is looked up in the parent PolicyInclude.
(2) Modified: AxisConfiguration, AxisService, AxisOperation ...
To hold an instance of PolicyInclude object and to provide getter and
setter methods for it.
(3) Modified: DescriptionBuilder
To process <wsp:Policy> , <wsp:PolicyRefenece ..> elements and
generate Policy and PolicyRefence objects repectively. These objects
are added to a PolicyInclude object which is provided as the argument.
(4) Modified: AxisConfigBuilder, ServiceBuilder, ModuleBuilder ,,
To generate an appropriate PolicyInclude object and set it in the
appropriate description class
Best,
Sanka
>
> Thanks,
>
> Sanjiva.
>
>
>
Index: core/src/org/apache/axis2/deployment/AxisConfigBuilder.java
===================================================================
--- core/src/org/apache/axis2/deployment/AxisConfigBuilder.java (revision 358602)
+++ core/src/org/apache/axis2/deployment/AxisConfigBuilder.java (working copy)
@@ -107,6 +107,25 @@
if (hostElement != null) {
processHostCongiguration(hostElement, axisConfiguration);
}
+
+ // setting the PolicyInclude
+ PolicyInclude policyInclude = new PolicyInclude();
+ axisConfiguration.setPolicyInclude(policyInclude);
+
+ // processing <wsp:Policy> .. </..> elements
+ Iterator policyElements = config_element.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY));
+
+ if (policyElements != null) {
+ processPolicyElements(policyElements, axisConfiguration.getPolicyInclude());
+ }
+
+ // processing <wsp:PolicyReference> .. </..> elements
+ Iterator policyRefElements = config_element.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY_REF));
+
+ if (policyRefElements != null) {
+ processPolicyRefElements(policyElements, axisConfiguration.getPolicyInclude());
+ }
+
} catch (XMLStreamException e) {
throw new DeploymentException(e);
}
Index: core/src/org/apache/axis2/deployment/ServiceBuilder.java
===================================================================
--- core/src/org/apache/axis2/deployment/ServiceBuilder.java (revision 358602)
+++ core/src/org/apache/axis2/deployment/ServiceBuilder.java (working copy)
@@ -25,6 +25,7 @@
import org.apache.axis2.i18n.Messages;
import org.apache.axis2.om.OMAttribute;
import org.apache.axis2.om.OMElement;
+import org.apache.ws.policy.util.PolicyRegistry;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
@@ -51,7 +52,7 @@
public ServiceBuilder(InputStream serviceInputStream, AxisConfiguration axisConfig,
AxisService service) {
super(serviceInputStream, axisConfig);
- this.service = service;
+ this.service = service;
}
/**
@@ -89,6 +90,25 @@
service.setServiceDescription(serviceNameatt.getAttributeValue());
}
}
+
+ // setting the PolicyInclude
+ PolicyInclude parent = axisConfig.getPolicyInclude();
+ PolicyInclude policyInclude = new PolicyInclude(parent);
+ service.setPolicyInclude(policyInclude);
+
+ // processing <wsp:Policy> .. </..> elements
+ Iterator policyElements = service_element.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY));
+
+ if (policyElements != null) {
+ processPolicyElements(policyElements, service.getPolicyInclude());
+ }
+
+ // processing <wsp:PolicyReference> .. </..> elements
+ Iterator policyRefElements = service_element.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY_REF));
+
+ if (policyRefElements != null) {
+ processPolicyRefElements(policyRefElements, service.getPolicyInclude());
+ }
// processing servicewide modules which required to engage gloabally
Iterator moduleRefs = service_element.getChildrenWithName(new QName(TAG_MODULE));
@@ -126,6 +146,10 @@
Iterator moduleConfigs = service_element.getChildrenWithName(new QName(TAG_MODULE_CONFIG));
processServiceModuleConfig(moduleConfigs, service, service);
+
+
+
+
} catch (XMLStreamException e) {
throw new DeploymentException(e);
} catch (AxisFault axisFault) {
@@ -148,8 +172,29 @@
AxisMessage message = new AxisMessage();
Iterator parameters = messageElement.getChildrenWithName(new QName(TAG_PARAMETER));
+
+ // setting the PolicyInclude
+ PolicyInclude parent = operation.getPolicyInclude();
+ PolicyInclude policyInclude = new PolicyInclude(parent);
+ message.setPolicyInclude(policyInclude);
+
+ // processing <wsp:Policy> .. </..> elements
+ Iterator policyElements = messageElement.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY));
+
+ if (policyElements != null) {
+ processPolicyElements(policyElements, message.getPolicyInclude());
+ }
+
+ // processing <wsp:PolicyReference> .. </..> elements
+ Iterator policyRefElements = messageElement.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY_REF));
+
+ if (policyRefElements != null) {
+ processPolicyRefElements(policyRefElements, message.getPolicyInclude());
+ }
processParameters(parameters, message, operation);
+
+
operation.addMessage(message, lable.getAttributeValue().trim());
}
}
@@ -240,7 +285,26 @@
}
op_descrip.setName(new QName(opname));
}
-
+
+ // setting the PolicyInclude
+ PolicyInclude parent = axisConfig.getPolicyInclude();
+ PolicyInclude policyInclude = new PolicyInclude(parent);
+ op_descrip.setPolicyInclude(policyInclude);
+
+ // processing <wsp:Policy> .. </..> elements
+ Iterator policyElements = operation.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY));
+
+ if (policyElements != null) {
+ processPolicyElements(policyElements, op_descrip.getPolicyInclude());
+ }
+
+ // processing <wsp:PolicyReference> .. </..> elements
+ Iterator policyRefElements = operation.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY_REF));
+
+ if (policyRefElements != null) {
+ processPolicyRefElements(policyRefElements, op_descrip.getPolicyInclude());
+ }
+
// Operation Parameters
Iterator parameters = operation.getChildrenWithName(new QName(TAG_PARAMETER));
ArrayList wsamappings = processParameters(parameters, op_descrip, service);
@@ -281,7 +345,7 @@
Iterator moduleConfigs = operation.getChildrenWithName(new QName(TAG_MODULE_CONFIG));
processOperationModuleConfig(moduleConfigs, op_descrip, op_descrip);
-
+
// adding the operation
operations.add(op_descrip);
}
@@ -309,5 +373,6 @@
service.addModuleConfig(moduleConfiguration);
}
}
- }
+ }
+
}
Index: core/src/org/apache/axis2/deployment/DeploymentConstants.java
===================================================================
--- core/src/org/apache/axis2/deployment/DeploymentConstants.java (revision 358602)
+++ core/src/org/apache/axis2/deployment/DeploymentConstants.java (working copy)
@@ -90,4 +90,9 @@
String BOOLEAN_FALSE = "false";
char SEPARATOR_DOT = '.';
char SEPARATOR_COLON = ':';
+
+ String POLICY_NS_URI = "http://schemas.xmlsoap.org/ws/2004/09/policy";
+ String TAG_POLICY = "Policy";
+ String TAG_POLICY_REF = "PolicyReference";
+
}
Index: core/src/org/apache/axis2/deployment/DescriptionBuilder.java
===================================================================
--- core/src/org/apache/axis2/deployment/DescriptionBuilder.java (revision 358602)
+++ core/src/org/apache/axis2/deployment/DescriptionBuilder.java (working copy)
@@ -30,6 +30,10 @@
import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.ws.policy.Policy;
+import org.apache.ws.policy.PolicyReference;
+import org.apache.ws.policy.util.OMPolicyReader;
+import org.apache.ws.policy.util.PolicyFactory;
import org.apache.wsdl.WSDLConstants;
import javax.xml.namespace.QName;
@@ -371,7 +375,33 @@
return wsamapping;
}
+
+ protected void processPolicyElements(Iterator policyElements,
+ PolicyInclude policyInclude) {
+ OMPolicyReader reader = (OMPolicyReader) PolicyFactory
+ .getPolicyReader(PolicyFactory.OM_POLICY_READER);
+ OMElement policyElement;
+ while (policyElements.hasNext()) {
+ Policy p = reader.readPolicy((OMElement) policyElements.next());
+ policyInclude.addPolicy(p);
+ }
+ }
+
+ protected void processPolicyRefElements(Iterator policyRefElements,
+ PolicyInclude policyInclude) {
+ OMPolicyReader reader = (OMPolicyReader) PolicyFactory
+ .getPolicyReader(PolicyFactory.OM_POLICY_READER);
+ OMElement policyRefElement;
+
+ while (policyRefElements.hasNext()) {
+ PolicyReference policyReference = reader
+ .readPolicyReference((OMElement) policyRefElements.next());
+ policyInclude.addPolicyReference(policyReference);
+ }
+ }
+
+
/**
* This method is used to retrive service name form the arechive file name
* if the archive file name is service1.aar , then axis service name would be service1
Index: core/src/org/apache/axis2/deployment/ModuleBuilder.java
===================================================================
--- core/src/org/apache/axis2/deployment/ModuleBuilder.java (revision 358602)
+++ core/src/org/apache/axis2/deployment/ModuleBuilder.java (working copy)
@@ -23,6 +23,7 @@
import org.apache.axis2.description.AxisOperationFactory;
import org.apache.axis2.description.InOnlyAxisOperation;
import org.apache.axis2.description.ModuleDescription;
+import org.apache.axis2.description.PolicyInclude;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.MessageReceiver;
import org.apache.axis2.i18n.Messages;
@@ -90,6 +91,25 @@
loadModuleClass(module, moduleClass);
}
}
+
+ // setting the PolicyInclude
+ PolicyInclude parent = axisConfig.getPolicyInclude();
+ PolicyInclude policyInclude = new PolicyInclude(parent);
+ module.setPolicyInclude(policyInclude);
+
+ // processing <wsp:Policy> .. </..> elements
+ Iterator policyElements = moduleElement.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY));
+
+ if (policyElements != null) {
+ processPolicyElements(policyElements, module.getPolicyInclude());
+ }
+
+ // processing <wsp:PolicyReference> .. </..> elements
+ Iterator policyRefElements = moduleElement.getChildrenWithName(new QName(POLICY_NS_URI, TAG_POLICY_REF));
+
+ if (policyRefElements != null) {
+ processPolicyRefElements(policyRefElements, module.getPolicyInclude());
+ }
// processing Parameters
// Processing service level parameters
Index: core/src/org/apache/axis2/description/PolicyInclude.java
===================================================================
--- core/src/org/apache/axis2/description/PolicyInclude.java (revision 0)
+++ core/src/org/apache/axis2/description/PolicyInclude.java (revision 0)
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.description;
+
+import java.util.HashMap;
+import java.util.Hashtable;
+
+import org.apache.ws.policy.Policy;
+import org.apache.ws.policy.PolicyReference;
+import org.apache.ws.policy.util.PolicyRegistry;
+
+/**
+ * @author Sanka Samaranayake ([EMAIL PROTECTED])
+ */
+public class PolicyInclude {
+
+ private Policy policy = null;
+ private PolicyInclude parent = null;
+ private PolicyRegistry reg;
+
+ public PolicyInclude() {
+ reg = new PolicyRegistry();
+ }
+
+ public PolicyInclude(PolicyInclude parent) {
+ this.parent = parent;
+ }
+
+ public Policy getPolicy(String policyURI) {
+
+ if (reg.lookup(policyURI) != null) {
+ return (Policy) reg.lookup(policyURI);
+ }
+
+ if (parent != null) {
+ return parent.getPolicy(policyURI);
+ }
+ return null;
+ }
+
+ public void setPolicy(Policy policy) {
+ this.policy = policy;
+ }
+
+ public Policy getPolicy() {
+ return policy;
+ }
+
+ public void addPolicy(Policy nPolicy) {
+
+ if (policy == null) {
+ policy = nPolicy;
+
+ } else {
+ policy = (Policy) policy.merge(nPolicy, reg);
+ }
+
+ if (nPolicy.getPolicyURI() != null) {
+ reg.register(nPolicy.getPolicyURI(), nPolicy);
+ }
+ }
+
+ public void addPolicyReference(PolicyReference policyReference) {
+ addPolicy((Policy) policyReference.normalize(reg));
+ }
+}
Index: core/src/org/apache/axis2/description/AxisMessage.java
===================================================================
--- core/src/org/apache/axis2/description/AxisMessage.java (revision 358602)
+++ core/src/org/apache/axis2/description/AxisMessage.java (working copy)
@@ -36,6 +36,8 @@
//to keep data in WSDL message refference and to keep the Java2WSDL data
// such as SchemaElementName , direction etc.
private MessageReference messageReference;
+
+ private PolicyInclude policyInclude;
public AxisMessage() {
parameterinclude = new ParameterIncludeImpl();
@@ -116,4 +118,12 @@
public void setElementQName(QName element) {
messageReference.setElementQName(element);
}
+
+ public void setPolicyInclude(PolicyInclude policyInclude) {
+ this.policyInclude = policyInclude;
+ }
+
+ public PolicyInclude getPolicyInclude() {
+ return policyInclude;
+ }
}
Index: core/src/org/apache/axis2/description/AxisService.java
===================================================================
--- core/src/org/apache/axis2/description/AxisService.java (revision 358602)
+++ core/src/org/apache/axis2/description/AxisService.java (working copy)
@@ -82,6 +82,9 @@
//to store default message receivers
private HashMap messageReceivers;
+
+ // to store policies which are valid for the entire service
+ private PolicyInclude policyInclude;
/**
* Constructor AxisService
@@ -633,4 +636,12 @@
this.scope = scope;
}
}
+
+ public void setPolicyInclude(PolicyInclude policyInclude) {
+ this.policyInclude = policyInclude;
+ }
+
+ public PolicyInclude getPolicyInclude() {
+ return policyInclude;
+ }
}
Index: core/src/org/apache/axis2/description/AxisOperation.java
===================================================================
--- core/src/org/apache/axis2/description/AxisOperation.java (revision 358602)
+++ core/src/org/apache/axis2/description/AxisOperation.java (working copy)
@@ -53,6 +53,9 @@
private AxisService parent;
private ArrayList wsamappingList;
+
+ // to store policies which are valid for entire operation
+ private PolicyInclude policyInclude;
public AxisOperation() {
mepURI = MEP_URI_IN_OUT;
@@ -418,4 +421,12 @@
public OperationClient createClient (ServiceContext sc, Options options){
throw new UnsupportedOperationException ("The MEP you are using (" + mepURI + ") has not implemented createClient().");
}
+
+ public void setPolicyInclude(PolicyInclude policyInclude) {
+ this.policyInclude = policyInclude;
+ }
+
+ public PolicyInclude getPolicyInclude() {
+ return policyInclude;
+ }
}
Index: core/src/org/apache/axis2/description/ModuleDescription.java
===================================================================
--- core/src/org/apache/axis2/description/ModuleDescription.java (revision 358602)
+++ core/src/org/apache/axis2/description/ModuleDescription.java (working copy)
@@ -57,6 +57,11 @@
// to store module operations , which are suppose to be added to a service if it is engaged to a service
private HashMap operations;
private AxisConfiguration parent;
+
+ /*
+ * to store policies which are falid for any service for which the module is
+ */
+ private PolicyInclude policyInclude;
/**
* Constructor ModuleDescription
@@ -229,4 +234,12 @@
public void setParent(AxisConfiguration parent) {
this.parent = parent;
}
+
+ public void setPolicyInclude(PolicyInclude policyInclude) {
+ this.policyInclude = policyInclude;
+ }
+
+ public PolicyInclude getPolicyInclude() {
+ return policyInclude;
+ }
}
Index: core/src/org/apache/axis2/engine/AxisConfiguration.java
===================================================================
--- core/src/org/apache/axis2/engine/AxisConfiguration.java (revision 358602)
+++ core/src/org/apache/axis2/engine/AxisConfiguration.java (working copy)
@@ -67,6 +67,9 @@
private ArrayList inFaultPhases;
private ArrayList inPhasesUptoAndIncludingPostDispatch;
private HashMap messageReceivers;
+
+ // to store policies which are valid for entire system
+ private PolicyInclude policyInclude;
private ClassLoader moduleClassLoader;
private HashMap moduleConfigmap;
@@ -92,6 +95,7 @@
faultyModules = new Hashtable();
observersList = new ArrayList();
inPhasesUptoAndIncludingPostDispatch = new ArrayList();
+
systemClassLoader = Thread.currentThread().getContextClassLoader();
serviceClassLoader = Thread.currentThread().getContextClassLoader();
moduleClassLoader = Thread.currentThread().getContextClassLoader();
@@ -553,4 +557,12 @@
public void setSystemClassLoader(ClassLoader classLoader) {
this.systemClassLoader = classLoader;
}
+
+ public void setPolicyInclude(PolicyInclude policyInclude) {
+ this.policyInclude = policyInclude;
+ }
+
+ public PolicyInclude getPolicyInclude() {
+ return policyInclude;
+ }
}