public static String[] getNSServiceNameAndMessageNameArray(
     Definition wsdlDefinition,
     String serviceName,
     String portName,
     String bindingName,
     String opName) {
   Map<?, ?> services = wsdlDefinition.getServices();
   Set<?> serviceKeys = services.keySet();
   for (Iterator<?> it = serviceKeys.iterator(); it.hasNext(); ) {
     QName serviceKey = (QName) it.next();
     if (serviceName != null && serviceKey.getLocalPart().contentEquals(serviceName)) {
       Service service = (Service) services.get(serviceKey);
       Map<?, ?> ports = service.getPorts();
       Set<?> portKeys = ports.keySet();
       for (Iterator<?> it2 = portKeys.iterator(); it2.hasNext(); ) {
         String portKey = (String) it2.next();
         if (portName != null && portKey.contentEquals(portName)) {
           Port port = (Port) ports.get(portKey);
           Binding wsdlBinding = port.getBinding();
           PortType portType = wsdlBinding.getPortType();
           String ns = portType.getQName().getNamespaceURI();
           List<?> operations = portType.getOperations();
           for (Iterator<?> it3 = operations.iterator(); it3.hasNext(); ) {
             Operation operation = (Operation) it3.next();
             if (opName != null && operation.getName().contentEquals(opName)) {
               return new String[] {ns, serviceName, portName};
             }
           }
         }
       }
     }
   }
   return null;
 }
Example #2
0
  // TODO: Should also check SoapHeader/SoapHeaderFault
  public boolean checkR2205() {
    Collection<Binding> bindings = CastUtils.cast(def.getBindings().values());
    for (Binding binding : bindings) {

      if (!SOAPBindingUtil.isSOAPBinding(binding)) {
        System.err.println(
            "WSIBP Validator found <" + binding.getQName() + "> is NOT a SOAP binding");
        continue;
      }
      if (binding.getPortType() == null) {
        // will error later
        continue;
      }

      for (Iterator<?> ite2 = binding.getPortType().getOperations().iterator(); ite2.hasNext(); ) {
        Operation operation = (Operation) ite2.next();
        Collection<Fault> faults = CastUtils.cast(operation.getFaults().values());
        if (CollectionUtils.isEmpty(faults)) {
          continue;
        }

        for (Fault fault : faults) {
          Message message = fault.getMessage();
          Collection<Part> parts = CastUtils.cast(message.getParts().values());
          for (Part part : parts) {
            if (part.getElementName() == null) {
              addErrorMessage(
                  getErrorPrefix("WSI-BP-1.0 R2205")
                      + "In Message "
                      + message.getQName()
                      + ", part "
                      + part.getName()
                      + " must specify a 'element' attribute");
              return false;
            }
          }
        }
      }
    }
    return true;
  }
