Package org.eclipse.wst.wsi.internal.core.analyzer

Examples of org.eclipse.wst.wsi.internal.core.analyzer.AssertionFailException


          mimeContentsFound = true;
          Input portTypeInput = bindingOperation.getOperation().getInput();
          // If there is no the corresponding wsdl:input in wsdl:portType,
          // the assertion failed
          if (portTypeInput == null)
            throw new AssertionFailException(
              "There is no the corresponging wsdl:input in the wsdl:portType"
              + " operation for the wsdl:input of the \""
              + bindingOperation.getName() + "\" binding operation.");

          // If the wsdl:portType input does not reference any wsdl:message,
          // the assertion failed
          if (portTypeInput.getMessage() == null)
            throw new AssertionFailException("The wsdl:input of the \""
              + bindingOperation.getOperation().getName() + "\" wsdl:portType "
              + "operation does not reference any wsdl:message.");

          // Getting the part name that is not specified in the wsdl:message
          // the input of wsdl:portType refers to
          String part = getInvalidMimeContentPart(
            inputMimeContents, portTypeInput.getMessage());

          // If such part is found, the assertion failed
          if (part != null)
            throw new AssertionFailException("part=\"" + part +
              "\", the input of the binding operation \""
              + bindingOperation.getName() + "\"");
        }

        // If the wsdl:output contains mime:content elements
        if (!outputMimeContents.isEmpty())
        {
          mimeContentsFound = true;
          Output portTypeOutput = bindingOperation.getOperation().getOutput();
          // If there is no the corresponding wsdl:input in wsdl:portType,
          // the assertion failed
          if (portTypeOutput == null)
            throw new AssertionFailException(
              "There is no the corresponging wsdl:output in the wsdl:portType"
              + " operation for the wsdl:output of the \""
              + bindingOperation.getName() + "\" binding operation.");

          // If the wsdl:portType output does not reference any wsdl:message,
          // the assertion failed
          if (portTypeOutput.getMessage() == null)
            throw new AssertionFailException("The wsdl:output of the \""
              + bindingOperation.getOperation().getName() + "\" wsdl:portType "
              + "operation does not reference any wsdl:message.");

          // Getting the part name that is not specified in the wsdl:message
          // the output of wsdl:portType refers to
          String part = getInvalidMimeContentPart(
              outputMimeContents, portTypeOutput.getMessage());

          // If such part is found, the assertion failed
          if (part != null)
            throw new AssertionFailException("part=\"" + part +
                "\", the output of the binding operation \""
                + bindingOperation.getName() + "\"");
        }
      }
