Author: alessio.soldano(a)jboss.com
Date: 2013-06-05 13:52:03 -0400 (Wed, 05 Jun 2013)
New Revision: 17651
Added:
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/EndpointPolicyAttachments.java
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicyAttachment.java
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicyAttachmentStore.java
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicySets.java
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicySetsAnnotationListener.java
stack/cxf/branches/JBWS-3648/modules/client/src/test/java/org/jboss/wsf/stack/cxf/policy/
stack/cxf/branches/JBWS-3648/modules/client/src/test/java/org/jboss/wsf/stack/cxf/policy/PolicySetsTest.java
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/WS-SP-EX224-BINDING.xml
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/WS-SP-EX224-BINDING_OPERATION_INPUT.xml
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/WS-SP-EX224-BINDING_OPERATION_OUTPUT.xml
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/org.jboss.wsf.stack.cxf.policy.PolicyAttachmentStore
Log:
Adding components for parsing policy attachments and a preliminary cxf bean listener to
add policies to endpoints / wsdl contracts
Added:
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/EndpointPolicyAttachments.java
===================================================================
---
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/EndpointPolicyAttachments.java
(rev 0)
+++
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/EndpointPolicyAttachments.java 2013-06-05
17:52:03 UTC (rev 17651)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.policy;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.annotations.Policy.Placement;
+
+
+/**
+ * A class for collecting policy attachments for a given endpoint
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 03-Jun-2013
+ *
+ */
+public class EndpointPolicyAttachments
+{
+ private Map<Placement, List<PolicyAttachment>> attachmentMap;
+
+ private EndpointPolicyAttachments(Map<Placement, List<PolicyAttachment>>
attachmentMap) {
+ this.attachmentMap = attachmentMap;
+ }
+
+ public static EndpointPolicyAttachments newInstance(String[] sets,
PolicyAttachmentStore store) {
+ Map<Placement, List<PolicyAttachment>> map = new HashMap<Placement,
List<PolicyAttachment>>();
+ for (String set : sets) {
+ List<PolicyAttachment> attachments = store.get(set);
+ for (PolicyAttachment attachment: attachments) {
+ Placement p = attachment.getPlacement();
+ if (map.containsKey(p)) {
+ map.get(p).add(attachment);
+ } else {
+ List<PolicyAttachment> list = new
ArrayList<PolicyAttachment>(4);
+ list.add(attachment);
+ map.put(attachment.getPlacement(), list);
+ }
+ }
+ }
+ return new EndpointPolicyAttachments(map);
+ }
+
+ public List<PolicyAttachment> getPolicyAttachments(Placement placement)
+ {
+ List<PolicyAttachment> pal = attachmentMap.get(placement);
+ if (pal == null) {
+ return Collections.emptyList();
+ } else {
+ return pal;
+ }
+ }
+}
Added:
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicyAttachment.java
===================================================================
---
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicyAttachment.java
(rev 0)
+++
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicyAttachment.java 2013-06-05
17:52:03 UTC (rev 17651)
@@ -0,0 +1,133 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.policy;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.cxf.annotations.Policy.Placement;
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.resource.ExtendedURIResolver;
+import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.cxf.ws.policy.PolicyConstants;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+
+/**
+ * A lazy-loaded Policy attachment reference
+ * with the placement point it is meant for.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 03-Jun-2013
+ *
+ */
+public class PolicyAttachment
+{
+ private Placement placement;
+ private String uri;
+
+ public PolicyAttachment(Placement placement, String uri)
+ {
+ this.placement = placement;
+ this.uri = uri;
+ }
+
+ public Placement getPlacement()
+ {
+ return placement;
+ }
+
+// public Element read(String defName)
+// {
+// String id = uri;
+// ExtendedURIResolver resolver = new ExtendedURIResolver();
+// InputSource src = resolver.resolve(id, "classpath:");
+// if (null == src)
+// {
+// return null;
+// }
+// XMLStreamReader reader = null;
+// try
+// {
+// reader = StaxUtils.createXMLStreamReader(src);
+// Document doc = StaxUtils.read(reader);
+// Element elem = doc.getDocumentElement();
+// id = elem.getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI,
PolicyConstants.WSU_ID_ATTR_NAME);
+// if (StringUtils.isEmpty(id))
+// {
+// Attr att = doc.createAttributeNS(PolicyConstants.WSU_NAMESPACE_URI,
"wsu:" + PolicyConstants.WSU_ID_ATTR_NAME);
+// att.setNodeValue(defName);
+// elem.setAttributeNodeNS(att);
+// }
+// return elem;
+// }
+// catch (XMLStreamException e)
+// {
+// throw new RuntimeException(e);
+// }
+// finally
+// {
+// StaxUtils.close(reader);
+// }
+// }
+
+ public Element read(String defName)
+ {
+ XMLStreamReader reader = null;
+ InputStream is = null;
+ try
+ {
+ is = new URL(uri).openStream();
+ reader = StaxUtils.createXMLStreamReader(is);
+ Document doc = StaxUtils.read(reader);
+ Element elem = doc.getDocumentElement();
+ String id = elem.getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI,
PolicyConstants.WSU_ID_ATTR_NAME);
+ if (StringUtils.isEmpty(id))
+ {
+ Attr att = doc.createAttributeNS(PolicyConstants.WSU_NAMESPACE_URI,
"wsu:" + PolicyConstants.WSU_ID_ATTR_NAME);
+ att.setNodeValue(defName);
+ elem.setAttributeNodeNS(att);
+ }
+ return elem;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ StaxUtils.close(reader);
+ if (is != null) {
+ try {
+ is.close();
+ } catch (Exception e) {
+ //ignore
+ }
+ }
+ }
+ }
+}
Added:
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicyAttachmentStore.java
===================================================================
---
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicyAttachmentStore.java
(rev 0)
+++
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicyAttachmentStore.java 2013-06-05
17:52:03 UTC (rev 17651)
@@ -0,0 +1,152 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.policy;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.annotations.Policy.Placement;
+import org.jboss.wsf.stack.cxf.client.ProviderImpl;
+
+
+/**
+ * The store containing pre-defined policy attachments
+ * grouped by set name; lazy loaded on first use.
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 03-Jun-2013
+ *
+ */
+public class PolicyAttachmentStore
+{
+ private static final String POLICY_ATTACHMENT_LOCATION =
"META-INF/policies/";
+ private volatile Map<String, List<PolicyAttachment>> attachments;
+ private ClassLoader cl;
+ private static PolicyAttachmentStore defaultServerInstance;
+
+ public PolicyAttachmentStore(ClassLoader cl) {
+ this.cl = cl;
+ }
+
+ public static synchronized PolicyAttachmentStore getDefaultServerInstance() {
+ if (defaultServerInstance == null) {
+ defaultServerInstance = new
PolicyAttachmentStore(ProviderImpl.class.getClassLoader());
+ }
+ return defaultServerInstance;
+ }
+
+ public List<PolicyAttachment> get(String setName)
+ {
+ if (attachments == null) {
+ synchronized (PolicyAttachmentStore.class)
+ {
+ if (attachments == null) {
+ Map<String, List<PolicyAttachment>> map = new
HashMap<String, List<PolicyAttachment>>();
+ parsePolicyAttachmentResources(cl, map);
+ attachments = map;
+ }
+ }
+ }
+ List<PolicyAttachment> l = attachments.get(setName);
+ if (l != null && !l.isEmpty()) {
+ return Collections.unmodifiableList(l);
+ } else {
+ return Collections.emptyList();
+ }
+ }
+
+ private static void parsePolicyAttachmentResources(ClassLoader cl, Map<String,
List<PolicyAttachment>> map) {
+ try {
+ Enumeration<URL> urls = getResources(cl, POLICY_ATTACHMENT_LOCATION +
PolicyAttachmentStore.class.getName());
+ if (urls != null) {
+ while (urls.hasMoreElements()) {
+ parsePolicyAttachmentStore(urls.nextElement(), map);
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static void parsePolicyAttachmentStore(URL url, Map<String,
List<PolicyAttachment>> map) throws IOException {
+ InputStream storeStream = url.openStream();
+ if (storeStream != null) {
+ String baseUrl = url.toString();
+ baseUrl = baseUrl.substring(0, baseUrl.length() -
PolicyAttachmentStore.class.getName().length());
+ BufferedReader br = new BufferedReader(new InputStreamReader(storeStream,
"UTF-8"));
+ try {
+ String set;
+ while ((set = br.readLine()) != null) {
+ for (Placement p : Placement.values()) {
+ final String newUrl = baseUrl + set + "-" + p +
".xml";
+ final URL policyAttachmentUrl = new URL(newUrl);
+ InputStream is = null;
+ try {
+ is = policyAttachmentUrl.openStream();
+ if (is != null) {
+ if (map.containsKey(set)) {
+ map.get(set).add(new PolicyAttachment(p, newUrl));
+ } else {
+ List<PolicyAttachment> list = new
ArrayList<PolicyAttachment>(4);
+ list.add(new PolicyAttachment(p, newUrl));
+ map.put(set, list);
+ }
+ }
+ } catch (FileNotFoundException fnfe) {
+ //ignore
+ } finally {
+ if (is != null)
+ is.close();
+ }
+ }
+ }
+ } finally {
+ br.close();
+ }
+ }
+ }
+
+ private static Enumeration<URL> getResources(final ClassLoader cl, final String
filename) throws Exception {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null) {
+ return cl.getResources(filename);
+ } else {
+ return AccessController.doPrivileged(new
PrivilegedExceptionAction<Enumeration<URL>>() {
+ public Enumeration<URL> run() throws Exception {
+ return cl.getResources(filename);
+ }
+ });
+ }
+ }
+}
Added:
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicySets.java
===================================================================
---
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicySets.java
(rev 0)
+++
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicySets.java 2013-06-05
17:52:03 UTC (rev 17651)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.policy;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 04-Jun-2013
+ *
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.TYPE })
+public @interface PolicySets {
+ String[] value();
+}
Added:
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicySetsAnnotationListener.java
===================================================================
---
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicySetsAnnotationListener.java
(rev 0)
+++
stack/cxf/branches/JBWS-3648/modules/client/src/main/java/org/jboss/wsf/stack/cxf/policy/PolicySetsAnnotationListener.java 2013-06-05
17:52:03 UTC (rev 17651)
@@ -0,0 +1,298 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.policy;
+
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.wsdl.extensions.UnknownExtensibilityElement;
+
+import org.apache.cxf.annotations.Policy.Placement;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.service.factory.AbstractServiceFactoryBean;
+import org.apache.cxf.service.factory.FactoryBeanListener;
+import org.apache.cxf.service.model.AbstractPropertiesHolder;
+import org.apache.cxf.service.model.BindingFaultInfo;
+import org.apache.cxf.service.model.BindingInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.DescriptionInfo;
+import org.apache.cxf.service.model.FaultInfo;
+import org.apache.cxf.service.model.InterfaceInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.ws.policy.PolicyConstants;
+import org.apache.neethi.Constants;
+import org.jboss.logging.Logger;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * A FactoryBeanListener that adds policies according to a given map of
EndpointPolicyAttachment
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 03-Jun-2013
+ */
+public class PolicySetsAnnotationListener implements FactoryBeanListener
+{
+ private final Map<Class<?>, EndpointPolicyAttachments> epaMap = new
HashMap<Class<?>, EndpointPolicyAttachments>(); //usare la SEI come class
+ private PolicyAttachmentStore store;
+
+ public PolicySetsAnnotationListener() {
+ this.store = PolicyAttachmentStore.getDefaultServerInstance();
+ }
+
+ public PolicySetsAnnotationListener(PolicyAttachmentStore store) {
+ this.store = store;
+ }
+
+ protected EndpointPolicyAttachments getEndpointPolicyAttachment(Class<?> clazz)
{
+ if (epaMap.containsKey(clazz)) {
+ return epaMap.get(clazz);
+ } else {
+ final PolicySets ps = clazz.getAnnotation(PolicySets.class);
+ final EndpointPolicyAttachments epa = (ps != null) ?
EndpointPolicyAttachments.newInstance(ps.value(), store) : null;
+ epaMap.put(clazz, epa);
+ return epa;
+ }
+ }
+
+ public void handleEvent(Event ev, AbstractServiceFactoryBean factory, Object... args)
+ {
+// Logger.getLogger(this.getClass()).info("**** EVENT: " + ev + "#
Args: ");
+// for (Object o : args) {
+// Logger.getLogger(this.getClass()).info(o);
+// }
+ switch (ev)
+ {
+// case INTERFACE_CREATED : {
+// InterfaceInfo ii = (InterfaceInfo) args[0];
+// Class<?> cls = (Class<?>) args[1];
+// addPolicies(factory, ii, cls);
+// break;
+// }
+
+ case ENDPOINT_SELECTED : {
+ Class<?> cls = (Class<?>) args[2];
+ //Class<?> implCls = (Class<?>) args[3];
+ Endpoint ep = (Endpoint) args[1];
+ if (ep.getEndpointInfo().getInterface() != null)
+ {
+ addPolicies(factory, ep, cls);
+ }
+ break;
+ }
+
+ case INTERFACE_OPERATION_BOUND : { //TODO possibly remove either this block or
next one
+ OperationInfo inf = (OperationInfo) args[0];
+ Method m = (Method) args[1];
+ addPolicies(factory, inf, m);
+ break;
+ }
+
+ case BINDING_OPERATION_CREATED :
+ BindingOperationInfo boi = (BindingOperationInfo) args[1];
+ Method m = (Method) args[2];
+ addPolicies(factory, boi.getOperationInfo(), m);
+ break;
+
+ default :
+ //ignore
+ }
+ }
+
+ private void addPolicies(AbstractServiceFactoryBean factory, OperationInfo inf, Method
m)
+ {
+ if (m == null)
+ {
+ return;
+ }
+
+ final Class<?> cls = m.getDeclaringClass();
+ EndpointPolicyAttachments epa = getEndpointPolicyAttachment(cls);
+ if (epa != null)
+ {
+ final ServiceInfo service = inf.getInterface().getService();
+ for (PolicyAttachment pa :
epa.getPolicyAttachments(Placement.PORT_TYPE_OPERATION)) {
+ addPolicy(inf, service, pa, cls, inf.getName().getLocalPart() +
"PortTypeOpPolicy");
+ }
+ for (PolicyAttachment pa :
epa.getPolicyAttachments(Placement.PORT_TYPE_OPERATION_INPUT)) {
+ addPolicy(inf.getInput(), service, pa, cls, inf.getName().getLocalPart() +
"PortTypeOpInputPolicy");
+ }
+ for (PolicyAttachment pa :
epa.getPolicyAttachments(Placement.PORT_TYPE_OPERATION_OUTPUT)) {
+ addPolicy(inf.getOutput(), service, pa, cls, inf.getName().getLocalPart() +
"PortTypeOpOutputPolicy");
+ }
+ for (PolicyAttachment pa :
epa.getPolicyAttachments(Placement.PORT_TYPE_OPERATION_FAULT)) {
+ for (FaultInfo f : inf.getFaults())
+ {
+ addPolicy(f, service, pa, cls, f.getName().getLocalPart() +
"PortTypeOpFaultPolicy");
+ }
+ }
+ }
+ }
+
+ private void addPolicies(AbstractServiceFactoryBean factory, Endpoint ep,
Class<?> cls)
+ {
+ final EndpointPolicyAttachments epa = getEndpointPolicyAttachment(cls);
+ if (epa != null) {
+ final BindingInfo binf = ep.getBinding().getBindingInfo();
+ final ServiceInfo si = ep.getService().getServiceInfos().get(0);
+ final InterfaceInfo inf = ep.getEndpointInfo().getInterface();
+
+ for (PolicyAttachment pa : epa.getPolicyAttachments(Placement.BINDING)) {
+ addPolicy(binf, si, pa, cls, binf.getName().getLocalPart() +
"BindingPolicy");
+ }
+ for (PolicyAttachment pa : epa.getPolicyAttachments(Placement.PORT_TYPE)) {
+ addPolicy(inf, si, pa, cls, inf.getName().getLocalPart() +
"PortTypePolicy");
+ }
+ for (PolicyAttachment pa : epa.getPolicyAttachments(Placement.SERVICE)) {
+ addPolicy(si, si, pa, cls, si.getName().getLocalPart() +
"ServicePolicy");
+ }
+ for (PolicyAttachment pa : epa.getPolicyAttachments(Placement.SERVICE_PORT)) {
+ addPolicy(ep.getEndpointInfo(), si, pa, cls,
ep.getEndpointInfo().getName().getLocalPart()
+ + "PortPolicy");
+ }
+
+ for (BindingOperationInfo binfo : binf.getOperations())
+ {
+ for (PolicyAttachment pa :
epa.getPolicyAttachments(Placement.BINDING_OPERATION)) {
+ addPolicy(binfo, si, pa, cls, binfo.getName().getLocalPart() +
"BindingOpPolicy");
+ }
+ for (PolicyAttachment pa :
epa.getPolicyAttachments(Placement.BINDING_OPERATION_INPUT)) {
+ addPolicy(binfo.getInput(), si, pa, cls, binfo.getName().getLocalPart()
+ + "BindingOpInputPolicy");
+ }
+ for (PolicyAttachment pa :
epa.getPolicyAttachments(Placement.BINDING_OPERATION_OUTPUT)) {
+ addPolicy(binfo.getOutput(), si, pa, cls, binfo.getName().getLocalPart()
+ + "BindingOpOutputPolicy");
+ }
+ for (PolicyAttachment pa :
epa.getPolicyAttachments(Placement.BINDING_OPERATION_FAULT)) {
+ for (BindingFaultInfo f : binfo.getFaults())
+ {
+ addPolicy(f, si, pa, cls, f.getFaultInfo().getName().getLocalPart()
+ + "BindingOpFaultPolicy");
+ }
+ }
+ }
+ }
+ }
+
+// private void addPolicies(AbstractServiceFactoryBean factory, InterfaceInfo ii,
Class<?> cls)
+// {
+// if (cls == null)
+// {
+// return;
+// }
+// EndpointPolicyAttachment epa = epaMap.get(cls);
+// if (epa != null)
+// {
+// for (PolicyAttachment pa : epa.getPolicyAttachment(Placement.PORT_TYPE)) {
+// addPolicy(ii, ii.getService(), pa, cls, ii.getName().getLocalPart() +
"PortTypePolicy");
+// }
+// for (PolicyAttachment pa : epa.getPolicyAttachment(Placement.SERVICE)) {
+// addPolicy(ii, ii.getService(), pa, cls, ii.getName().getLocalPart() +
"PortTypePolicy");
+// }
+// }
+// }
+
+ private void addPolicy(AbstractPropertiesHolder place, ServiceInfo service,
PolicyAttachment pa, Class<?> cls, String defName)
+ {
+ Element el = addPolicy(service, pa, cls, defName);
+ if (el != null)
+ {
+ UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
+ uee.setElement(el);
+ uee.setRequired(true);
+ uee.setElementType(DOMUtils.getElementQName(el));
+ place.addExtensor(uee);
+ }
+ }
+
+ private Element addPolicy(ServiceInfo service, PolicyAttachment pa, Class<?>
cls, String defName)
+ {
+ Element element = pa.read(defName);
+ if (element == null)
+ {
+ return null;
+ }
+
+ // might have been updated on load policy
+ String refId = getPolicyId(element);
+
+ if (service.getDescription() == null && cls != null)
+ {
+ service.setDescription(new DescriptionInfo());
+ URL u = cls.getResource("/");
+ if (u != null)
+ {
+ service.getDescription().setBaseURI(u.toString());
+ }
+ }
+
+ // if not already added to service add it, otherwise ignore
+ // and just create the policy reference.
+ if (!isExistsPolicy(service, refId))
+ {
+ UnknownExtensibilityElement uee = new UnknownExtensibilityElement();
+ uee.setElement(element);
+ uee.setRequired(true);
+ uee.setElementType(DOMUtils.getElementQName(element));
+ service.getDescription().addExtensor(uee);
+ }
+
+ refId = "#" + refId;
+
+ Document doc = DOMUtils.createDocument();
+ Element el = doc.createElementNS(element.getNamespaceURI(), "wsp:" +
Constants.ELEM_POLICY_REF);
+ Attr att = doc.createAttributeNS(null, "URI");
+ att.setValue(refId);
+ el.setAttributeNodeNS(att);
+ return el;
+ }
+
+ private String getPolicyId(Element element)
+ {
+ return element.getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI,
PolicyConstants.WSU_ID_ATTR_NAME);
+ }
+
+ private boolean isExistsPolicy(ServiceInfo service, String uri)
+ {
+ Object exts[] = service.getDescription().getExtensors().get();
+ exts = exts == null ? new Object[0] : exts;
+ for (Object o : exts)
+ {
+ if (o instanceof UnknownExtensibilityElement)
+ {
+ UnknownExtensibilityElement uee = (UnknownExtensibilityElement) o;
+ String uri2 = getPolicyId(uee.getElement());
+ if (uri.equals(uri2))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+}
Added:
stack/cxf/branches/JBWS-3648/modules/client/src/test/java/org/jboss/wsf/stack/cxf/policy/PolicySetsTest.java
===================================================================
---
stack/cxf/branches/JBWS-3648/modules/client/src/test/java/org/jboss/wsf/stack/cxf/policy/PolicySetsTest.java
(rev 0)
+++
stack/cxf/branches/JBWS-3648/modules/client/src/test/java/org/jboss/wsf/stack/cxf/policy/PolicySetsTest.java 2013-06-05
17:52:03 UTC (rev 17651)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2012, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wsf.stack.cxf.policy;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.annotations.Policy.Placement;
+import org.junit.Test;
+import org.w3c.dom.Element;
+
+
+/**
+ * A test case of basic policy sets parsing
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 04-Jun-2013
+ *
+ */
+public class PolicySetsTest extends TestCase
+{
+ @Test
+ public void testStore() throws Exception {
+ PolicyAttachmentStore paStore = new
PolicyAttachmentStore(PolicySetsTest.class.getClassLoader());
+ List<PolicyAttachment> pas =
paStore.get("WS-SP-EX224_WSS11_Mutual_Auth_X509_Sign_Encrypt");
+ assertNotNull(pas);
+ assertEquals(3, pas.size());
+ pas = paStore.get("Foo");
+ assertNotNull(pas);
+ assertEquals(0, pas.size());
+ }
+
+ @Test
+ public void testPolicyAttachmentRead() throws Exception {
+ PolicyAttachmentStore paStore = new
PolicyAttachmentStore(PolicySetsTest.class.getClassLoader());
+ List<PolicyAttachment> pas =
paStore.get("WS-SP-EX224_WSS11_Mutual_Auth_X509_Sign_Encrypt");
+ assertNotNull(pas);
+ for (PolicyAttachment pa : pas) {
+ Element el = pa.read("foo");
+ assertEquals("Policy", el.getLocalName());
+
assertEquals("http://www.w3.org/ns/ws-policy", el.getNamespaceURI());
+ }
+ }
+
+ @Test
+ public void testEndpointPolicyAttachments() throws Exception {
+ PolicyAttachmentStore store = new
PolicyAttachmentStore(PolicySetsTest.class.getClassLoader());
+ EndpointPolicyAttachments epa = EndpointPolicyAttachments.newInstance(new
String[]{""}, store);
+ for (Placement p : Placement.values()) {
+ assertEquals(0, epa.getPolicyAttachments(p).size());
+ }
+ epa = EndpointPolicyAttachments.newInstance(new String[]{"fafds"},
store);
+ for (Placement p : Placement.values()) {
+ assertEquals(0, epa.getPolicyAttachments(p).size());
+ }
+ epa = EndpointPolicyAttachments.newInstance(new String[]{"Foooo",
"WS-SP-EX224_WSS11_Mutual_Auth_X509_Sign_Encrypt"}, store);
+ for (Placement p : Placement.values()) {
+ if (p == Placement.BINDING || p == Placement.BINDING_OPERATION_INPUT || p ==
Placement.BINDING_OPERATION_OUTPUT) {
+ List<PolicyAttachment> pas = epa.getPolicyAttachments(p);
+ assertNotNull(pas);
+ assertEquals(1, pas.size());
+ assertNotNull(pas.iterator().next().read(""));
+ } else {
+ assertEquals(0, epa.getPolicyAttachments(p).size());
+ }
+ }
+ }
+}
\ No newline at end of file
Added:
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/WS-SP-EX224-BINDING.xml
===================================================================
---
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/WS-SP-EX224-BINDING.xml
(rev 0)
+++
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/WS-SP-EX224-BINDING.xml 2013-06-05
17:52:03 UTC (rev 17651)
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wsp:Policy wsu:Id="WS-SP-EX224_binding_policy"
+
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-w...
+
xmlns:wsp="http://www.w3.org/ns/ws-policy"
+
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702&...
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:SymmetricBinding>
+ <wsp:Policy>
+ <sp:ProtectionToken>
+ <wsp:Policy>
+ <sp:X509Token
sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/...
+ <wsp:Policy>
+ <sp:RequireDerivedKeys/>
+ <sp:RequireThumbprintReference/>
+ <sp:WssX509V3Token11/>
+ </wsp:Policy>
+ </sp:X509Token>
+ </wsp:Policy>
+ </sp:ProtectionToken>
+ <sp:AlgorithmSuite>
+ <wsp:Policy>
+ <sp:Basic256/>
+ </wsp:Policy>
+ </sp:AlgorithmSuite>
+ <sp:Layout>
+ <wsp:Policy>
+ <sp:Strict/>
+ </wsp:Policy>
+ </sp:Layout>
+ <sp:IncludeTimestamp/>
+ <sp:OnlySignEntireHeadersAndBody/>
+ </wsp:Policy>
+ </sp:SymmetricBinding>
+ <sp:EndorsingSupportingTokens>
+ <wsp:Policy>
+ <sp:X509Token
sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/...
+ <wsp:Policy>
+ <sp:RequireThumbprintReference/>
+ <sp:WssX509V3Token11/>
+ </wsp:Policy>
+ </sp:X509Token>
+ </wsp:Policy>
+ </sp:EndorsingSupportingTokens>
+ <sp:Wss11>
+ <wsp:Policy>
+ <sp:MustSupportRefKeyIdentifier/>
+ <sp:MustSupportRefIssuerSerial/>
+ <sp:MustSupportRefThumbprint/>
+ <sp:MustSupportRefEncryptedKey/>
+ <sp:RequireSignatureConfirmation/>
+ </wsp:Policy>
+ </sp:Wss11>
+ </wsp:All>
+ </wsp:ExactlyOne>
+</wsp:Policy>
\ No newline at end of file
Added:
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/WS-SP-EX224-BINDING_OPERATION_INPUT.xml
===================================================================
---
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/WS-SP-EX224-BINDING_OPERATION_INPUT.xml
(rev 0)
+++
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/WS-SP-EX224-BINDING_OPERATION_INPUT.xml 2013-06-05
17:52:03 UTC (rev 17651)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wsp:Policy wsu:Id="WS-SP-EX224_Binding_Operation_Input_Policy"
+
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-w...
+
xmlns:wsp="http://www.w3.org/ns/ws-policy"
+
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702&...
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:EncryptedParts>
+ <sp:Body/>
+ </sp:EncryptedParts>
+ <sp:SignedParts>
+ <sp:Body/>
+ </sp:SignedParts>
+ </wsp:All>
+ </wsp:ExactlyOne>
+</wsp:Policy>
\ No newline at end of file
Added:
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/WS-SP-EX224-BINDING_OPERATION_OUTPUT.xml
===================================================================
---
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/WS-SP-EX224-BINDING_OPERATION_OUTPUT.xml
(rev 0)
+++
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/WS-SP-EX224-BINDING_OPERATION_OUTPUT.xml 2013-06-05
17:52:03 UTC (rev 17651)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wsp:Policy wsu:Id="WS-SP-EX224_Binding_Operation_Output_Policy"
+
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-w...
+
xmlns:wsp="http://www.w3.org/ns/ws-policy"
+
xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702&...
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:EncryptedParts>
+ <sp:Body/>
+ </sp:EncryptedParts>
+ <sp:SignedParts>
+ <sp:Body/>
+ </sp:SignedParts>
+ </wsp:All>
+ </wsp:ExactlyOne>
+</wsp:Policy>
\ No newline at end of file
Added:
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/org.jboss.wsf.stack.cxf.policy.PolicyAttachmentStore
===================================================================
---
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/org.jboss.wsf.stack.cxf.policy.PolicyAttachmentStore
(rev 0)
+++
stack/cxf/branches/JBWS-3648/modules/client/src/test/resources/META-INF/policies/org.jboss.wsf.stack.cxf.policy.PolicyAttachmentStore 2013-06-05
17:52:03 UTC (rev 17651)
@@ -0,0 +1 @@
+WS-SP-EX224
\ No newline at end of file