Пример #1
1
  /**
   * Identifies WSDL documents from the {@link DOMForest}. Also identifies the root wsdl document.
   */
  private void identifyRootWsdls() {
    for (String location : rootDocuments) {
      Document doc = get(location);
      if (doc != null) {
        Element definition = doc.getDocumentElement();
        if (definition == null
            || definition.getLocalName() == null
            || definition.getNamespaceURI() == null) continue;
        if (definition.getNamespaceURI().equals(WSDLConstants.NS_WSDL)
            && definition.getLocalName().equals("definitions")) {
          rootWsdls.add(location);
          // set the root wsdl at this point. Root wsdl is one which has wsdl:service in it
          NodeList nl = definition.getElementsByTagNameNS(WSDLConstants.NS_WSDL, "service");

          // TODO:what if there are more than one wsdl with wsdl:service element. Probably such
          // cases
          // are rare and we will take any one of them, this logic should still work
          if (nl.getLength() > 0) rootWSDL = location;
        }
      }
    }
    // no wsdl with wsdl:service found, throw error
    if (rootWSDL == null) {
      StringBuilder strbuf = new StringBuilder();
      for (String str : rootWsdls) {
        strbuf.append(str);
        strbuf.append('\n');
      }
      errorReceiver.error(null, WsdlMessages.FAILED_NOSERVICE(strbuf.toString()));
    }
  }
