Example #1
0
  /**
   * Validates the request SOAP message against the WSDL.
   *
   * @param wsdlUrl WSDL URL.
   * @param operationName operation name.
   * @param request request SOAP message.
   * @return list of error messages if any.
   */
  public static List<String> validateRequest(String wsdlUrl, String operationName, String request) {

    WsdlInterface intf = loadWsdl(wsdlUrl);

    WsdlOperation operation = intf.getOperationByName(operationName);

    if (operation == null) {
      throw new MockException("Operation " + operationName + " not found.");
    }

    WsdlRequest req = operation.addNewRequest("something");
    req.setRequestContent(request);
    WsdlValidator validator = new WsdlValidator(intf.getWsdlContext());

    List<String> errorList = new ArrayList<String>();

    try {
      AssertionError[] errors =
          validator.assertRequest(new WsdlResponseMessageExchange(req), false);

      for (AssertionError error : errors) {
        errorList.add(error.toString());
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new MockException("Unable to validate the message.");
    }

    return errorList;
  }
Example #2
0
  /**
   * Validates the XML structure.
   *
   * @param xml input xml.
   * @return list of errors.
   */
  public static List<String> validateXml(String xml) {
    WsdlValidator validator = new WsdlValidator(null);

    List<XmlError> errorList = new ArrayList<XmlError>();
    validator.validateXml(xml, errorList);
    List<String> errors = new ArrayList<String>();
    for (XmlError error : errorList) {
      errors.add("Line " + error.getLine() + ": " + error.getMessage());
    }
    return errors;
  }