View Full Code Here


      if (doc == null)
      {
        if (this.validator.isOneWayResponse(entryContext))
          throw new AssertionNotApplicableException();
        else
          throw new AssertionFailException("The log message is empty or invalid.");
      }
      // SOAP 1.1 specifications, Section 4.
      // http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383494

      // The namespace identifier for the elements and attributes defined
      // in this section is "http://schemas.xmlsoap.org/soap/envelope/".

      //  o The Envelope is the top element of the XML document representing the message.

      // Rule 1. Envelope
      //  o The element name is "Envelope".
      //  o The element MUST be present in a SOAP message
      //  o The element MAY contain namespace declarations as well as additional attributes.
      //    If present, such additional attributes MUST be namespace-qualified. Similarly,
      //    the element MAY contain additional sub elements. If present these elements
      //    MUST be namespace-qualified and MUST follow the SOAP Body element.

      // Getting the top element
      Element element = doc.getDocumentElement();

      // Assuming that the top element should be soap:Envelope
      // If not, the assertion failed
      if (!element.getLocalName().equals(XMLUtils.SOAP_ELEM_ENVELOPE)
        || !isSOAPNamespace(element.getNamespaceURI()))
        throw new AssertionFailException("The top element is not soap:Envelope");

      // Collecting all the namespace declarations
      Collection envelopeNamespaces = collectNamespaces(element.getAttributes());
      envelopeNamespaces.add(WSIConstants.NS_URI_XMLNS);

      // Getting an attribute that is not in any of the namespaces
      Attr notValidAttr = getNotValidAttr(
        element.getAttributes(),
        envelopeNamespaces);

      // If found one, the assertion failed
      if (notValidAttr != null)
        throw new AssertionFailException("The attribute "
          + notValidAttr.getNodeName() + " is not namespace-qualified");


      // Rule 2. Header
      //  o The element name is "Header".
      //  o The element MAY be present in a SOAP message. If present, the element
      //    MUST be the first immediate child element of a SOAP Envelope element.
      //  o The element MAY contain a set of header entries each being an immediate
      //    child element of the SOAP Header element. All immediate child elements
      //    of the SOAP Header element MUST be namespace-qualified.

      // Getting the first sub element of the envelope
      element = XMLUtils.getFirstChild(element);
      Collection headerNamespaces = collectNamespaces(element.getAttributes());

      // If the child is soap:Header
      if (element != null
        && element.getLocalName().equals(XMLUtils.SOAP_ELEM_HEADER)
        && isSOAPNamespace(element.getNamespaceURI()))
      {

        // Going through all the Header entries
        Element headerEntry = XMLUtils.getFirstChild(element);
        while (headerEntry != null)
        {
          // Collecting all the namespaces for the current entry
          Collection headerEntryNamespaces = collectNamespaces(
            headerEntry.getAttributes());

          // If the entry is not in the namespaces, the assertion failed
          if (!envelopeNamespaces.contains(headerEntry.getNamespaceURI())
            && !headerNamespaces.contains(headerEntry.getNamespaceURI())
            && !headerEntryNamespaces.contains(headerEntry.getNamespaceURI()))
            throw new AssertionFailException("The header entry "
              + headerEntry.getNodeName() + " is not namespace-qualified");

          // Getting the next Header entry
          headerEntry = XMLUtils.getNextSibling(headerEntry);
        }

        // Getting the next sub element of the envelope
        element = XMLUtils.getNextSibling(element);
      }


      // Rule 3. Body
      //  o The element name is "Body".
      //  o The element MUST be present in a SOAP message and MUST be an immediate
      //    child element of a SOAP Envelope element. It MUST directly follow the
      //    SOAP Header element if present. Otherwise it MUST be the first immediate
      //    child element of the SOAP Envelope element.
      //  o The element MAY contain a set of body entries each being an immediate
      //    child element of the SOAP Body element. Immediate child elements of the
      //    SOAP Body element MAY be namespace-qualified. SOAP defines the SOAP Fault
      //    element, which is used to indicate error messages.

      // if the SOAP Body element is not presented, the assertion failed
      if (element == null
        || !element.getLocalName().equals(XMLUtils.SOAP_ELEM_BODY)
        || !isSOAPNamespace(element.getNamespaceURI()))
        throw new AssertionFailException("The soap:Body element is not presented "
          + "or follows an additional sub element of soap:Envelope");

      // Processing all other sub elements of the envelope
      element = XMLUtils.getNextSibling(element);
      while (element != null)
      {
        // Checking for the SOAP Header element
        if (element.getLocalName().equals(XMLUtils.SOAP_ELEM_HEADER)
          && isSOAPNamespace(element.getNamespaceURI()))
            throw new AssertionFailException(
              "The soap:Header element cannot follow the soap:Body element");

        // Collecting all the namespaces for the current element
        Collection elementNamespaces = collectNamespaces(
          element.getAttributes());

        // If the element is not in the namespaces, the assertion failed
        if (!envelopeNamespaces.contains(element.getNamespaceURI())
          && !elementNamespaces.contains(element.getNamespaceURI()))
          throw new AssertionFailException("The sub envelope element "
            + element.getNodeName() + " is not namespace-qualified");

        // Getting the next sub element of the envelope
        element = XMLUtils.getNextSibling(element);
      }
