1 package org.netbeans.modules.xml.wsdl.model.extensions.soap.validation; 2 3 import java.net.URI ; 4 import java.net.URL ; 5 import java.util.Collection ; 6 import java.util.Collections ; 7 import java.util.HashSet ; 8 import java.util.Iterator ; 9 import java.util.List ; 10 import org.netbeans.modules.xml.wsdl.model.Binding; 11 import org.netbeans.modules.xml.wsdl.model.BindingInput; 12 import org.netbeans.modules.xml.wsdl.model.BindingFault; 13 import org.netbeans.modules.xml.wsdl.model.BindingOperation; 14 import org.netbeans.modules.xml.wsdl.model.BindingOutput; 15 import org.netbeans.modules.xml.wsdl.model.Definitions; 16 import org.netbeans.modules.xml.wsdl.model.Input; 17 import org.netbeans.modules.xml.wsdl.model.Output; 18 import org.netbeans.modules.xml.wsdl.model.Port; 19 import org.netbeans.modules.xml.wsdl.model.Service; 20 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 21 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 22 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPAddress; 23 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBinding; 24 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBody; 25 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPComponent; 26 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPFault; 27 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPHeader; 28 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPHeaderFault; 29 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPMessageBase; 30 import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPOperation; 31 import org.netbeans.modules.xml.xam.Component; 32 import org.netbeans.modules.xml.xam.Model; 33 import org.netbeans.modules.xml.xam.Model.State; 34 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 35 import org.netbeans.modules.xml.wsdl.model.Message; 36 import org.netbeans.modules.xml.xam.spi.Validation; 37 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType; 38 import org.netbeans.modules.xml.xam.spi.ValidationResult; 39 import org.netbeans.modules.xml.xam.spi.Validator; 40 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem; 41 import org.openide.util.NbBundle; 42 43 44 48 public class SOAPComponentValidator 49 implements Validator, SOAPComponent.Visitor { 50 51 private static final String HTTP_DEFAULT_PORT_TOKEN = "${HttpDefaultPort}"; 52 private static final String HTTPS_DEFAULT_PORT_TOKEN = "${HttpsDefaultPort}"; 53 54 private Validation mValidation; 55 private ValidationType mValidationType; 56 private ValidationResult mValidationResult; 57 58 @SuppressWarnings ("unchecked") 59 public static final ValidationResult EMPTY_RESULT = 60 new ValidationResult( Collections.EMPTY_SET, 61 Collections.EMPTY_SET); 62 63 64 public SOAPComponentValidator() {} 65 66 72 75 public String getName() { 76 return getClass().getName(); 77 } 78 79 87 public ValidationResult validate(Model model, Validation validation, 88 ValidationType validationType) { 89 mValidation = validation; 91 92 mValidationType = validationType; 94 95 HashSet <ResultItem> results = new HashSet <ResultItem>(); 97 HashSet <Model> models = new HashSet <Model>(); 98 models.add(model); 99 mValidationResult = new ValidationResult(results, models); 100 101 if (model instanceof WSDLModel) { 103 WSDLModel wsdlModel = (WSDLModel)model; 104 105 if (model.getState() == State.NOT_WELL_FORMED) { 106 return EMPTY_RESULT; 107 } 108 Definitions defs = wsdlModel.getDefinitions(); 109 Iterator <Binding> bindings = defs.getBindings().iterator(); 110 while (bindings.hasNext()) { 111 Binding binding = bindings.next(); 112 int numSoapBindings = binding.getExtensibilityElements(SOAPBinding.class).size(); 113 if (numSoapBindings > 0 && numSoapBindings != 1) { 114 results.add( 115 new Validator.ResultItem(this, 116 Validator.ResultType.ERROR, 117 binding, 118 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPBindingValidator.Only_one_binding_allowed"))); 119 } 120 Iterator <SOAPBinding> soapBindings = 121 binding.getExtensibilityElements(SOAPBinding.class).iterator(); 122 while (soapBindings.hasNext()) { 123 soapBindings.next().accept(this); 124 } 125 Iterator <BindingOperation> bindingOps = 126 binding.getBindingOperations().iterator(); 127 while (bindingOps.hasNext()) { 128 BindingOperation bindingOp = bindingOps.next(); 129 List soapOpsList = bindingOp.getExtensibilityElements(SOAPOperation.class); 130 Iterator <SOAPOperation> soapOps = 131 soapOpsList.iterator(); 132 while (soapOps.hasNext()) { 133 soapOps.next().accept(this); 134 } 135 136 if(soapOpsList.size() > 0) { 137 BindingInput bindingInput = bindingOp.getBindingInput(); 138 if (bindingInput != null) { 139 Iterator <SOAPHeader> soapHeaders= 140 bindingInput.getExtensibilityElements(SOAPHeader.class).iterator(); 141 while (soapHeaders.hasNext()) { 142 SOAPHeader soapHeader = soapHeaders.next(); 143 soapHeader.accept(this); 144 Iterator <SOAPHeaderFault> soapHeaderFaults = 145 soapHeader.getSOAPHeaderFaults().iterator(); 146 while(soapHeaderFaults.hasNext()) { 147 soapHeaderFaults.next().accept(this); 148 } 149 } 150 151 int numSoapBodies = bindingInput.getExtensibilityElements(SOAPBody.class).size(); 152 if(numSoapBodies == 0) { 153 results.add( 154 new Validator.ResultItem(this, 155 Validator.ResultType.ERROR, 156 bindingInput, 157 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPBodyValidator.Atleast_one_body_Required"))); 158 159 } else if (numSoapBodies > 0 && numSoapBodies != 1) { 160 results.add( 161 new Validator.ResultItem(this, 162 Validator.ResultType.ERROR, 163 bindingInput, 164 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPBodyValidator.Only_one_body_allowed"))); 165 } 166 Iterator <SOAPBody> soapBodies = 167 bindingInput.getExtensibilityElements(SOAPBody.class).iterator(); 168 while(soapBodies.hasNext()) { 169 soapBodies.next().accept(this); 170 } 171 } 172 173 BindingOutput bindingOutput = bindingOp.getBindingOutput(); 174 if (bindingOutput != null) { 175 Iterator <SOAPHeader> soapHeaders= 176 bindingOutput.getExtensibilityElements(SOAPHeader.class).iterator(); 177 while (soapHeaders.hasNext()) { 178 SOAPHeader soapHeader = soapHeaders.next(); 179 soapHeader.accept(this); 180 Iterator <SOAPHeaderFault> soapHeaderFaults = 181 soapHeader.getSOAPHeaderFaults().iterator(); 182 while(soapHeaderFaults.hasNext()) { 183 soapHeaderFaults.next().accept(this); 184 } 185 } 186 187 int numSoapBodies = bindingOutput.getExtensibilityElements(SOAPBody.class).size(); 188 if(numSoapBodies == 0) { 189 results.add( 190 new Validator.ResultItem(this, 191 Validator.ResultType.ERROR, 192 bindingOutput, 193 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPBodyValidator.Atleast_one_body_Required"))); 194 195 } else if (numSoapBodies > 0 && numSoapBodies != 1) { 196 197 results.add( 198 new Validator.ResultItem(this, 199 Validator.ResultType.ERROR, 200 bindingOutput, 201 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPBodyValidator.Only_one_body_allowed"))); 202 } 203 Iterator <SOAPBody> soapBodies = 204 bindingOutput.getExtensibilityElements(SOAPBody.class).iterator(); 205 while(soapBodies.hasNext()) { 206 soapBodies.next().accept(this); 207 } 208 } 209 210 Iterator <BindingFault> bindingFaults = 211 bindingOp.getBindingFaults().iterator(); 212 while (bindingFaults.hasNext()) { 213 BindingFault bindingFault = bindingFaults.next(); 214 int numSoapFaults = bindingFault.getExtensibilityElements(SOAPFault.class).size(); 215 if (numSoapFaults > 0 && numSoapFaults != 1) { 216 217 results.add( 218 new Validator.ResultItem(this, 219 Validator.ResultType.ERROR, 220 bindingFault, 221 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPFaultValidator.Only_one_fault_allowed"))); 222 } 223 Iterator <SOAPFault> soapFaults = 224 bindingFault.getExtensibilityElements(SOAPFault.class).iterator(); 225 while(soapFaults.hasNext()) { 226 soapFaults.next().accept(this); 227 } 228 } 229 } 230 } 231 } 232 Iterator <Service> services = defs.getServices().iterator(); 233 while (services.hasNext()) { 234 Iterator <Port> ports = services.next().getPorts().iterator(); 235 while (ports.hasNext()) { 236 Port port = ports.next(); 237 if(port.getBinding() != null) { 238 Binding binding = port.getBinding().get(); 239 if(binding != null) { 240 int numRelatedSoapBindings = binding.getExtensibilityElements(SOAPBinding.class).size(); 241 Iterator <SOAPAddress> soapAddresses = port.getExtensibilityElements(SOAPAddress.class).iterator(); 242 if((numRelatedSoapBindings > 0) && (!soapAddresses.hasNext())){ 243 results.add( 244 new Validator.ResultItem(this, 245 Validator.ResultType.ERROR, 246 port, 247 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPAddressValidator.Missing_SoapAddress"))); 248 } 249 250 if(port.getExtensibilityElements(SOAPAddress.class).size() > 1){ 251 results.add( 252 new Validator.ResultItem(this, 253 Validator.ResultType.ERROR, 254 port, 255 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPAddressValidator.Only_one_SoapAddress_allowed"))); 256 } 257 while (soapAddresses.hasNext()) { 258 soapAddresses.next().accept(this); 259 } 260 } 261 } 262 } 263 } 264 } 265 266 mValidation = null; 268 mValidationType = null; 269 ValidationResult rv = mValidationResult; 270 mValidationResult = null; 271 272 return rv; 273 } 274 275 281 public void visit(SOAPHeader header) { 282 Collection <ResultItem> results = 283 mValidationResult.getValidationResult(); 284 285 286 NamedComponentReference<Message> message = header.getMessage(); 287 if (message == null) { 288 results.add( 289 new Validator.ResultItem(this, 290 Validator.ResultType.ERROR, 291 header, 292 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPHeaderValidator.Missing_message"))); 293 } 294 295 String part = header.getPart(); 296 if (part == null) { 297 results.add( 298 new Validator.ResultItem(this, 299 Validator.ResultType.ERROR, 300 header, 301 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPHeaderValidator.Missing_part"))); 302 } 303 304 try { 305 SOAPMessageBase.Use use = header.getUse(); 306 if (use == null) { 307 results.add( 308 new Validator.ResultItem(this, 309 Validator.ResultType.ERROR, 310 header, 311 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPHeaderValidator.Missing_use"))); 312 } 313 } catch (Throwable th) { 314 results.add( 315 new Validator.ResultItem(this, 316 Validator.ResultType.ERROR, 317 header, 318 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPHeaderValidator.Unsupported_header_use_attribute"))); 319 } 320 321 Collection <String > encodingStyles = header.getEncodingStyles(); 322 if (encodingStyles != null) { 323 } 325 326 String namespace = header.getNamespace(); 327 if (namespace != null) { 328 331 } 332 } 333 334 public void visit(SOAPAddress address) { 335 Collection <ResultItem> results = 336 mValidationResult.getValidationResult(); 337 338 String location = address.getLocation(); 339 if (location == null) { 340 results.add( 341 new Validator.ResultItem(this, 342 Validator.ResultType.ERROR, 343 address, 344 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPAddressValidator.Missing_location"))); 345 return; 346 } 347 348 if("REPLACE_WITH_ACTUAL_URL".equals(location)) { 353 return; 354 } 355 356 361 if (location.indexOf(HTTP_DEFAULT_PORT_TOKEN, 6) > 0) { 362 int colonIndex = -1; 363 int contextStartIndex = -1; 364 365 if (location.startsWith("http")) { 366 colonIndex = location.indexOf(":", 6); 368 contextStartIndex = location.indexOf("/", 7); 369 370 if (HTTP_DEFAULT_PORT_TOKEN.equals(location.substring(colonIndex + 1, contextStartIndex))) { 371 return; 372 } else { 373 results.add( 374 new Validator.ResultItem(this, 375 Validator.ResultType.ERROR, 376 address, 377 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPAddressValidator.Unsupported_location_attribute"))); 378 return; 379 } 380 } 381 } 382 383 if (location.indexOf(HTTPS_DEFAULT_PORT_TOKEN, 7) > 0) { 384 int colonIndex = -1; 385 int contextStartIndex = -1; 386 387 if (location.startsWith("https")) { 388 colonIndex = location.indexOf(":", 7); 390 contextStartIndex = location.indexOf("/", 8); 391 392 if (HTTPS_DEFAULT_PORT_TOKEN.equals(location.substring(colonIndex + 1, contextStartIndex))) { 393 return; 394 } else { 395 results.add( 396 new Validator.ResultItem(this, 397 Validator.ResultType.ERROR, 398 address, 399 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPAddressValidator.Unsupported_location_attribute"))); 400 return; 401 } 402 } 403 } 404 405 try { 406 URI uri = new URI (location); 407 String scheme = uri.getScheme(); 408 if (!scheme.equalsIgnoreCase("http") && 409 !scheme.equalsIgnoreCase("https")) { 410 return; 411 } 412 URL url = uri.toURL(); 413 } catch (Exception ex) { 414 results.add( 415 new Validator.ResultItem(this, 416 Validator.ResultType.ERROR, 417 address, 418 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPAddressValidator.Unsupported_location_attribute"))); 419 } 420 } 421 422 public void visit(SOAPBinding binding) { 423 Collection <ResultItem> results = 424 mValidationResult.getValidationResult(); 425 426 String transportURI = binding.getTransportURI(); 427 if (transportURI == null) { 428 results.add( 429 new Validator.ResultItem(this, 430 Validator.ResultType.ERROR, 431 binding, 432 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPBindingValidator.Transport_URI_required"))); 433 } else if (!transportURI.equals("http://schemas.xmlsoap.org/soap/http")) { 434 results.add( 435 new Validator.ResultItem(this, 436 Validator.ResultType.ERROR, 437 binding, 438 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPBindingValidator.Unsupported_transport"))); 439 } 440 441 try { 442 SOAPBinding.Style style = binding.getStyle(); 443 } catch (Throwable th) { 444 results.add( 445 new Validator.ResultItem(this, 446 Validator.ResultType.ERROR, 447 binding, 448 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPBindingValidator.Unsupported_style_attribute"))); 449 } 450 } 451 452 public void visit(SOAPBody body) { 453 Collection <ResultItem> results = 454 mValidationResult.getValidationResult(); 455 456 457 Collection <String > encodingStyles = body.getEncodingStyles(); 458 if (encodingStyles != null) { 459 } 461 462 String namespace = body.getNamespace(); 463 if (namespace != null) { 464 } 467 468 try { 469 SOAPMessageBase.Use use = body.getUse(); 470 } catch (Throwable th) { 471 results.add( 472 new Validator.ResultItem(this, 473 Validator.ResultType.ERROR, 474 body, 475 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPBodyValidator.Unsupported_use_attribute"))); 476 } 477 478 List <String > parts = body.getParts(); 479 if (parts != null) { 480 } 482 483 515 } 516 517 public void visit(SOAPFault fault) { 518 Collection <ResultItem> results = 519 mValidationResult.getValidationResult(); 520 521 String name = fault.getName(); 522 if (name == null) { 523 results.add( 524 new Validator.ResultItem(this, 525 Validator.ResultType.ERROR, 526 fault, 527 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPFaultValidator.Missing_name"))); 528 } 529 530 Collection <String > encodingStyles = fault.getEncodingStyles(); 531 if (encodingStyles != null) { 532 } 534 535 String namespace = fault.getNamespace(); 536 if (namespace != null) { 537 } 540 541 try { 542 SOAPMessageBase.Use use = fault.getUse(); 543 } catch (Throwable th) { 544 results.add( 545 new Validator.ResultItem(this, 546 Validator.ResultType.ERROR, 547 fault, 548 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPFaultValidator.Unsupported_use_attribute"))); 549 } 550 } 551 552 public void visit(SOAPHeaderFault headerFault) { 553 Collection <ResultItem> results = 554 mValidationResult.getValidationResult(); 555 556 NamedComponentReference<Message> message = headerFault.getMessage(); 557 if (message == null) { 558 results.add( 559 new Validator.ResultItem(this, 560 Validator.ResultType.ERROR, 561 headerFault, 562 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPHeaderFaultValidator.Missing_header_fault_message"))); 563 } 564 565 String part = headerFault.getPart(); 566 if (part == null) { 567 results.add( 568 new Validator.ResultItem(this, 569 Validator.ResultType.ERROR, 570 headerFault, 571 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPHeaderFaultValidator.Missing_header_fault_part"))); 572 } 573 574 try { 575 SOAPMessageBase.Use use = headerFault.getUse(); 576 if (use == null) { 577 results.add( 578 new Validator.ResultItem(this, 579 Validator.ResultType.ERROR, 580 headerFault, 581 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPHeaderFaultValidator.Missing_header_fault_use"))); 582 } 583 } catch (Throwable th) { 584 results.add( 585 new Validator.ResultItem(this, 586 Validator.ResultType.ERROR, 587 headerFault, 588 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPHeaderFaultValidator.Unsupported_header_fault_use_attribute"))); 589 } 590 591 592 Collection <String > encodingStyles = headerFault.getEncodingStyles(); 593 if (encodingStyles != null) { 594 } 596 597 String namespace = headerFault.getNamespace(); 598 if (namespace != null) { 599 } 602 603 } 604 605 public void visit(SOAPOperation operation) { 606 Collection <ResultItem> results = 607 mValidationResult.getValidationResult(); 608 609 String soapActionURI = operation.getSoapAction(); 610 if (soapActionURI != null) { 611 } 615 616 try { 617 SOAPBinding.Style style = operation.getStyle(); 618 } catch (Throwable th) { 619 results.add( 620 new Validator.ResultItem(this, 621 Validator.ResultType.ERROR, 622 operation, 623 NbBundle.getMessage(SOAPComponentValidator.class, "SOAPOperationValidator.Unsupported_style_attribute"))); 624 } 625 } 626 } 627 | Popular Tags |