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