src/share/jaxws_classes/com/sun/xml/internal/ws/policy/jaxws/PolicyWSDLParserExtension.java

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

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

mercurial