View Full Code Here

      {
        String partName = getMIMEContentPart((MIMEPart) parts.get(i));
        // find the corresponding MIME part
        if (findMIMEPart(mimeParts.getParts(), partName) == null)
        {           
          throw new AssertionFailException("The corresponding binding " +
              "operation \"" + bindingOperation.getName() +
              "\" does not contain part \"" + partName + "\"");
        }
      }
    }
View Full Code Here

          Input portTypeInput = bindingOperation.getOperation().getInput();
          // If there is no the corresponding wsdl:input in wsdl:portType
          // or the wsdl:input does not specify a message attribute,
          // the assertion failed
          if (portTypeInput == null || portTypeInput.getMessage() == null)
            throw new AssertionFailException(
              "The corresponging operation in the wsdl:portType for the \""
              + bindingOperation.getName() + "\" binding operation is invalid.");
          // Getting a mime:content referencing an invalid wsdl:part
          String part = getInvalidMimeContentPart(
            inputMimeContents, portTypeInput.getMessage());
          // If such part is found, the assertion failed
          if (part != null)
            throw new AssertionFailException("part=\"" + part +
              "\", the input of the binding operation \""
              + bindingOperation.getName() + "\"");
        }

        // If the wsdl:output contains mime:content elements
        if (!outputMimeContents.isEmpty())
        {
          mimeContentsFound = true;
          Output portTypeOutput = bindingOperation.getOperation().getOutput();
          // If there is no the corresponding wsdl:output in wsdl:portType
          // or the wsdl:output does not specify a message attribute,
          // the assertion failed
          if (portTypeOutput == null || portTypeOutput.getMessage() == null)
            throw new AssertionFailException(
              "The corresponging operation in the wsdl:portType for the \""
              + bindingOperation.getName() + "\" binding operation is invalid.");
          // Getting a mime:content referencing an invalid wsdl:part
          String part = getInvalidMimeContentPart(
              outputMimeContents, portTypeOutput.getMessage());
          // If such part is found, the assertion failed
          if (part != null)
            throw new AssertionFailException("part=\"" + part +
                "\", the output of the binding operation \""
                + bindingOperation.getName() + "\"");
        }
      }
