Example #1
0
  private void collectValidationPointsForPortTypes() {
    for (QName ptName : portTypeRefNames) {
      PortType portType = getPortType(ptName);
      if (portType == null) {
        vResults.addError(new Message("NO_PORTTYPE", LOG, ptName));
        continue;
      }

      XNode vPortTypeNode = getXNode(portType);
      for (Operation operation : getOperations(portType).values()) {
        XNode vOperationNode = getOperationXNode(vPortTypeNode, operation.getName());
        if (operation.getInput() == null) {
          vResults.addError(
              new Message("WRONG_MEP", LOG, operation.getName(), portType.getQName()));
          continue;
        }
        javax.wsdl.Message inMsg = operation.getInput().getMessage();
        if (inMsg == null) {
          addWarning(
              "Operation "
                  + operation.getName()
                  + " in PortType: "
                  + portType.getQName()
                  + " has no input message");
        } else {
          XNode vInMsgNode = getXNode(inMsg);
          vInMsgNode.setFailurePoint(getInputXNode(vOperationNode, operation.getInput().getName()));
          vNodes.add(vInMsgNode);
          messageRefNames.add(inMsg.getQName());
        }

        if (operation.getOutput() != null) {
          javax.wsdl.Message outMsg = operation.getOutput().getMessage();

          if (outMsg == null) {
            addWarning(
                "Operation "
                    + operation.getName()
                    + " in PortType: "
                    + portType.getQName()
                    + " has no output message");
          } else {
            XNode vOutMsgNode = getXNode(outMsg);
            vOutMsgNode.setFailurePoint(
                getOutputXNode(vOperationNode, operation.getOutput().getName()));
            vNodes.add(vOutMsgNode);
            messageRefNames.add(outMsg.getQName());
          }
        }
        for (Iterator<?> iter = operation.getFaults().values().iterator(); iter.hasNext(); ) {
          Fault fault = (Fault) iter.next();
          javax.wsdl.Message faultMsg = fault.getMessage();
          XNode vFaultMsgNode = getXNode(faultMsg);
          vFaultMsgNode.setFailurePoint(getFaultXNode(vOperationNode, fault.getName()));
          vNodes.add(vFaultMsgNode);
          messageRefNames.add(faultMsg.getQName());
        }
      }
    }
  }
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 joliex.wsdl.impl.Operation convertOperation(Operation operation, Style style)
      throws IOException {
    String comment = "";
    if (operation.getDocumentationElement() != null) {
      operation.getDocumentationElement().getNodeValue();
    }
    String responseTypeName = null;

    String requestTypeName =
        convertOperationMessage(operation.getInput().getMessage(), operation.getName(), style);
    if (operation.getOutput() != null) {
      responseTypeName =
          convertOperationMessage(operation.getOutput().getMessage(), operation.getName(), style);
    }

    Map<String, Part> parts;
    List<Pair<String, String>> faultList = new ArrayList<Pair<String, String>>();
    Map<String, Fault> faults = operation.getFaults();
    for (Entry<String, Fault> entry : faults.entrySet()) {
      String faultName = entry.getKey();
      String faultTypeName = null;
      parts = entry.getValue().getMessage().getParts();
      if (parts.size() > 1) {
        String typeName = faultName = faultTypeName;
        TypeInlineDefinition faultType =
            new TypeInlineDefinition(
                URIParsingContext.DEFAULT,
                typeName,
                NativeType.VOID,
                jolie.lang.Constants.RANGE_ONE_TO_ONE);
        for (Entry<String, Part> partEntry : parts.entrySet()) {
          Part part = partEntry.getValue();
          if (part.getElementName() == null) {
            if (part.getTypeName() == null) {
              throw new IOException(
                  "Could not parse message part "
                      + entry.getKey()
                      + " for operation "
                      + operation.getName()
                      + ".");
            }
            TypeDefinitionLink link =
                new TypeDefinitionLink(
                    URIParsingContext.DEFAULT,
                    part.getName(),
                    jolie.lang.Constants.RANGE_ONE_TO_ONE,
                    XsdUtils.xsdToNativeType(part.getTypeName().getLocalPart()).id());
            faultType.putSubType(link);
          } else {
            TypeDefinitionLink link =
                new TypeDefinitionLink(
                    URIParsingContext.DEFAULT,
                    part.getName(),
                    jolie.lang.Constants.RANGE_ONE_TO_ONE,
                    part.getElementName().getLocalPart());
            faultType.putSubType(link);
          }
        }
        typeDefinitions.add(faultType);
      } else {
        for (Entry<String, Part> e : parts.entrySet()) {
          Part part = e.getValue();
          if (part.getElementName() == null) {
            if (part.getTypeName() == null) {
              throw new IOException(
                  "Could not parse message part "
                      + e.getKey()
                      + " for operation "
                      + operation.getName()
                      + ", fault "
                      + entry.getKey()
                      + ".");
            }
            faultTypeName = XsdUtils.xsdToNativeType(part.getTypeName().getLocalPart()).id();
          } else {
            faultTypeName = part.getElementName().getLocalPart();
            NativeType nativeType = XsdUtils.xsdToNativeType(faultTypeName);
            if (nativeType != null) {
              faultTypeName = nativeType.id();
            }
          }
        }
      }
      faultList.add(new Pair<String, String>(faultName, faultTypeName));
    }

    return new joliex.wsdl.impl.Operation(
        operation.getName(), requestTypeName, responseTypeName, faultList, comment);
  }
  protected void addPortTypeTransformers(
      PortType portType,
      boolean provider,
      StringBuffer transformers,
      javax.wsdl.Definition wsdl,
      ResourceLocator locator,
      String srcFolder) {
    String attr1 = (provider ? "from" : "to");
    String attr2 = (provider ? "to" : "from");

    for (Object opobj : portType.getOperations()) {
      if (opobj instanceof javax.wsdl.Operation) {
        javax.wsdl.Operation op = (javax.wsdl.Operation) opobj;

        String qname = "";
        String javaType = "";
        String javaPackage = "";

        javax.wsdl.Part p =
            (javax.wsdl.Part) op.getInput().getMessage().getParts().values().iterator().next();
        qname = p.getElementName().toString();

        javaType = getJavaType(wsdl, p.getElementName(), locator);

        if (javaType != null) {
          int ind = javaType.lastIndexOf('.');
          if (ind != -1) {
            javaPackage = javaType.substring(0, ind);
          }
        }

        transformers.append("\t\t<xform:transform.jaxb\r\n");
        transformers.append("\t\t\t" + attr1 + "=\"" + qname + "\"\r\n");
        transformers.append("\t\t\t" + attr2 + "=\"java:" + javaType + "\"\r\n");
        transformers.append("\t\t\tcontextPath=\"" + javaPackage + "\"/>\r\n");

        if (op.getOutput() != null) {
          p = (javax.wsdl.Part) op.getOutput().getMessage().getParts().values().iterator().next();
          qname = p.getElementName().toString();

          javaType = getJavaType(wsdl, p.getElementName(), locator);

          if (javaType != null) {
            int ind = javaType.lastIndexOf('.');
            if (ind != -1) {
              javaPackage = javaType.substring(0, ind);
            }
          }

          transformers.append("\t\t<xform:transform.jaxb\r\n");
          transformers.append("\t\t\t" + attr2 + "=\"" + qname + "\"\r\n");
          transformers.append("\t\t\t" + attr1 + "=\"java:" + javaType + "\"\r\n");
          transformers.append("\t\t\tcontextPath=\"" + javaPackage + "\"/>\r\n");
        }

        for (Object faultObj : op.getFaults().values()) {
          if (faultObj instanceof javax.wsdl.Fault) {
            javax.wsdl.Fault fault = (javax.wsdl.Fault) faultObj;

            p = (javax.wsdl.Part) fault.getMessage().getParts().values().iterator().next();
            qname = p.getElementName().toString();

            String javaFaultType = getJavaType(wsdl, p.getElementName(), locator);

            String pack =
                JavaGeneratorUtil.getJavaPackage(fault.getMessage().getQName().getNamespaceURI());

            javaType =
                pack
                    + "."
                    + JavaGeneratorUtil.getJavaClassName(
                        fault.getMessage().getQName().getLocalPart());

            String transformerClassName = getFaultTransformerClassName(javaType, provider);

            String faultTransClass = pack + "." + transformerClassName;

            transformers.append("\t\t<xform:transform.java class=\"" + faultTransClass + "\"\r\n");
            transformers.append("\t\t\t" + attr2 + "=\"" + qname + "\"\r\n");
            transformers.append("\t\t\t" + attr1 + "=\"java:" + javaType + "\"/>\r\n");

            // Create transformer class
            String folder = pack.replace('.', java.io.File.separatorChar);

            String javaFile = folder + java.io.File.separator + transformerClassName;

            java.io.File jFile =
                new java.io.File(srcFolder + java.io.File.separator + javaFile + ".java");

            jFile.getParentFile().mkdirs();

            try {
              java.io.FileOutputStream fos = new java.io.FileOutputStream(jFile);

              generateFaultTransformer(qname, javaType, javaFaultType, provider, fos);

              fos.close();
            } catch (Exception e) {
              logger.log(Level.SEVERE, "Failed to create fault transformer", e);
            }
          }
        }
      }
    }
  }