Пример #2
0
  private Node evaluateXPathNode(
      Node bindings, Node target, String expression, NamespaceContext namespaceContext) {
    NodeList nlst;
    try {
      xpath.setNamespaceContext(namespaceContext);
      nlst = (NodeList) xpath.evaluate(expression, target, XPathConstants.NODESET);
    } catch (XPathExpressionException e) {
      reportError(
          (Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATION_ERROR(e.getMessage()), e);
      return null; // abort processing this <jaxb:bindings>
    }

    if (nlst.getLength() == 0) {
      reportError(
          (Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATES_TO_NO_TARGET(expression));
      return null; // abort
    }

    if (nlst.getLength() != 1) {
      reportError(
          (Element) bindings,
          WsdlMessages.INTERNALIZER_X_PATH_EVAULATES_TO_TOO_MANY_TARGETS(
              expression, nlst.getLength()));
      return null; // abort
    }

    Node rnode = nlst.item(0);
    if (!(rnode instanceof Element)) {
      reportError(
          (Element) bindings,
          WsdlMessages.INTERNALIZER_X_PATH_EVALUATES_TO_NON_ELEMENT(expression));
      return null; // abort
    }
    return rnode;
  }
Пример #3
0
  @SuppressWarnings("element-type-mismatch")
  public void parseWSDL() {
    // parse source grammars
    for (InputSource value : options.getWSDLs()) {
      String systemID = value.getSystemId();
      errorReceiver.pollAbort();

      Document dom;
      Element doc;

      try {
        // if there is entity resolver use it
        if (options.entityResolver != null) {
          value = options.entityResolver.resolveEntity(null, systemID);
        }
        if (value == null) {
          value = new InputSource(systemID);
        }
        dom = parse(value, true);

        doc = dom.getDocumentElement();
        if (doc == null) {
          continue;
        }
        // if its not a WSDL document, retry with MEX
        if (doc.getNamespaceURI() == null
            || !doc.getNamespaceURI().equals(WSDLConstants.NS_WSDL)
            || !doc.getLocalName().equals("definitions")) {
          throw new SAXParseException(
              WsdlMessages.INVALID_WSDL(
                  systemID,
                  com.sun.xml.internal.ws.wsdl.parser.WSDLConstants.QNAME_DEFINITIONS,
                  doc.getNodeName(),
                  locatorTable.getStartLocation(doc).getLineNumber()),
              locatorTable.getStartLocation(doc));
        }
      } catch (FileNotFoundException e) {
        errorReceiver.error(WsdlMessages.FILE_NOT_FOUND(systemID), e);
        return;
      } catch (IOException e) {
        doc = getFromMetadataResolver(systemID, e);
      } catch (SAXParseException e) {
        doc = getFromMetadataResolver(systemID, e);
      } catch (SAXException e) {
        doc = getFromMetadataResolver(systemID, e);
      }

      if (doc == null) {
        continue;
      }

      NodeList schemas = doc.getElementsByTagNameNS(SchemaConstants.NS_XSD, "schema");
      for (int i = 0; i < schemas.getLength(); i++) {
        if (!inlinedSchemaElements.contains(schemas.item(i))) {
          inlinedSchemaElements.add((Element) schemas.item(i));
        }
      }
    }
    identifyRootWsdls();
  }
Пример #4
0
  /*
   * If source and target namespace are also passed in,
   * then if the mex resolver is found and it cannot get
   * the data, wsimport attempts to add ?wsdl to the
   * address and retrieve the data with a normal http get.
   * This behavior should only happen when trying a
   * mex request first.
   */
  private @Nullable Element getFromMetadataResolver(String systemId, Exception ex) {
    // try MEX
    MetaDataResolver resolver;
    ServiceDescriptor serviceDescriptor = null;
    for (MetadataResolverFactory resolverFactory :
        ServiceFinder.find(MetadataResolverFactory.class)) {
      resolver = resolverFactory.metadataResolver(options.entityResolver);
      try {
        serviceDescriptor = resolver.resolve(new URI(systemId));
        // we got the ServiceDescriptor, now break
        if (serviceDescriptor != null) break;
      } catch (URISyntaxException e) {
        throw new ParseException(e);
      }
    }

    if (serviceDescriptor != null) {
      errorReceiver.warning(
          new SAXParseException(WsdlMessages.TRY_WITH_MEX(ex.getMessage()), null, ex));
      return parseMetadata(systemId, serviceDescriptor);
    } else {
      errorReceiver.error(
          null,
          WsdlMessages.PARSING_UNABLE_TO_GET_METADATA(
              ex.getMessage(), WscompileMessages.WSIMPORT_NO_WSDL(systemId)),
          ex);
    }
    return null;
  }
Пример #5
0
 private boolean isGlobalBinding(Node bindings) {
   if (bindings.getNamespaceURI() == null) {
     errorReceiver.warning(
         forest.locatorTable.getStartLocation((Element) bindings),
         WsdlMessages.INVALID_CUSTOMIZATION_NAMESPACE(bindings.getLocalName()));
     return false;
   }
   return (bindings.getNamespaceURI().equals(JAXWSBindingsConstants.NS_JAXWS_BINDINGS)
       && (bindings.getLocalName().equals("package")
           || bindings.getLocalName().equals("enableAsyncMapping")
           || bindings.getLocalName().equals("enableAdditionalSOAPHeaderMapping")
           || bindings.getLocalName().equals("enableWrapperStyle")
           || bindings.getLocalName().equals("enableMIMEContent")));
 }
Пример #6
0
  /**
   * Determines the target node of the "bindings" element by using the inherited target node, then
   * put the result into the "result" map.
   */
  private void buildTargetNodeMap(
      Element bindings, Node inheritedTarget, Map<Element, Node> result) {
    // start by the inherited target
    Node target = inheritedTarget;

    validate(bindings); // validate this node

    // look for @wsdlLocation
    if (isTopLevelBinding(bindings)) {
      String wsdlLocation;
      if (bindings.getAttributeNode("wsdlLocation") != null) {
        wsdlLocation = bindings.getAttribute("wsdlLocation");

        try {
          // absolutize this URI.
          // TODO: use the URI class
          // TODO: honor xml:base
          wsdlLocation =
              new URL(new URL(forest.getSystemId(bindings.getOwnerDocument())), wsdlLocation)
                  .toExternalForm();
        } catch (MalformedURLException e) {
          wsdlLocation = JAXWSUtils.absolutize(JAXWSUtils.getFileOrURLName(wsdlLocation));
        }
      } else {
        // the node does not have
        wsdlLocation = forest.getFirstRootDocument();
      }
      target = forest.get(wsdlLocation);

      if (target == null) {
        reportError(
            bindings,
            WsdlMessages.INTERNALIZER_INCORRECT_SCHEMA_REFERENCE(
                wsdlLocation, EditDistance.findNearest(wsdlLocation, forest.listSystemIDs())));
        return; // abort processing this <JAXWS:bindings>
      }
    }

    // if the target node is xs:schema, declare the jaxb version on it as latter on it will be
    // required by the inlined schema bindings

    Element element = DOMUtil.getFirstElementChild(target);
    if (element != null
        && element.getNamespaceURI().equals(Constants.NS_WSDL)
        && element.getLocalName().equals("definitions")) {
      // get all schema elements
      Element type = DOMUtils.getFirstChildElement(element, Constants.NS_WSDL, "types");
      if (type != null) {
        for (Element schemaElement : DOMUtils.getChildElements(type, Constants.NS_XSD, "schema")) {
          if (!schemaElement.hasAttributeNS(Constants.NS_XMLNS, "jaxb")) {
            schemaElement.setAttributeNS(
                Constants.NS_XMLNS, "xmlns:jaxb", JAXWSBindingsConstants.NS_JAXB_BINDINGS);
          }

          // add jaxb:bindings version info. Lets put it to 1.0, may need to change latter
          if (!schemaElement.hasAttributeNS(JAXWSBindingsConstants.NS_JAXB_BINDINGS, "version")) {
            schemaElement.setAttributeNS(
                JAXWSBindingsConstants.NS_JAXB_BINDINGS,
                "jaxb:version",
                JAXWSBindingsConstants.JAXB_BINDING_VERSION);
          }
        }
      }
    }

    boolean hasNode = true;
    if ((isJAXWSBindings(bindings) || isJAXBBindings(bindings))
        && bindings.getAttributeNode("node") != null) {
      target =
          evaluateXPathNode(
              bindings, target, bindings.getAttribute("node"), new NamespaceContextImpl(bindings));
    } else if (isJAXWSBindings(bindings)
        && (bindings.getAttributeNode("node") == null)
        && !isTopLevelBinding(bindings)) {
      hasNode = false;
    } else if (isGlobalBinding(bindings)
        && !isWSDLDefinition(target)
        && isTopLevelBinding(bindings.getParentNode())) {
      target = getWSDLDefintionNode(bindings, target);
    }

    // if target is null it means the xpath evaluation has some problem,
    // just return
    if (target == null) return;

    // update the result map
    if (hasNode) result.put(bindings, target);

    // look for child <JAXWS:bindings> and process them recursively
    Element[] children = getChildElements(bindings);
    for (Element child : children) buildTargetNodeMap(child, target, result);
  }