Example #1
0
  /**
   * Gets the dummy fault messages for the WSDL and operation name.
   *
   * @param wsdlUrl WSDL URL.
   * @param operationName operation name.
   * @return map of fault messages.
   */
  public static HashMap<String, String> getDummyFaults(String wsdlUrl, String operationName) {

    WsdlInterface intf = loadWsdl(wsdlUrl);

    WsdlOperation operation = intf.getOperationByName(operationName);

    FaultPart[] faultParts = operation.getFaultParts();

    HashMap<String, String> faultRespMap = new HashMap<String, String>();

    for (FaultPart faultPart : faultParts) {
      String faultString = intf.getMessageBuilder().buildFault(faultPart);

      faultString = faultString.replaceAll("\r\n      <!--Optional:-->", "");
      faultString = faultString.replaceAll("\r\n      <faultactor>\\?</faultactor>", "");
      faultString =
          faultString.replaceAll("\r\n        <!--You may enter ANY elements at this point-->", "");

      faultString =
          faultString.replaceFirst(
              "<faultcode>\\?</faultcode>", "<faultcode>soapenv:Server</faultcode>");

      if ("technicalFault".equals(faultPart.getName())) {
        faultString =
            faultString.replaceFirst(
                "<faultstring xml:lang=\"\\?\">\\?</faultstring>",
                "<faultstring>Technical Exception</faultstring>");
      } else if ("businessFault".equals(faultPart.getName())) {
        faultString =
            faultString.replaceFirst(
                "<faultstring xml:lang=\"\\?\">\\?</faultstring>",
                "<faultstring>Business Exception</faultstring>");
      }

      faultRespMap.put(faultPart.getName(), faultString);
    }

    return faultRespMap;
  }