Example #3
0
  private void convertPort(Port port) throws IOException {
    String comment = "";
    String name = port.getName();
    String protocol = "soap";
    String location = "socket://localhost:80/";
    if (port.getDocumentationElement() != null) {
      comment = port.getDocumentationElement().getNodeValue();
    }
    List<ExtensibilityElement> extElements = port.getExtensibilityElements();
    for (ExtensibilityElement element : extElements) {
      if (element instanceof SOAPAddress) {
        location = ((SOAPAddress) element).getLocationURI().toString();
        StringBuilder builder = new StringBuilder();
        builder
            .append("soap {\n")
            .append("\t.wsdl = \"")
            .append(definition.getDocumentBaseURI())
            .append("\";\n")
            .append("\t.wsdl.port = \"")
            .append(port.getName())
            .append("\"\n}");
        protocol = builder.toString();

      } else if (element instanceof HTTPAddress) {
        location = ((HTTPAddress) element).getLocationURI().toString();
        protocol = "http";
      }
    }
    try {
      URI uri = new URI(location);
      uri =
          new URI(
              "socket",
              uri.getUserInfo(),
              uri.getHost(),
              (uri.getPort() < 1) ? 80 : uri.getPort(),
              uri.getPath(),
              uri.getQuery(),
              uri.getFragment());
      location = uri.toString();
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
    Binding binding = port.getBinding();
    PortType portType = binding.getPortType();
    convertPortType(portType, binding);
    outputPorts.put(
        name,
        new OutputPort(name, location, protocol, portType.getQName().getLocalPart(), comment));
  }
Example #4
0
  private void collectValidationPointsForBindings() throws Exception {
    Map<QName, XNode> vBindingNodes = new HashMap<QName, XNode>();
    for (Service service : services.values()) {
      vBindingNodes.putAll(getBindings(service));
    }

    for (Map.Entry<QName, XNode> entry : vBindingNodes.entrySet()) {
      QName bName = entry.getKey();
      Binding binding = this.definition.getBinding(bName);
      if (binding == null) {
        LOG.log(
            Level.SEVERE,
            bName.toString()
                + " is not correct, please check that the correct namespace is being used");
        throw new Exception(
            bName.toString()
                + " is not correct, please check that the correct namespace is being used");
      }
      XNode vBindingNode = getXNode(binding);
      vBindingNode.setFailurePoint(entry.getValue());
      vNodes.add(vBindingNode);

      if (binding.getPortType() == null) {
        continue;
      }
      portTypeRefNames.add(binding.getPortType().getQName());

      XNode vPortTypeNode = getXNode(binding.getPortType());
      vPortTypeNode.setFailurePoint(vBindingNode);
      vNodes.add(vPortTypeNode);
      Collection<BindingOperation> bops = CastUtils.cast(binding.getBindingOperations());
      for (BindingOperation bop : bops) {
        XNode vOpNode = getOperationXNode(vPortTypeNode, bop.getName());
        XNode vBopNode = getOperationXNode(vBindingNode, bop.getName());
        vOpNode.setFailurePoint(vBopNode);
        vNodes.add(vOpNode);
        if (bop.getBindingInput() != null) {
          String inName = bop.getBindingInput().getName();
          if (!StringUtils.isEmpty(inName)) {
            XNode vInputNode = getInputXNode(vOpNode, inName);
            vInputNode.setFailurePoint(getInputXNode(vBopNode, inName));
            vNodes.add(vInputNode);
          }
        }
        if (bop.getBindingOutput() != null) {
          String outName = bop.getBindingOutput().getName();
          if (!StringUtils.isEmpty(outName)) {
            XNode vOutputNode = getOutputXNode(vOpNode, outName);
            vOutputNode.setFailurePoint(getOutputXNode(vBopNode, outName));
            vNodes.add(vOutputNode);
          }
        }
        for (Iterator<?> iter1 = bop.getBindingFaults().keySet().iterator(); iter1.hasNext(); ) {
          String faultName = (String) iter1.next();
          XNode vFaultNode = getFaultXNode(vOpNode, faultName);
          vFaultNode.setFailurePoint(getFaultXNode(vBopNode, faultName));
          vNodes.add(vFaultNode);
        }
      }
    }
  }
Example #5
0
  public boolean checkR2203And2204() {

    Collection<Binding> bindings = CastUtils.cast(def.getBindings().values());
    for (Binding binding : bindings) {

      String style = SOAPBindingUtil.getCanonicalBindingStyle(binding);

      if (binding.getPortType() == null) {
        return true;
      }

      //

      for (Iterator<?> ite2 = binding.getPortType().getOperations().iterator(); ite2.hasNext(); ) {
        Operation operation = (Operation) ite2.next();
        BindingOperation bop = wsdlHelper.getBindingOperation(def, operation.getName());
        if (operation.getInput() != null && operation.getInput().getMessage() != null) {
          Message inMess = operation.getInput().getMessage();

          for (Iterator<?> ite3 = inMess.getParts().values().iterator(); ite3.hasNext(); ) {
            Part p = (Part) ite3.next();
            if (SOAPBinding.Style.RPC.name().equalsIgnoreCase(style)
                && p.getTypeName() == null
                && !isHeaderPart(bop, p)) {
              addErrorMessage(
                  "An rpc-literal binding in a DESCRIPTION MUST refer, "
                      + "in its soapbind:body element(s), only to "
                      + "wsdl:part element(s) that have been defined "
                      + "using the type attribute.");
              return false;
            }

            if (SOAPBinding.Style.DOCUMENT.name().equalsIgnoreCase(style)
                && p.getElementName() == null) {
              addErrorMessage(
                  "A document-literal binding in a DESCRIPTION MUST refer, "
                      + "in each of its soapbind:body element(s),"
                      + "only to wsdl:part element(s)"
                      + " that have been defined using the element attribute.");
              return false;
            }
          }
        }
        if (operation.getOutput() != null && operation.getOutput().getMessage() != null) {
          Message outMess = operation.getOutput().getMessage();
          for (Iterator<?> ite3 = outMess.getParts().values().iterator(); ite3.hasNext(); ) {
            Part p = (Part) ite3.next();
            if (style.equalsIgnoreCase(SOAPBinding.Style.RPC.name())
                && p.getTypeName() == null
                && !isHeaderPart(bop, p)) {
              addErrorMessage(
                  "An rpc-literal binding in a DESCRIPTION MUST refer, "
                      + "in its soapbind:body element(s), only to "
                      + "wsdl:part element(s) that have been defined "
                      + "using the type attribute.");
              return false;
            }

            if (style.equalsIgnoreCase(SOAPBinding.Style.DOCUMENT.name())
                && p.getElementName() == null) {
              addErrorMessage(
                  "A document-literal binding in a DESCRIPTION MUST refer, "
                      + "in each of its soapbind:body element(s),"
                      + "only to wsdl:part element(s)"
                      + " that have been defined using the element attribute.");
              return false;
            }
          }
        }
      }
    }
    return true;
  }