Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package com.sun.xml.internal.ws.policy.jaxws; |
ohair@286 | 27 | |
ohair@286 | 28 | import com.sun.xml.internal.ws.api.model.wsdl.*; |
ohair@286 | 29 | import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension; |
ohair@286 | 30 | import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtensionContext; |
ohair@286 | 31 | import com.sun.xml.internal.ws.api.policy.PolicyResolver; |
ohair@286 | 32 | import com.sun.xml.internal.ws.resources.PolicyMessages; |
ohair@286 | 33 | import com.sun.xml.internal.ws.policy.jaxws.SafePolicyReader.PolicyRecord; |
ohair@286 | 34 | import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger; |
ohair@286 | 35 | import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils; |
ohair@286 | 36 | import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModel; |
ohair@286 | 37 | import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModelContext; |
ohair@286 | 38 | import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion; |
ohair@286 | 39 | import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.XmlToken; |
ohair@286 | 40 | import com.sun.xml.internal.ws.model.wsdl.WSDLModelImpl; |
ohair@286 | 41 | import com.sun.xml.internal.ws.policy.PolicyException; |
ohair@286 | 42 | import com.sun.xml.internal.ws.policy.PolicyMap; |
alanb@368 | 43 | import com.sun.xml.internal.ws.util.xml.XmlUtil; |
ohair@286 | 44 | |
ohair@286 | 45 | import java.io.IOException; |
ohair@286 | 46 | import java.io.InputStream; |
ohair@286 | 47 | import java.net.URI; |
ohair@286 | 48 | import java.net.URISyntaxException; |
ohair@286 | 49 | import java.net.URL; |
ohair@286 | 50 | import java.util.List; |
ohair@286 | 51 | import java.util.HashSet; |
ohair@286 | 52 | import java.util.ArrayList; |
ohair@286 | 53 | import java.util.Collection; |
ohair@286 | 54 | import java.util.HashMap; |
ohair@286 | 55 | import java.util.LinkedList; |
ohair@286 | 56 | import java.util.Map; |
ohair@286 | 57 | import javax.xml.namespace.QName; |
ohair@286 | 58 | import javax.xml.stream.XMLStreamException; |
ohair@286 | 59 | import javax.xml.stream.XMLStreamReader; |
ohair@286 | 60 | import javax.xml.stream.XMLInputFactory; |
ohair@286 | 61 | import javax.xml.ws.WebServiceException; |
alanb@368 | 62 | import javax.xml.xpath.XPathFactoryConfigurationException; |
ohair@286 | 63 | |
ohair@286 | 64 | /** |
ohair@286 | 65 | * This class parses the Policy Attachments in the WSDL and creates a PolicyMap thaty captures the policies configured on |
ohair@286 | 66 | * different PolicySubjects in the wsdl. |
ohair@286 | 67 | * |
ohair@286 | 68 | * After, it is finished it sets the PolicyMap on the WSDLModel. |
ohair@286 | 69 | * |
ohair@286 | 70 | * @author Jakub Podlesak (jakub.podlesak at sun.com) |
ohair@286 | 71 | * @author Fabian Ritzmann |
ohair@286 | 72 | * @author Rama Pulavarthi |
ohair@286 | 73 | */ |
ohair@286 | 74 | final public class PolicyWSDLParserExtension extends WSDLParserExtension { |
ohair@286 | 75 | |
ohair@286 | 76 | enum HandlerType { |
ohair@286 | 77 | PolicyUri, AnonymousPolicyId |
ohair@286 | 78 | } |
ohair@286 | 79 | |
ohair@286 | 80 | final static class PolicyRecordHandler { |
ohair@286 | 81 | String handler; |
ohair@286 | 82 | HandlerType type; |
ohair@286 | 83 | |
ohair@286 | 84 | PolicyRecordHandler(HandlerType type, String handler) { |
ohair@286 | 85 | this.type = type; |
ohair@286 | 86 | this.handler = handler; |
ohair@286 | 87 | } |
ohair@286 | 88 | |
ohair@286 | 89 | HandlerType getType() { |
ohair@286 | 90 | return type; |
ohair@286 | 91 | } |
ohair@286 | 92 | |
ohair@286 | 93 | String getHandler() { |
ohair@286 | 94 | return handler; |
ohair@286 | 95 | } |
ohair@286 | 96 | } |
ohair@286 | 97 | |
ohair@286 | 98 | private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyWSDLParserExtension.class); |
ohair@286 | 99 | |
ohair@286 | 100 | //anonymous policy id prefix |
ohair@286 | 101 | private static final StringBuffer AnonymnousPolicyIdPrefix = new StringBuffer("#__anonymousPolicy__ID"); |
ohair@286 | 102 | |
ohair@286 | 103 | // anonymous policies count |
ohair@286 | 104 | private int anonymousPoliciesCount; |
ohair@286 | 105 | |
ohair@286 | 106 | private final SafePolicyReader policyReader = new SafePolicyReader(); |
ohair@286 | 107 | |
ohair@286 | 108 | // policy queue -- needed for evaluating the right order policy of policy models expansion |
ohair@286 | 109 | private PolicyRecord expandQueueHead = null; |
ohair@286 | 110 | |
ohair@286 | 111 | // storage for policy models with an id passed by |
ohair@286 | 112 | private Map<String,PolicyRecord> policyRecordsPassedBy = null; |
ohair@286 | 113 | // storage for anonymous policies defined within given WSDL |
ohair@286 | 114 | private Map<String,PolicySourceModel> anonymousPolicyModels = null; |
ohair@286 | 115 | |
ohair@286 | 116 | // container for URIs of policies referenced |
ohair@286 | 117 | private List<String> unresolvedUris = null; |
ohair@286 | 118 | |
ohair@286 | 119 | // structures for policies really needed to build a map |
ohair@286 | 120 | private final LinkedList<String> urisNeeded = new LinkedList<String>(); |
ohair@286 | 121 | private final Map<String, PolicySourceModel> modelsNeeded = new HashMap<String, PolicySourceModel>(); |
ohair@286 | 122 | |
ohair@286 | 123 | // lookup tables for Policy attachments found |
ohair@286 | 124 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4ServiceMap = null; |
ohair@286 | 125 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4PortMap = null; |
ohair@286 | 126 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4PortTypeMap = null; |
ohair@286 | 127 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4BindingMap = null; |
ohair@286 | 128 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4BoundOperationMap = null; |
ohair@286 | 129 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4OperationMap = null; |
ohair@286 | 130 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4MessageMap = null; |
ohair@286 | 131 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4InputMap = null; |
ohair@286 | 132 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4OutputMap = null; |
ohair@286 | 133 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4FaultMap = null; |
ohair@286 | 134 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4BindingInputOpMap = null; |
ohair@286 | 135 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4BindingOutputOpMap = null; |
ohair@286 | 136 | private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4BindingFaultOpMap = null; |
ohair@286 | 137 | |
ohair@286 | 138 | private PolicyMapBuilder policyBuilder = new PolicyMapBuilder(); |
ohair@286 | 139 | |
ohair@286 | 140 | private boolean isPolicyProcessed(final String policyUri) { |
ohair@286 | 141 | return modelsNeeded.containsKey(policyUri); |
ohair@286 | 142 | } |
ohair@286 | 143 | |
ohair@286 | 144 | private void addNewPolicyNeeded(final String policyUri, final PolicySourceModel policyModel) { |
ohair@286 | 145 | if (!modelsNeeded.containsKey(policyUri)) { |
ohair@286 | 146 | modelsNeeded.put(policyUri, policyModel); |
ohair@286 | 147 | urisNeeded.addFirst(policyUri); |
ohair@286 | 148 | } |
ohair@286 | 149 | } |
ohair@286 | 150 | |
ohair@286 | 151 | private Map<String, PolicySourceModel> getPolicyModels() { |
ohair@286 | 152 | return modelsNeeded; |
ohair@286 | 153 | } |
ohair@286 | 154 | |
ohair@286 | 155 | private Map<String,PolicyRecord> getPolicyRecordsPassedBy() { |
ohair@286 | 156 | if (null==policyRecordsPassedBy) { |
ohair@286 | 157 | policyRecordsPassedBy = new HashMap<String,PolicyRecord>(); |
ohair@286 | 158 | } |
ohair@286 | 159 | return policyRecordsPassedBy; |
ohair@286 | 160 | } |
ohair@286 | 161 | |
ohair@286 | 162 | private Map<String,PolicySourceModel> getAnonymousPolicyModels() { |
ohair@286 | 163 | if (null==anonymousPolicyModels) { |
ohair@286 | 164 | anonymousPolicyModels = new HashMap<String,PolicySourceModel>(); |
ohair@286 | 165 | } |
ohair@286 | 166 | return anonymousPolicyModels; |
ohair@286 | 167 | } |
ohair@286 | 168 | |
ohair@286 | 169 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4ServiceMap() { |
ohair@286 | 170 | if (null==handlers4ServiceMap) { |
ohair@286 | 171 | handlers4ServiceMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 172 | } |
ohair@286 | 173 | return handlers4ServiceMap; |
ohair@286 | 174 | } |
ohair@286 | 175 | |
ohair@286 | 176 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4PortMap() { |
ohair@286 | 177 | if (null==handlers4PortMap) { |
ohair@286 | 178 | handlers4PortMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 179 | } |
ohair@286 | 180 | return handlers4PortMap; |
ohair@286 | 181 | } |
ohair@286 | 182 | |
ohair@286 | 183 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4PortTypeMap() { |
ohair@286 | 184 | if (null==handlers4PortTypeMap) { |
ohair@286 | 185 | handlers4PortTypeMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 186 | } |
ohair@286 | 187 | return handlers4PortTypeMap; |
ohair@286 | 188 | } |
ohair@286 | 189 | |
ohair@286 | 190 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4BindingMap() { |
ohair@286 | 191 | if (null==handlers4BindingMap) { |
ohair@286 | 192 | handlers4BindingMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 193 | } |
ohair@286 | 194 | return handlers4BindingMap; |
ohair@286 | 195 | } |
ohair@286 | 196 | |
ohair@286 | 197 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4OperationMap() { |
ohair@286 | 198 | if (null==handlers4OperationMap) { |
ohair@286 | 199 | handlers4OperationMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 200 | } |
ohair@286 | 201 | return handlers4OperationMap; |
ohair@286 | 202 | } |
ohair@286 | 203 | |
ohair@286 | 204 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4BoundOperationMap() { |
ohair@286 | 205 | if (null==handlers4BoundOperationMap) { |
ohair@286 | 206 | handlers4BoundOperationMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 207 | } |
ohair@286 | 208 | return handlers4BoundOperationMap; |
ohair@286 | 209 | } |
ohair@286 | 210 | |
ohair@286 | 211 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4MessageMap() { |
ohair@286 | 212 | if (null==handlers4MessageMap) { |
ohair@286 | 213 | handlers4MessageMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 214 | } |
ohair@286 | 215 | return handlers4MessageMap; |
ohair@286 | 216 | } |
ohair@286 | 217 | |
ohair@286 | 218 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4InputMap() { |
ohair@286 | 219 | if (null==handlers4InputMap) { |
ohair@286 | 220 | handlers4InputMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 221 | } |
ohair@286 | 222 | return handlers4InputMap; |
ohair@286 | 223 | } |
ohair@286 | 224 | |
ohair@286 | 225 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4OutputMap() { |
ohair@286 | 226 | if (null==handlers4OutputMap) { |
ohair@286 | 227 | handlers4OutputMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 228 | } |
ohair@286 | 229 | return handlers4OutputMap; |
ohair@286 | 230 | } |
ohair@286 | 231 | |
ohair@286 | 232 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4FaultMap() { |
ohair@286 | 233 | if (null==handlers4FaultMap) { |
ohair@286 | 234 | handlers4FaultMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 235 | } |
ohair@286 | 236 | return handlers4FaultMap; |
ohair@286 | 237 | } |
ohair@286 | 238 | |
ohair@286 | 239 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4BindingInputOpMap() { |
ohair@286 | 240 | if (null==handlers4BindingInputOpMap) { |
ohair@286 | 241 | handlers4BindingInputOpMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 242 | } |
ohair@286 | 243 | return handlers4BindingInputOpMap; |
ohair@286 | 244 | } |
ohair@286 | 245 | |
ohair@286 | 246 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4BindingOutputOpMap() { |
ohair@286 | 247 | if (null==handlers4BindingOutputOpMap) { |
ohair@286 | 248 | handlers4BindingOutputOpMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 249 | } |
ohair@286 | 250 | return handlers4BindingOutputOpMap; |
ohair@286 | 251 | } |
ohair@286 | 252 | |
ohair@286 | 253 | private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4BindingFaultOpMap() { |
ohair@286 | 254 | if (null==handlers4BindingFaultOpMap) { |
ohair@286 | 255 | handlers4BindingFaultOpMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>(); |
ohair@286 | 256 | } |
ohair@286 | 257 | return handlers4BindingFaultOpMap; |
ohair@286 | 258 | } |
ohair@286 | 259 | |
ohair@286 | 260 | private List<String> getUnresolvedUris(final boolean emptyListNeeded) { |
ohair@286 | 261 | if ((null == unresolvedUris) || emptyListNeeded) { |
ohair@286 | 262 | unresolvedUris = new LinkedList<String>(); |
ohair@286 | 263 | } |
ohair@286 | 264 | return unresolvedUris; |
ohair@286 | 265 | } |
ohair@286 | 266 | |
ohair@286 | 267 | |
ohair@286 | 268 | |
ohair@286 | 269 | private void policyRecToExpandQueue(final PolicyRecord policyRec) { |
ohair@286 | 270 | if (null==expandQueueHead) { |
ohair@286 | 271 | expandQueueHead = policyRec; |
ohair@286 | 272 | } else { |
ohair@286 | 273 | expandQueueHead = expandQueueHead.insert(policyRec); |
ohair@286 | 274 | } |
ohair@286 | 275 | } |
ohair@286 | 276 | |
ohair@286 | 277 | /** |
ohair@286 | 278 | * Creates a new instance of PolicyWSDLParserExtension |
ohair@286 | 279 | */ |
ohair@286 | 280 | public PolicyWSDLParserExtension() { |
ohair@286 | 281 | |
ohair@286 | 282 | } |
ohair@286 | 283 | |
ohair@286 | 284 | |
ohair@286 | 285 | private PolicyRecordHandler readSinglePolicy(final PolicyRecord policyRec, final boolean inner) { |
ohair@286 | 286 | PolicyRecordHandler handler = null; |
ohair@286 | 287 | String policyId = policyRec.policyModel.getPolicyId(); |
ohair@286 | 288 | if (policyId == null) { |
ohair@286 | 289 | policyId = policyRec.policyModel.getPolicyName(); |
ohair@286 | 290 | } |
ohair@286 | 291 | if (policyId != null) { // policy id defined, keep the policy |
ohair@286 | 292 | handler = new PolicyRecordHandler(HandlerType.PolicyUri, policyRec.getUri()); |
ohair@286 | 293 | getPolicyRecordsPassedBy().put(policyRec.getUri(), policyRec); |
ohair@286 | 294 | policyRecToExpandQueue(policyRec); |
ohair@286 | 295 | } else if (inner) { // no id given to the policy --> keep as an annonymous policy model |
ohair@286 | 296 | final String anonymousId = AnonymnousPolicyIdPrefix.append(anonymousPoliciesCount++).toString(); |
ohair@286 | 297 | handler = new PolicyRecordHandler(HandlerType.AnonymousPolicyId,anonymousId); |
ohair@286 | 298 | getAnonymousPolicyModels().put(anonymousId, policyRec.policyModel); |
ohair@286 | 299 | if (null != policyRec.unresolvedURIs) { |
ohair@286 | 300 | getUnresolvedUris(false).addAll(policyRec.unresolvedURIs); |
ohair@286 | 301 | } |
ohair@286 | 302 | } |
ohair@286 | 303 | return handler; |
ohair@286 | 304 | } |
ohair@286 | 305 | |
ohair@286 | 306 | |
ohair@286 | 307 | private void addHandlerToMap( |
ohair@286 | 308 | final Map<WSDLObject, Collection<PolicyRecordHandler>> map, final WSDLObject key, final PolicyRecordHandler handler) { |
ohair@286 | 309 | if (map.containsKey(key)) { |
ohair@286 | 310 | map.get(key).add(handler); |
ohair@286 | 311 | } else { |
ohair@286 | 312 | final Collection<PolicyRecordHandler> newSet = new LinkedList<PolicyRecordHandler>(); |
ohair@286 | 313 | newSet.add(handler); |
ohair@286 | 314 | map.put(key,newSet); |
ohair@286 | 315 | } |
ohair@286 | 316 | } |
ohair@286 | 317 | |
ohair@286 | 318 | private String getBaseUrl(final String policyUri) { |
ohair@286 | 319 | if (null == policyUri) { |
ohair@286 | 320 | return null; |
ohair@286 | 321 | } |
ohair@286 | 322 | // TODO: encoded urls (escaped characters) might be a problem ? |
ohair@286 | 323 | final int fragmentIdx = policyUri.indexOf('#'); |
ohair@286 | 324 | return (fragmentIdx == -1) ? policyUri : policyUri.substring(0, fragmentIdx); |
ohair@286 | 325 | } |
ohair@286 | 326 | |
ohair@286 | 327 | // adding current url even to locally referenced policies |
ohair@286 | 328 | // in order to distinguish imported policies |
ohair@286 | 329 | private void processReferenceUri( |
ohair@286 | 330 | final String policyUri, |
ohair@286 | 331 | final WSDLObject element, |
ohair@286 | 332 | final XMLStreamReader reader, |
ohair@286 | 333 | final Map<WSDLObject, Collection<PolicyRecordHandler>> map) { |
ohair@286 | 334 | |
ohair@286 | 335 | if (null == policyUri || policyUri.length() == 0) { |
ohair@286 | 336 | return; |
ohair@286 | 337 | } |
ohair@286 | 338 | if ('#' != policyUri.charAt(0)) { // external uri (already) |
ohair@286 | 339 | getUnresolvedUris(false).add(policyUri); |
ohair@286 | 340 | } |
ohair@286 | 341 | |
ohair@286 | 342 | addHandlerToMap(map, element, |
ohair@286 | 343 | new PolicyRecordHandler( |
ohair@286 | 344 | HandlerType.PolicyUri, |
ohair@286 | 345 | SafePolicyReader.relativeToAbsoluteUrl(policyUri, reader.getLocation().getSystemId()))); |
ohair@286 | 346 | } |
ohair@286 | 347 | |
ohair@286 | 348 | private boolean processSubelement( |
ohair@286 | 349 | final WSDLObject element, final XMLStreamReader reader, final Map<WSDLObject, Collection<PolicyRecordHandler>> map) { |
ohair@286 | 350 | if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.PolicyReference) { // "PolicyReference" element interests us |
ohair@286 | 351 | processReferenceUri(policyReader.readPolicyReferenceElement(reader), element, reader, map); |
ohair@286 | 352 | return true; |
ohair@286 | 353 | } else if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) { // policy could be defined here |
ohair@286 | 354 | final PolicyRecordHandler handler = |
ohair@286 | 355 | readSinglePolicy( |
ohair@286 | 356 | policyReader.readPolicyElement( |
ohair@286 | 357 | reader, |
ohair@286 | 358 | (null == reader.getLocation().getSystemId()) ? // baseUrl |
ohair@286 | 359 | "" : reader.getLocation().getSystemId()), |
ohair@286 | 360 | true); |
ohair@286 | 361 | if (null != handler) { // only policies with an Id can work for us |
ohair@286 | 362 | addHandlerToMap(map, element, handler); |
ohair@286 | 363 | } // endif null != handler |
ohair@286 | 364 | return true; // element consumed |
ohair@286 | 365 | }//end if Policy element found |
ohair@286 | 366 | return false; |
ohair@286 | 367 | } |
ohair@286 | 368 | |
ohair@286 | 369 | private void processAttributes(final WSDLObject element, final XMLStreamReader reader, final Map<WSDLObject, Collection<PolicyRecordHandler>> map) { |
ohair@286 | 370 | final String[] uriArray = getPolicyURIsFromAttr(reader); |
ohair@286 | 371 | if (null != uriArray) { |
ohair@286 | 372 | for (String policyUri : uriArray) { |
ohair@286 | 373 | processReferenceUri(policyUri, element, reader, map); |
ohair@286 | 374 | } |
ohair@286 | 375 | } |
ohair@286 | 376 | } |
ohair@286 | 377 | |
ohair@286 | 378 | @Override |
ohair@286 | 379 | public boolean portElements(final WSDLPort port, final XMLStreamReader reader) { |
ohair@286 | 380 | LOGGER.entering(); |
ohair@286 | 381 | final boolean result = processSubelement(port, reader, getHandlers4PortMap()); |
ohair@286 | 382 | LOGGER.exiting(); |
ohair@286 | 383 | return result; |
ohair@286 | 384 | } |
ohair@286 | 385 | |
ohair@286 | 386 | @Override |
ohair@286 | 387 | public void portAttributes(final WSDLPort port, final XMLStreamReader reader) { |
ohair@286 | 388 | LOGGER.entering(); |
ohair@286 | 389 | processAttributes(port, reader, getHandlers4PortMap()); |
ohair@286 | 390 | LOGGER.exiting(); |
ohair@286 | 391 | } |
ohair@286 | 392 | |
ohair@286 | 393 | @Override |
ohair@286 | 394 | public boolean serviceElements(final WSDLService service, final XMLStreamReader reader) { |
ohair@286 | 395 | LOGGER.entering(); |
ohair@286 | 396 | final boolean result = processSubelement(service, reader, getHandlers4ServiceMap()); |
ohair@286 | 397 | LOGGER.exiting(); |
ohair@286 | 398 | return result; |
ohair@286 | 399 | } |
ohair@286 | 400 | |
ohair@286 | 401 | @Override |
ohair@286 | 402 | public void serviceAttributes(final WSDLService service, final XMLStreamReader reader) { |
ohair@286 | 403 | LOGGER.entering(); |
ohair@286 | 404 | processAttributes(service, reader, getHandlers4ServiceMap()); |
ohair@286 | 405 | LOGGER.exiting(); |
ohair@286 | 406 | } |
ohair@286 | 407 | |
ohair@286 | 408 | |
ohair@286 | 409 | @Override |
ohair@286 | 410 | public boolean definitionsElements(final XMLStreamReader reader){ |
ohair@286 | 411 | LOGGER.entering(); |
ohair@286 | 412 | if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) { // Only "Policy" element interests me |
ohair@286 | 413 | readSinglePolicy( |
ohair@286 | 414 | policyReader.readPolicyElement( |
ohair@286 | 415 | reader, |
ohair@286 | 416 | (null == reader.getLocation().getSystemId()) ? // baseUrl |
ohair@286 | 417 | "" : reader.getLocation().getSystemId()), |
ohair@286 | 418 | false); |
ohair@286 | 419 | LOGGER.exiting(); |
ohair@286 | 420 | return true; |
ohair@286 | 421 | } |
ohair@286 | 422 | LOGGER.exiting(); |
ohair@286 | 423 | return false; |
ohair@286 | 424 | } |
ohair@286 | 425 | |
ohair@286 | 426 | @Override |
ohair@286 | 427 | public boolean bindingElements(final WSDLBoundPortType binding, final XMLStreamReader reader) { |
ohair@286 | 428 | LOGGER.entering(); |
ohair@286 | 429 | final boolean result = processSubelement(binding, reader, getHandlers4BindingMap()); |
ohair@286 | 430 | LOGGER.exiting(); |
ohair@286 | 431 | return result; |
ohair@286 | 432 | } |
ohair@286 | 433 | |
ohair@286 | 434 | @Override |
ohair@286 | 435 | public void bindingAttributes(final WSDLBoundPortType binding, final XMLStreamReader reader) { |
ohair@286 | 436 | LOGGER.entering(); |
ohair@286 | 437 | processAttributes(binding, reader, getHandlers4BindingMap()); |
ohair@286 | 438 | LOGGER.exiting(); |
ohair@286 | 439 | } |
ohair@286 | 440 | |
ohair@286 | 441 | @Override |
ohair@286 | 442 | public boolean portTypeElements(final WSDLPortType portType, final XMLStreamReader reader) { |
ohair@286 | 443 | LOGGER.entering(); |
ohair@286 | 444 | final boolean result = processSubelement(portType, reader, getHandlers4PortTypeMap()); |
ohair@286 | 445 | LOGGER.exiting(); |
ohair@286 | 446 | return result; |
ohair@286 | 447 | } |
ohair@286 | 448 | |
ohair@286 | 449 | @Override |
ohair@286 | 450 | public void portTypeAttributes(final WSDLPortType portType, final XMLStreamReader reader) { |
ohair@286 | 451 | LOGGER.entering(); |
ohair@286 | 452 | processAttributes(portType, reader, getHandlers4PortTypeMap()); |
ohair@286 | 453 | LOGGER.exiting(); |
ohair@286 | 454 | } |
ohair@286 | 455 | |
ohair@286 | 456 | @Override |
ohair@286 | 457 | public boolean portTypeOperationElements(final WSDLOperation operation, final XMLStreamReader reader) { |
ohair@286 | 458 | LOGGER.entering(); |
ohair@286 | 459 | final boolean result = processSubelement(operation, reader, getHandlers4OperationMap()); |
ohair@286 | 460 | LOGGER.exiting(); |
ohair@286 | 461 | return result; |
ohair@286 | 462 | } |
ohair@286 | 463 | |
ohair@286 | 464 | @Override |
ohair@286 | 465 | public void portTypeOperationAttributes(final WSDLOperation operation, final XMLStreamReader reader) { |
ohair@286 | 466 | LOGGER.entering(); |
ohair@286 | 467 | processAttributes(operation, reader, getHandlers4OperationMap()); |
ohair@286 | 468 | LOGGER.exiting(); |
ohair@286 | 469 | } |
ohair@286 | 470 | |
ohair@286 | 471 | @Override |
ohair@286 | 472 | public boolean bindingOperationElements(final WSDLBoundOperation boundOperation, final XMLStreamReader reader) { |
ohair@286 | 473 | LOGGER.entering(); |
ohair@286 | 474 | final boolean result = processSubelement(boundOperation, reader, getHandlers4BoundOperationMap()); |
ohair@286 | 475 | LOGGER.exiting(); |
ohair@286 | 476 | return result; |
ohair@286 | 477 | } |
ohair@286 | 478 | |
ohair@286 | 479 | @Override |
ohair@286 | 480 | public void bindingOperationAttributes(final WSDLBoundOperation boundOperation, final XMLStreamReader reader) { |
ohair@286 | 481 | LOGGER.entering(); |
ohair@286 | 482 | processAttributes(boundOperation, reader, getHandlers4BoundOperationMap()); |
ohair@286 | 483 | LOGGER.exiting(); |
ohair@286 | 484 | } |
ohair@286 | 485 | |
ohair@286 | 486 | @Override |
ohair@286 | 487 | public boolean messageElements(final WSDLMessage msg, final XMLStreamReader reader) { |
ohair@286 | 488 | LOGGER.entering(); |
ohair@286 | 489 | final boolean result = processSubelement(msg, reader, getHandlers4MessageMap()); |
ohair@286 | 490 | LOGGER.exiting(); |
ohair@286 | 491 | return result; |
ohair@286 | 492 | } |
ohair@286 | 493 | |
ohair@286 | 494 | @Override |
ohair@286 | 495 | public void messageAttributes(final WSDLMessage msg, final XMLStreamReader reader) { |
ohair@286 | 496 | LOGGER.entering(); |
ohair@286 | 497 | processAttributes(msg, reader, getHandlers4MessageMap()); |
ohair@286 | 498 | LOGGER.exiting(); |
ohair@286 | 499 | } |
ohair@286 | 500 | |
ohair@286 | 501 | @Override |
ohair@286 | 502 | public boolean portTypeOperationInputElements(final WSDLInput input, final XMLStreamReader reader) { |
ohair@286 | 503 | LOGGER.entering(); |
ohair@286 | 504 | final boolean result = processSubelement(input, reader, getHandlers4InputMap()); |
ohair@286 | 505 | LOGGER.exiting(); |
ohair@286 | 506 | return result; |
ohair@286 | 507 | } |
ohair@286 | 508 | |
ohair@286 | 509 | @Override |
ohair@286 | 510 | public void portTypeOperationInputAttributes(final WSDLInput input, final XMLStreamReader reader) { |
ohair@286 | 511 | LOGGER.entering(); |
ohair@286 | 512 | processAttributes(input, reader, getHandlers4InputMap()); |
ohair@286 | 513 | LOGGER.exiting(); |
ohair@286 | 514 | } |
ohair@286 | 515 | |
ohair@286 | 516 | |
ohair@286 | 517 | @Override |
ohair@286 | 518 | public boolean portTypeOperationOutputElements(final WSDLOutput output, final XMLStreamReader reader) { |
ohair@286 | 519 | LOGGER.entering(); |
ohair@286 | 520 | final boolean result = processSubelement(output, reader, getHandlers4OutputMap()); |
ohair@286 | 521 | LOGGER.exiting(); |
ohair@286 | 522 | return result; |
ohair@286 | 523 | } |
ohair@286 | 524 | |
ohair@286 | 525 | @Override |
ohair@286 | 526 | public void portTypeOperationOutputAttributes(final WSDLOutput output, final XMLStreamReader reader) { |
ohair@286 | 527 | LOGGER.entering(); |
ohair@286 | 528 | processAttributes(output, reader, getHandlers4OutputMap()); |
ohair@286 | 529 | LOGGER.exiting(); |
ohair@286 | 530 | } |
ohair@286 | 531 | |
ohair@286 | 532 | |
ohair@286 | 533 | @Override |
ohair@286 | 534 | public boolean portTypeOperationFaultElements(final WSDLFault fault, final XMLStreamReader reader) { |
ohair@286 | 535 | LOGGER.entering(); |
ohair@286 | 536 | final boolean result = processSubelement(fault, reader, getHandlers4FaultMap()); |
ohair@286 | 537 | LOGGER.exiting(); |
ohair@286 | 538 | return result; |
ohair@286 | 539 | } |
ohair@286 | 540 | |
ohair@286 | 541 | @Override |
ohair@286 | 542 | public void portTypeOperationFaultAttributes(final WSDLFault fault, final XMLStreamReader reader) { |
ohair@286 | 543 | LOGGER.entering(); |
ohair@286 | 544 | processAttributes(fault, reader, getHandlers4FaultMap()); |
ohair@286 | 545 | LOGGER.exiting(); |
ohair@286 | 546 | } |
ohair@286 | 547 | |
ohair@286 | 548 | @Override |
ohair@286 | 549 | public boolean bindingOperationInputElements(final WSDLBoundOperation operation, final XMLStreamReader reader) { |
ohair@286 | 550 | LOGGER.entering(); |
ohair@286 | 551 | final boolean result = processSubelement(operation, reader, getHandlers4BindingInputOpMap()); |
ohair@286 | 552 | LOGGER.exiting(); |
ohair@286 | 553 | return result; |
ohair@286 | 554 | } |
ohair@286 | 555 | |
ohair@286 | 556 | @Override |
ohair@286 | 557 | public void bindingOperationInputAttributes(final WSDLBoundOperation operation, final XMLStreamReader reader) { |
ohair@286 | 558 | LOGGER.entering(); |
ohair@286 | 559 | processAttributes(operation, reader, getHandlers4BindingInputOpMap()); |
ohair@286 | 560 | LOGGER.exiting(); |
ohair@286 | 561 | } |
ohair@286 | 562 | |
ohair@286 | 563 | |
ohair@286 | 564 | @Override |
ohair@286 | 565 | public boolean bindingOperationOutputElements(final WSDLBoundOperation operation, final XMLStreamReader reader) { |
ohair@286 | 566 | LOGGER.entering(); |
ohair@286 | 567 | final boolean result = processSubelement(operation, reader, getHandlers4BindingOutputOpMap()); |
ohair@286 | 568 | LOGGER.exiting(); |
ohair@286 | 569 | return result; |
ohair@286 | 570 | } |
ohair@286 | 571 | |
ohair@286 | 572 | @Override |
ohair@286 | 573 | public void bindingOperationOutputAttributes(final WSDLBoundOperation operation, final XMLStreamReader reader) { |
ohair@286 | 574 | LOGGER.entering(); |
ohair@286 | 575 | processAttributes(operation, reader, getHandlers4BindingOutputOpMap()); |
ohair@286 | 576 | LOGGER.exiting(); |
ohair@286 | 577 | } |
ohair@286 | 578 | |
ohair@286 | 579 | @Override |
ohair@286 | 580 | public boolean bindingOperationFaultElements(final WSDLBoundFault fault, final XMLStreamReader reader) { |
ohair@286 | 581 | LOGGER.entering(); |
ohair@286 | 582 | final boolean result = processSubelement(fault, reader, getHandlers4BindingFaultOpMap()); |
ohair@286 | 583 | LOGGER.exiting(result); |
ohair@286 | 584 | return result; |
ohair@286 | 585 | } |
ohair@286 | 586 | |
ohair@286 | 587 | @Override |
ohair@286 | 588 | public void bindingOperationFaultAttributes(final WSDLBoundFault fault, final XMLStreamReader reader) { |
ohair@286 | 589 | LOGGER.entering(); |
ohair@286 | 590 | processAttributes(fault, reader, getHandlers4BindingFaultOpMap()); |
ohair@286 | 591 | LOGGER.exiting(); |
ohair@286 | 592 | } |
ohair@286 | 593 | |
ohair@286 | 594 | |
ohair@286 | 595 | private PolicyMapBuilder getPolicyMapBuilder() { |
ohair@286 | 596 | if (null == policyBuilder) { |
ohair@286 | 597 | policyBuilder = new PolicyMapBuilder(); |
ohair@286 | 598 | } |
ohair@286 | 599 | return policyBuilder; |
ohair@286 | 600 | } |
ohair@286 | 601 | |
ohair@286 | 602 | private Collection<String> getPolicyURIs( |
ohair@286 | 603 | final Collection<PolicyRecordHandler> handlers, final PolicySourceModelContext modelContext) throws PolicyException{ |
ohair@286 | 604 | final Collection<String> result = new ArrayList<String>(handlers.size()); |
ohair@286 | 605 | String policyUri; |
ohair@286 | 606 | for (PolicyRecordHandler handler : handlers) { |
ohair@286 | 607 | policyUri = handler.handler; |
ohair@286 | 608 | if (HandlerType.AnonymousPolicyId == handler.type) { |
ohair@286 | 609 | final PolicySourceModel policyModel = getAnonymousPolicyModels().get(policyUri); |
ohair@286 | 610 | policyModel.expand(modelContext); |
ohair@286 | 611 | while (getPolicyModels().containsKey(policyUri)) { |
ohair@286 | 612 | policyUri = AnonymnousPolicyIdPrefix.append(anonymousPoliciesCount++).toString(); |
ohair@286 | 613 | } |
ohair@286 | 614 | getPolicyModels().put(policyUri,policyModel); |
ohair@286 | 615 | } |
ohair@286 | 616 | result.add(policyUri); |
ohair@286 | 617 | } |
ohair@286 | 618 | return result; |
ohair@286 | 619 | } |
ohair@286 | 620 | |
ohair@286 | 621 | private boolean readExternalFile(final String fileUrl) { |
ohair@286 | 622 | InputStream ios = null; |
ohair@286 | 623 | XMLStreamReader reader = null; |
ohair@286 | 624 | try { |
ohair@286 | 625 | final URL xmlURL = new URL(fileUrl); |
ohair@286 | 626 | ios = xmlURL.openStream(); |
alanb@368 | 627 | reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(ios); |
ohair@286 | 628 | while (reader.hasNext()) { |
ohair@286 | 629 | if (reader.isStartElement() && NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) { |
ohair@286 | 630 | readSinglePolicy(policyReader.readPolicyElement(reader, fileUrl), false); |
ohair@286 | 631 | } |
ohair@286 | 632 | reader.next(); |
ohair@286 | 633 | } |
ohair@286 | 634 | return true; |
ohair@286 | 635 | } catch (IOException ioe) { |
ohair@286 | 636 | return false; |
ohair@286 | 637 | } catch (XMLStreamException xmlse) { |
ohair@286 | 638 | return false; |
ohair@286 | 639 | } finally { |
ohair@286 | 640 | PolicyUtils.IO.closeResource(reader); |
ohair@286 | 641 | PolicyUtils.IO.closeResource(ios); |
ohair@286 | 642 | } |
ohair@286 | 643 | } |
ohair@286 | 644 | |
ohair@286 | 645 | @Override |
ohair@286 | 646 | public void finished(final WSDLParserExtensionContext context) { |
ohair@286 | 647 | LOGGER.entering(context); |
ohair@286 | 648 | // need to make sure proper beginning order of internal policies within unresolvedUris list |
ohair@286 | 649 | if (null != expandQueueHead) { // any policies found |
ohair@286 | 650 | final List<String> externalUris = getUnresolvedUris(false); // protect list of possible external policies |
ohair@286 | 651 | getUnresolvedUris(true); // cleaning up the list only |
ohair@286 | 652 | final LinkedList<String> baseUnresolvedUris = new LinkedList<String>(); |
ohair@286 | 653 | for (PolicyRecord currentRec = expandQueueHead ; null != currentRec ; currentRec = currentRec.next) { |
ohair@286 | 654 | baseUnresolvedUris.addFirst(currentRec.getUri()); |
ohair@286 | 655 | } |
ohair@286 | 656 | getUnresolvedUris(false).addAll(baseUnresolvedUris); |
ohair@286 | 657 | expandQueueHead = null; // cut the queue off |
ohair@286 | 658 | getUnresolvedUris(false).addAll(externalUris); |
ohair@286 | 659 | } |
ohair@286 | 660 | |
ohair@286 | 661 | while (!getUnresolvedUris(false).isEmpty()) { |
ohair@286 | 662 | final List<String> urisToBeSolvedList = getUnresolvedUris(false); |
ohair@286 | 663 | getUnresolvedUris(true); // just cleaning up the list |
ohair@286 | 664 | for (String currentUri : urisToBeSolvedList) { |
ohair@286 | 665 | if (!isPolicyProcessed(currentUri)) { |
ohair@286 | 666 | final PolicyRecord prefetchedRecord = getPolicyRecordsPassedBy().get(currentUri); |
ohair@286 | 667 | if (null == prefetchedRecord) { |
ohair@286 | 668 | if (policyReader.getUrlsRead().contains(getBaseUrl(currentUri))) { // --> unresolvable policy |
ohair@286 | 669 | LOGGER.logSevereException(new PolicyException(PolicyMessages.WSP_1014_CAN_NOT_FIND_POLICY(currentUri))); |
ohair@286 | 670 | } else { |
ohair@286 | 671 | if (readExternalFile(getBaseUrl(currentUri))) { |
ohair@286 | 672 | getUnresolvedUris(false).add(currentUri); |
ohair@286 | 673 | } |
ohair@286 | 674 | } |
ohair@286 | 675 | } else { // policy has not been yet passed by |
ohair@286 | 676 | if (null != prefetchedRecord.unresolvedURIs) { |
ohair@286 | 677 | getUnresolvedUris(false).addAll(prefetchedRecord.unresolvedURIs); |
ohair@286 | 678 | } // end-if null != prefetchedRecord.unresolvedURIs |
ohair@286 | 679 | addNewPolicyNeeded(currentUri, prefetchedRecord.policyModel); |
ohair@286 | 680 | } |
ohair@286 | 681 | } // end-if policy already processed |
ohair@286 | 682 | } // end-foreach unresolved uris |
ohair@286 | 683 | } |
ohair@286 | 684 | final PolicySourceModelContext modelContext = PolicySourceModelContext.createContext(); |
ohair@286 | 685 | for (String policyUri : urisNeeded) { |
ohair@286 | 686 | final PolicySourceModel sourceModel = modelsNeeded.get(policyUri); |
ohair@286 | 687 | try { |
ohair@286 | 688 | sourceModel.expand(modelContext); |
ohair@286 | 689 | modelContext.addModel(new URI(policyUri), sourceModel); |
ohair@286 | 690 | } catch (URISyntaxException e) { |
ohair@286 | 691 | LOGGER.logSevereException(e); |
ohair@286 | 692 | } catch (PolicyException e) { |
ohair@286 | 693 | LOGGER.logSevereException(e); |
ohair@286 | 694 | } |
ohair@286 | 695 | } |
ohair@286 | 696 | |
ohair@286 | 697 | // Start-preparation of policy map builder |
ohair@286 | 698 | // iterating over all services and binding all the policies read before |
ohair@286 | 699 | try { |
ohair@286 | 700 | // messageSet holds the handlers for all wsdl:message elements. There |
ohair@286 | 701 | // may otherwise be multiple entries for policies that are contained |
ohair@286 | 702 | // by fault messages. |
ohair@286 | 703 | HashSet<BuilderHandlerMessageScope> messageSet = new HashSet<BuilderHandlerMessageScope>(); |
ohair@286 | 704 | for (WSDLService service : context.getWSDLModel().getServices().values()) { |
ohair@286 | 705 | if (getHandlers4ServiceMap().containsKey(service)) { |
ohair@286 | 706 | getPolicyMapBuilder().registerHandler(new BuilderHandlerServiceScope( |
ohair@286 | 707 | getPolicyURIs(getHandlers4ServiceMap().get(service),modelContext) |
ohair@286 | 708 | ,getPolicyModels() |
ohair@286 | 709 | ,service |
ohair@286 | 710 | ,service.getName())); |
ohair@286 | 711 | } |
ohair@286 | 712 | // end service scope |
ohair@286 | 713 | |
ohair@286 | 714 | for (WSDLPort port : service.getPorts()) { |
ohair@286 | 715 | if (getHandlers4PortMap().containsKey(port)) { |
ohair@286 | 716 | getPolicyMapBuilder().registerHandler( |
ohair@286 | 717 | new BuilderHandlerEndpointScope( |
ohair@286 | 718 | getPolicyURIs(getHandlers4PortMap().get(port),modelContext) |
ohair@286 | 719 | ,getPolicyModels() |
ohair@286 | 720 | ,port |
ohair@286 | 721 | ,port.getOwner().getName() |
ohair@286 | 722 | ,port.getName())); |
ohair@286 | 723 | } |
ohair@286 | 724 | if ( // port.getBinding may not be null, but in case ... |
ohair@286 | 725 | null != port.getBinding()) { |
ohair@286 | 726 | if ( // handler for binding |
ohair@286 | 727 | getHandlers4BindingMap().containsKey(port.getBinding())) { |
ohair@286 | 728 | getPolicyMapBuilder() |
ohair@286 | 729 | .registerHandler( |
ohair@286 | 730 | new BuilderHandlerEndpointScope( |
ohair@286 | 731 | getPolicyURIs(getHandlers4BindingMap().get(port.getBinding()),modelContext) |
ohair@286 | 732 | ,getPolicyModels() |
ohair@286 | 733 | ,port.getBinding() |
ohair@286 | 734 | ,service.getName() |
ohair@286 | 735 | ,port.getName())); |
ohair@286 | 736 | } // endif handler for binding |
ohair@286 | 737 | if ( // handler for port type |
ohair@286 | 738 | getHandlers4PortTypeMap().containsKey(port.getBinding().getPortType())) { |
ohair@286 | 739 | getPolicyMapBuilder() |
ohair@286 | 740 | .registerHandler( |
ohair@286 | 741 | new BuilderHandlerEndpointScope( |
ohair@286 | 742 | getPolicyURIs(getHandlers4PortTypeMap().get(port.getBinding().getPortType()),modelContext) |
ohair@286 | 743 | ,getPolicyModels() |
ohair@286 | 744 | ,port.getBinding().getPortType() |
ohair@286 | 745 | ,service.getName() |
ohair@286 | 746 | ,port.getName())); |
ohair@286 | 747 | } // endif handler for port type |
ohair@286 | 748 | // end endpoint scope |
ohair@286 | 749 | |
ohair@286 | 750 | for (WSDLBoundOperation boundOperation : port.getBinding().getBindingOperations()) { |
ohair@286 | 751 | |
ohair@286 | 752 | final WSDLOperation operation = boundOperation.getOperation(); |
ohair@286 | 753 | final QName operationName = new QName(boundOperation.getBoundPortType().getName().getNamespaceURI(), boundOperation.getName().getLocalPart()); |
ohair@286 | 754 | // We store the message and portType/operation under the same namespace as the binding/operation so that we can match them up later |
ohair@286 | 755 | if ( // handler for operation scope -- by boundOperation |
ohair@286 | 756 | getHandlers4BoundOperationMap().containsKey(boundOperation)) { |
ohair@286 | 757 | getPolicyMapBuilder() |
ohair@286 | 758 | .registerHandler( |
ohair@286 | 759 | new BuilderHandlerOperationScope( |
ohair@286 | 760 | getPolicyURIs(getHandlers4BoundOperationMap().get(boundOperation),modelContext) |
ohair@286 | 761 | ,getPolicyModels() |
ohair@286 | 762 | ,boundOperation |
ohair@286 | 763 | ,service.getName() |
ohair@286 | 764 | ,port.getName() |
ohair@286 | 765 | ,operationName)); |
ohair@286 | 766 | } // endif handler for binding:operation scope |
ohair@286 | 767 | if ( // handler for operation scope -- by operation map |
ohair@286 | 768 | getHandlers4OperationMap().containsKey(operation)) { |
ohair@286 | 769 | getPolicyMapBuilder() |
ohair@286 | 770 | .registerHandler( |
ohair@286 | 771 | new BuilderHandlerOperationScope( |
ohair@286 | 772 | getPolicyURIs(getHandlers4OperationMap().get(operation),modelContext) |
ohair@286 | 773 | ,getPolicyModels() |
ohair@286 | 774 | ,operation |
ohair@286 | 775 | ,service.getName() |
ohair@286 | 776 | ,port.getName() |
ohair@286 | 777 | ,operationName)); |
ohair@286 | 778 | } // endif for portType:operation scope |
ohair@286 | 779 | // end operation scope |
ohair@286 | 780 | |
ohair@286 | 781 | final WSDLInput input = operation.getInput(); |
ohair@286 | 782 | if (null!=input) { |
ohair@286 | 783 | WSDLMessage inputMsg = input.getMessage(); |
ohair@286 | 784 | if (inputMsg != null && getHandlers4MessageMap().containsKey(inputMsg)) { |
ohair@286 | 785 | messageSet.add(new BuilderHandlerMessageScope( |
ohair@286 | 786 | getPolicyURIs( |
ohair@286 | 787 | getHandlers4MessageMap().get(inputMsg), modelContext) |
ohair@286 | 788 | ,getPolicyModels() |
ohair@286 | 789 | ,inputMsg |
ohair@286 | 790 | ,BuilderHandlerMessageScope.Scope.InputMessageScope |
ohair@286 | 791 | ,service.getName() |
ohair@286 | 792 | ,port.getName() |
ohair@286 | 793 | ,operationName |
ohair@286 | 794 | ,null) |
ohair@286 | 795 | ); |
ohair@286 | 796 | } |
ohair@286 | 797 | } |
ohair@286 | 798 | if ( // binding op input msg |
ohair@286 | 799 | getHandlers4BindingInputOpMap().containsKey(boundOperation)) { |
ohair@286 | 800 | getPolicyMapBuilder() |
ohair@286 | 801 | .registerHandler( |
ohair@286 | 802 | new BuilderHandlerMessageScope( |
ohair@286 | 803 | getPolicyURIs(getHandlers4BindingInputOpMap().get(boundOperation),modelContext) |
ohair@286 | 804 | ,getPolicyModels() |
ohair@286 | 805 | ,boundOperation |
ohair@286 | 806 | ,BuilderHandlerMessageScope.Scope.InputMessageScope |
ohair@286 | 807 | ,service.getName() |
ohair@286 | 808 | ,port.getName() |
ohair@286 | 809 | ,operationName |
ohair@286 | 810 | ,null)); |
ohair@286 | 811 | } // endif binding op input msg |
ohair@286 | 812 | if ( null != input // portType op input msg |
ohair@286 | 813 | && getHandlers4InputMap().containsKey(input)) { |
ohair@286 | 814 | getPolicyMapBuilder() |
ohair@286 | 815 | .registerHandler( |
ohair@286 | 816 | new BuilderHandlerMessageScope( |
ohair@286 | 817 | getPolicyURIs(getHandlers4InputMap().get(input),modelContext) |
ohair@286 | 818 | ,getPolicyModels() |
ohair@286 | 819 | ,input |
ohair@286 | 820 | ,BuilderHandlerMessageScope.Scope.InputMessageScope |
ohair@286 | 821 | ,service.getName() |
ohair@286 | 822 | ,port.getName() |
ohair@286 | 823 | ,operationName |
ohair@286 | 824 | ,null)); |
ohair@286 | 825 | } // endif portType op input msg |
ohair@286 | 826 | // end input message scope |
ohair@286 | 827 | |
ohair@286 | 828 | final WSDLOutput output = operation.getOutput(); |
ohair@286 | 829 | if (null!=output) { |
ohair@286 | 830 | WSDLMessage outputMsg = output.getMessage(); |
ohair@286 | 831 | if (outputMsg != null && getHandlers4MessageMap().containsKey(outputMsg)) { |
ohair@286 | 832 | messageSet.add(new BuilderHandlerMessageScope( |
ohair@286 | 833 | getPolicyURIs( |
ohair@286 | 834 | getHandlers4MessageMap().get(outputMsg),modelContext) |
ohair@286 | 835 | ,getPolicyModels() |
ohair@286 | 836 | ,outputMsg |
ohair@286 | 837 | ,BuilderHandlerMessageScope.Scope.OutputMessageScope |
ohair@286 | 838 | ,service.getName() |
ohair@286 | 839 | ,port.getName() |
ohair@286 | 840 | ,operationName |
ohair@286 | 841 | ,null) |
ohair@286 | 842 | ); |
ohair@286 | 843 | } |
ohair@286 | 844 | } |
ohair@286 | 845 | if ( // binding op output msg |
ohair@286 | 846 | getHandlers4BindingOutputOpMap().containsKey(boundOperation)) { |
ohair@286 | 847 | getPolicyMapBuilder() |
ohair@286 | 848 | .registerHandler( |
ohair@286 | 849 | new BuilderHandlerMessageScope( |
ohair@286 | 850 | getPolicyURIs(getHandlers4BindingOutputOpMap().get(boundOperation),modelContext) |
ohair@286 | 851 | ,getPolicyModels() |
ohair@286 | 852 | ,boundOperation |
ohair@286 | 853 | ,BuilderHandlerMessageScope.Scope.OutputMessageScope |
ohair@286 | 854 | ,service.getName() |
ohair@286 | 855 | ,port.getName() |
ohair@286 | 856 | ,operationName |
ohair@286 | 857 | ,null)); |
ohair@286 | 858 | } // endif binding op output msg |
ohair@286 | 859 | if ( null != output // portType op output msg |
ohair@286 | 860 | && getHandlers4OutputMap().containsKey(output)) { |
ohair@286 | 861 | getPolicyMapBuilder() |
ohair@286 | 862 | .registerHandler( |
ohair@286 | 863 | new BuilderHandlerMessageScope( |
ohair@286 | 864 | getPolicyURIs(getHandlers4OutputMap().get(output),modelContext) |
ohair@286 | 865 | ,getPolicyModels() |
ohair@286 | 866 | ,output |
ohair@286 | 867 | ,BuilderHandlerMessageScope.Scope.OutputMessageScope |
ohair@286 | 868 | ,service.getName() |
ohair@286 | 869 | ,port.getName() |
ohair@286 | 870 | ,operationName |
ohair@286 | 871 | ,null)); |
ohair@286 | 872 | } // endif portType op output msg |
ohair@286 | 873 | // end output message scope |
ohair@286 | 874 | |
ohair@286 | 875 | for (WSDLBoundFault boundFault : boundOperation.getFaults()) { |
ohair@286 | 876 | final WSDLFault fault = boundFault.getFault(); |
alanb@368 | 877 | |
alanb@368 | 878 | // this shouldn't happen ususally, |
alanb@368 | 879 | // but since this scenario tested in lagacy tests, dont' fail here |
alanb@368 | 880 | if (fault == null) { |
alanb@368 | 881 | LOGGER.warning(PolicyMessages.WSP_1021_FAULT_NOT_BOUND(boundFault.getName())); |
alanb@368 | 882 | continue; |
alanb@368 | 883 | } |
alanb@368 | 884 | |
ohair@286 | 885 | final WSDLMessage faultMessage = fault.getMessage(); |
ohair@286 | 886 | final QName faultName = new QName(boundOperation.getBoundPortType().getName().getNamespaceURI(), boundFault.getName()); |
ohair@286 | 887 | // We store the message and portType/fault under the same namespace as the binding/fault so that we can match them up later |
ohair@286 | 888 | if (faultMessage != null && getHandlers4MessageMap().containsKey(faultMessage)) { |
ohair@286 | 889 | messageSet.add( |
ohair@286 | 890 | new BuilderHandlerMessageScope( |
ohair@286 | 891 | getPolicyURIs(getHandlers4MessageMap().get(faultMessage), modelContext) |
ohair@286 | 892 | ,getPolicyModels() |
ohair@286 | 893 | ,new WSDLBoundFaultContainer(boundFault, boundOperation) |
ohair@286 | 894 | ,BuilderHandlerMessageScope.Scope.FaultMessageScope |
ohair@286 | 895 | ,service.getName() |
ohair@286 | 896 | ,port.getName() |
ohair@286 | 897 | ,operationName |
ohair@286 | 898 | ,faultName) |
ohair@286 | 899 | ); |
ohair@286 | 900 | } |
ohair@286 | 901 | if (getHandlers4FaultMap().containsKey(fault)) { |
ohair@286 | 902 | messageSet.add( |
ohair@286 | 903 | new BuilderHandlerMessageScope( |
ohair@286 | 904 | getPolicyURIs(getHandlers4FaultMap().get(fault), modelContext) |
ohair@286 | 905 | ,getPolicyModels() |
ohair@286 | 906 | ,new WSDLBoundFaultContainer(boundFault, boundOperation) |
ohair@286 | 907 | ,BuilderHandlerMessageScope.Scope.FaultMessageScope |
ohair@286 | 908 | ,service.getName() |
ohair@286 | 909 | ,port.getName() |
ohair@286 | 910 | ,operationName |
ohair@286 | 911 | ,faultName) |
ohair@286 | 912 | ); |
ohair@286 | 913 | } |
ohair@286 | 914 | if (getHandlers4BindingFaultOpMap().containsKey(boundFault)) { |
ohair@286 | 915 | messageSet.add( |
ohair@286 | 916 | new BuilderHandlerMessageScope( |
ohair@286 | 917 | getPolicyURIs(getHandlers4BindingFaultOpMap().get(boundFault), modelContext) |
ohair@286 | 918 | ,getPolicyModels() |
ohair@286 | 919 | ,new WSDLBoundFaultContainer(boundFault, boundOperation) |
ohair@286 | 920 | ,BuilderHandlerMessageScope.Scope.FaultMessageScope |
ohair@286 | 921 | ,service.getName() |
ohair@286 | 922 | ,port.getName() |
ohair@286 | 923 | ,operationName |
ohair@286 | 924 | ,faultName) |
ohair@286 | 925 | ); |
ohair@286 | 926 | } |
ohair@286 | 927 | } // end foreach binding operation fault msg |
ohair@286 | 928 | // end fault message scope |
ohair@286 | 929 | |
ohair@286 | 930 | } // end foreach boundOperation in port |
ohair@286 | 931 | } // endif port.getBinding() != null |
ohair@286 | 932 | } // end foreach port in service |
ohair@286 | 933 | } // end foreach service in wsdl |
ohair@286 | 934 | // Add handlers for wsdl:message elements |
ohair@286 | 935 | for (BuilderHandlerMessageScope scopeHandler : messageSet) { |
ohair@286 | 936 | getPolicyMapBuilder().registerHandler(scopeHandler); |
ohair@286 | 937 | } |
ohair@286 | 938 | } catch(PolicyException e) { |
ohair@286 | 939 | LOGGER.logSevereException(e); |
ohair@286 | 940 | } |
ohair@286 | 941 | // End-preparation of policy map builder |
ohair@286 | 942 | |
ohair@286 | 943 | LOGGER.exiting(); |
ohair@286 | 944 | } |
ohair@286 | 945 | |
ohair@286 | 946 | |
ohair@286 | 947 | // time to read possible config file and do alternative selection (on client side) |
ohair@286 | 948 | @Override |
ohair@286 | 949 | public void postFinished(final WSDLParserExtensionContext context) { |
ohair@286 | 950 | // finally register the PolicyMap on the WSDLModel |
ohair@286 | 951 | WSDLModel wsdlModel = context.getWSDLModel(); |
ohair@286 | 952 | PolicyMap effectiveMap; |
ohair@286 | 953 | try { |
ohair@286 | 954 | if(context.isClientSide()) |
ohair@286 | 955 | effectiveMap = context.getPolicyResolver().resolve(new PolicyResolver.ClientContext(policyBuilder.getPolicyMap(),context.getContainer())); |
ohair@286 | 956 | else |
ohair@286 | 957 | effectiveMap = context.getPolicyResolver().resolve(new PolicyResolver.ServerContext(policyBuilder.getPolicyMap(), context.getContainer(),null)); |
ohair@286 | 958 | ((WSDLModelImpl) wsdlModel).setPolicyMap(effectiveMap); |
ohair@286 | 959 | } catch (PolicyException e) { |
ohair@286 | 960 | LOGGER.logSevereException(e); |
ohair@286 | 961 | throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1007_POLICY_EXCEPTION_WHILE_FINISHING_PARSING_WSDL(), e)); |
ohair@286 | 962 | } |
ohair@286 | 963 | try { |
ohair@286 | 964 | PolicyUtil.configureModel(wsdlModel,effectiveMap); |
ohair@286 | 965 | } catch (PolicyException e) { |
ohair@286 | 966 | LOGGER.logSevereException(e); |
ohair@286 | 967 | throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1012_FAILED_CONFIGURE_WSDL_MODEL(), e)); |
ohair@286 | 968 | } |
ohair@286 | 969 | LOGGER.exiting(); |
ohair@286 | 970 | } |
ohair@286 | 971 | |
ohair@286 | 972 | |
ohair@286 | 973 | /** |
ohair@286 | 974 | * Reads policy reference URIs from PolicyURIs attribute and returns them |
ohair@286 | 975 | * as a String array returns null if there is no such attribute. This method |
ohair@286 | 976 | * will attempt to check for the attribute in every supported policy namespace. |
ohair@286 | 977 | * Resulting array of URIs is concatenation of URIs defined in all found |
ohair@286 | 978 | * PolicyURIs attribute version. |
ohair@286 | 979 | */ |
ohair@286 | 980 | private String[] getPolicyURIsFromAttr(final XMLStreamReader reader) { |
ohair@286 | 981 | final StringBuilder policyUriBuffer = new StringBuilder(); |
ohair@286 | 982 | for (NamespaceVersion version : NamespaceVersion.values()) { |
ohair@286 | 983 | final String value = reader.getAttributeValue(version.toString(), XmlToken.PolicyUris.toString()); |
ohair@286 | 984 | if (value != null) { |
ohair@286 | 985 | policyUriBuffer.append(value).append(" "); |
ohair@286 | 986 | } |
ohair@286 | 987 | } |
ohair@286 | 988 | return (policyUriBuffer.length() > 0) ? policyUriBuffer.toString().split("[\\n ]+") : null; |
ohair@286 | 989 | } |
ohair@286 | 990 | |
ohair@286 | 991 | } |