View Full Code Here

  {
    try
    {

      if (this.validator.isOneWayResponse(entryContext))
        throw new AssertionFailException(
          AssertionResult.RESULT_NOT_APPLICABLE);

      // Parse message
      Document doc = entryContext.getMessageEntryDocument();

      // If there is no message, then throw fail exception
      if (doc == null)
        throw new AssertionFailException();

      if (this.validator.isFault(doc))
      {
        throw new AssertionFailException(
          AssertionResult.RESULT_NOT_APPLICABLE);
      }

      // Check if there is a soap body element
      if (!this.validator.containsSoapBodyWithChild(doc))
      {
        throw new AssertionNotApplicableException();
      }

      // Parse request message
      Document docRequest = entryContext.getRequestDocument();

      // get SOAPAction
      String action =
        validator.getSoapAction(entryContext.getRequest().getHTTPHeaders());

      Binding binding = validator.analyzerContext.getCandidateInfo().getBindings()[0];
      //Definition definition = entryContext.getAnalyzerContext().getCandidateInfo().getDefinitions()[0];
      TypesRegistry registry =
        new TypesRegistry(
          this.validator.getWSDLDocument().getDefinitions(),
          validator);
      OperationSignature.OperationMatch match =
        OperationSignature.matchOperation(
          docRequest,
          action,
          binding,
          registry);
      if (match == null)
        throw new AssertionNotApplicableException();

      BindingOperation bindingOperation = match.getOperation();

      // Is rpc style?
      if (!WSIConstants
        .ATTRVAL_SOAP_BIND_STYLE_RPC
        .equals(match.getOperationStyle()))
        throw new AssertionFailException(
          AssertionResult.RESULT_NOT_APPLICABLE);

      // Gets body
      NodeList soapBodyList =
        doc.getElementsByTagNameNS(
          WSIConstants.NS_URI_SOAP,
          XMLUtils.SOAP_ELEM_BODY);
      if (soapBodyList.getLength() == 0 || soapBodyList.getLength() > 1)
      {
        // There is not a body or more than one bodies in the envlope.
        throw new AssertionFailException();
      }
      Element soapBodyElem = (Element) soapBodyList.item(0);

      result = null;

      // Find operation in the body
      Element soapOperation = XMLUtils.getFirstChild(soapBodyElem);
      if (soapOperation == null)
      {
        throw new AssertionFailException();
      }

      // Find operation message and ext. elements in the binding
      Message operationMessage = null;
      List extElements = null;
      if (MessageEntry
        .TYPE_REQUEST
        .equals(entryContext.getMessageEntry().getType()))
      {
        operationMessage =
          bindingOperation.getOperation().getInput().getMessage();
        if (bindingOperation.getBindingInput() != null)
          extElements =
            bindingOperation.getBindingInput().getExtensibilityElements();
      }
      else
      {
        if (MessageEntry
          .TYPE_RESPONSE
          .equals(entryContext.getMessageEntry().getType()))
        {
          operationMessage =
            bindingOperation.getOperation().getOutput().getMessage();
          if (bindingOperation.getBindingOutput() != null)
            extElements =
              bindingOperation.getBindingOutput().getExtensibilityElements();
        }
      }

      // Is message RPC-literal?
      if (!validator.isLiteral(extElements))
        throw new AssertionFailException(
          AssertionResult.RESULT_NOT_APPLICABLE);

      // gets first child of message
      Element soapMessagePart = XMLUtils.getFirstChild(soapOperation);
      if (soapMessagePart == null)
      {
        throw new AssertionPassException();
      }

      while (soapMessagePart != null)
      {
        // check whether part accessor or return are in no namespace           

        if (soapMessagePart.getNamespaceURI() != null
          || "".equals(soapMessagePart.getNamespaceURI()))
        {
          throw new AssertionFailException();
        }

        //    check whether children are namespace qualified
        //  with the same targetNamespace with which their types are defined
        String typesTargetNS =
          getTypeNS(operationMessage, soapMessagePart.getLocalName());

        if (typesTargetNS == null)
          throw new AssertionFailException();

        if (!checkChildrenNamespace(soapMessagePart, typesTargetNS))
        {
          throw new AssertionFailException();
        }

        soapMessagePart = XMLUtils.getNextSibling(soapMessagePart);
      }
View Full Code Here

        throw new AssertionNotApplicableException();
      }

      if (this.validator.isFault(doc))
      {
        throw new AssertionFailException(
          AssertionResult.RESULT_NOT_APPLICABLE);
      }

      // get SOAPAction
      String headers = entryContext.getRequest().getHTTPHeaders();
      String action = null;
      if (headers != null)
        action = (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("SOAPAction".toUpperCase());

      Binding binding = validator.analyzerContext.getCandidateInfo().getBindings()[0];
      TypesRegistry registry =
        new TypesRegistry(
          this.validator.getWSDLDocument().getDefinitions(),
          validator);
      OperationSignature.OperationMatch match =
        OperationSignature.matchOperation(
          docRequest,
          action,
          binding,
          registry);

      if (match == null)
      {
        throw new AssertionNotApplicableException();
      }

      BindingOperation bindingOperation = match.getOperation();

      // If this is a one-way operation and we are processing a response, then set result to notApplicable
      if (bindingOperation
        .getOperation()
        .getStyle()
        .equals(OperationType.ONE_WAY)
        && (entryContext
          .getMessageEntry()
          .getType()
          .equals(MessageEntry.TYPE_RESPONSE)))
      {
        throw new AssertionNotApplicableException();
      }

      // find body
      NodeList soapBodyList =
        doc.getElementsByTagNameNS(
          WSIConstants.NS_URI_SOAP,
          XMLUtils.SOAP_ELEM_BODY);
      if (soapBodyList.getLength() == 0 || soapBodyList.getLength() > 1)
      {
        // There is not a body or more than one bodies in the envlope.
        throw new AssertionPassException();
      }
      // find headers
      NodeList soapHeaders =
        doc.getElementsByTagNameNS(
          WSITag.ELEM_SOAP_HEADER.getNamespaceURI(),
          WSITag.ELEM_SOAP_HEADER.getLocalPart());

      //find all operation
      //Element soapOperation = XMLUtils.getFirstChild(soapBodyElem);

      // gets soapbind:headers
      List bindingHeaders = null;
      if (entryContext
        .getMessageEntry()
        .getType()
        .equals(MessageEntry.TYPE_REQUEST))
      {
        if (bindingOperation.getBindingInput() != null)
          bindingHeaders =
            bindingOperation.getBindingInput().getExtensibilityElements();
        else
          throw new AssertionFailException();

      }
      else
      {
        if (entryContext
          .getMessageEntry()
          .getType()
          .equals(MessageEntry.TYPE_RESPONSE))
        {
          if (bindingOperation.getBindingOutput() != null)
            bindingHeaders =
              bindingOperation.getBindingOutput().getExtensibilityElements();
          else
            throw new AssertionFailException();
        }
      }
      if (bindingHeaders == null || bindingHeaders.size() == 0)
      {
        throw new AssertionPassException();
      }

      Iterator iterator = bindingHeaders.iterator();
      while (iterator.hasNext())
      {
        Object bindingHeader = iterator.next();
        if (bindingHeader instanceof SOAPHeader)
        {
          // find soapbind:header in SOAP message
          if (!isBindingHeaderInSOAPMessage(entryContext,
            soapHeaders,
            (SOAPHeader) bindingHeader))
          {
            throw new AssertionFailException();
          }
        }
      }

      result = AssertionResult.RESULT_PASSED;
View Full Code Here

        // If there is a mime:part containing multiple mime:contentS
        // which reference different wsdl:partS, the assertion failed
        if (containsInvalidMimePart(inputMimeParts))
        {
          throw new AssertionFailException("The invalid mime:part element "
            + "is in the wsdl:input of the \"" + bindingOperation.getName()
            + "\" binding operation.");
        }

        // If there is a mime:part containing multiple mime:contentS
        // which reference different wsdl:partS, the assertion failed
        if (containsInvalidMimePart(outputMimeParts))
        {
          throw new AssertionFailException("The invalid mime:part element "
            + "is in the wsdl:output of the \"" + bindingOperation.getName()
            + "\" binding operation.");
        }

      }
View Full Code Here

        {
          mimeContentsFound = true;
          // If there is a mime:content that does not include
          // the part attribute, the assertion failed
          if (hasInvalidMimeContent(inputMimeContents))
            throw new AssertionFailException("The invalid mime:content element"
              + " is in the wsdl:input of the \"" + bindingOperation.getName()
              + "\" binding operation.");
        }

        // If the wsdl:output contains mime:content elements
        if (!outputMimeContents.isEmpty())
        {
          mimeContentsFound = true;
          // If there is a mime:content that does not include
          // the part attribute, the assertion failed
          if (hasInvalidMimeContent(outputMimeContents))
            throw new AssertionFailException("The invalid mime:content element"
              + " is in the wsdl:output of the \"" + bindingOperation.getName()
              + "\" binding operation.");
        }
      }
View Full Code Here

        Iterator i = duplicates.iterator();
        while (i.hasNext())
        {
          failInfo.append((String) i.next() + "; ");
        }
        throw new AssertionFailException(failInfo.toString());
      }
    }
    catch (NullPointerException e)
    { // ?? no operations found, but does not fail the assertion.
      result = AssertionResult.RESULT_NOT_APPLICABLE;
View Full Code Here

TOP

Related Classes of org.eclipse.wst.wsi.internal.core.analyzer.AssertionFailException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.