@Test public void testIsValidXMLInvalidAttr() { String paramValue="<order xmlns=\"myns\" id=\"1\">" + "<item price=\"12345\" quantity=\"6\" >" + "<productCode>abc</productCode>" + "</item>"+ "<customer name=\"fred\">" + "<address>XYZ</address>" + "</customer>" + "</order>"; String mesgValue="<order xmlns=\"myns\" id=\"1\">" + "<customer name=\"fredX\">" + "<address>XYZ</address>" + "</customer>" + "<item quantity=\"6\" price=\"12345\" >" + "<productCode>abc</productCode>" + "</item>"+ "</order>"; try { if (MessageUtil.isValid(paramValue, XMLUtils.getNode(mesgValue)) == true) { fail("Should be invalid"); } } catch(Exception e) { fail("Failed: "+e); } }
public static boolean isValid(String paramValue, Object mesgValue) { boolean ret=false; if (mesgValue instanceof String) { ret = paramValue.equals(mesgValue); if (!ret) { try { mesgValue = XMLUtils.getNode((String)mesgValue); } catch(Exception e) { e.printStackTrace(); } } } if (mesgValue instanceof org.w3c.dom.Node) { try { logger.info("Validating value="+XMLUtils.toText((org.w3c.dom.Node)mesgValue)); org.w3c.dom.Node paramValueNode=XMLUtils.getNode(paramValue); if (paramValueNode != null) { ret = isValid(paramValueNode, (org.w3c.dom.Node)mesgValue); } else { logger.severe("Parameter value is not XML"); } } catch(Exception e) { e.printStackTrace(); } } return(ret); }
MessageUtil { public static boolean isValid(String paramValue, Object mesgValue) { boolean ret=false; if (mesgValue instanceof String) { ret = paramValue.equals(mesgValue); if (!ret) { try { mesgValue = XMLUtils.getNode((String)mesgValue); } catch(Exception e) { e.printStackTrace(); } } } if (mesgValue instanceof org.w3c.dom.Node) { try { logger.info("Validating value="+XMLUtils.toText((org.w3c.dom.Node)mesgValue)); org.w3c.dom.Node paramValueNode=XMLUtils.getNode(paramValue); if (paramValueNode != null) { ret = isValid(paramValueNode, (org.w3c.dom.Node)mesgValue); } else { logger.severe("Parameter value is not XML"); } } catch(Exception e) { e.printStackTrace(); } } return(ret); } }
MessageUtil { public static boolean isValid(String paramValue, Object mesgValue) { boolean ret=false; if (mesgValue instanceof String) { ret = paramValue.equals(mesgValue); if (!ret) { try { mesgValue = XMLUtils.getNode((String)mesgValue); } catch(Exception e) { e.printStackTrace(); } } } if (mesgValue instanceof org.w3c.dom.Node) { try { logger.info("Validating value="+XMLUtils.toText((org.w3c.dom.Node)mesgValue)); org.w3c.dom.Node paramValueNode=XMLUtils.getNode(paramValue); if (paramValueNode != null) { ret = isValid(paramValueNode, (org.w3c.dom.Node)mesgValue); } else { logger.severe("Parameter value is not XML"); } } catch(Exception e) { e.printStackTrace(); } } return(ret); }  }
MessageUtil { public static boolean isValid(String paramValue, Object mesgValue) { boolean ret=false; if (mesgValue instanceof String) { ret = paramValue.equals(mesgValue); if (!ret) { try { mesgValue = XMLUtils.getNode((String)mesgValue); } catch(Exception e) { e.printStackTrace(); } } } if (mesgValue instanceof org.w3c.dom.Node) { try { logger.info("Validating value="+XMLUtils.toText((org.w3c.dom.Node)mesgValue)); org.w3c.dom.Node paramValueNode=XMLUtils.getNode(paramValue); if (paramValueNode != null) { ret = isValid(paramValueNode, (org.w3c.dom.Node)mesgValue); } else { logger.severe("Parameter value is not XML"); } } catch(Exception e) { e.printStackTrace(); } } return(ret); }  static boolean isValid(String paramValue, Object mesgValue); static boolean isValid(org.w3c.dom.Node paramValue, org.w3c.dom.Node mesgValue); }
MessageUtil { public static boolean isValid(String paramValue, Object mesgValue) { boolean ret=false; if (mesgValue instanceof String) { ret = paramValue.equals(mesgValue); if (!ret) { try { mesgValue = XMLUtils.getNode((String)mesgValue); } catch(Exception e) { e.printStackTrace(); } } } if (mesgValue instanceof org.w3c.dom.Node) { try { logger.info("Validating value="+XMLUtils.toText((org.w3c.dom.Node)mesgValue)); org.w3c.dom.Node paramValueNode=XMLUtils.getNode(paramValue); if (paramValueNode != null) { ret = isValid(paramValueNode, (org.w3c.dom.Node)mesgValue); } else { logger.severe("Parameter value is not XML"); } } catch(Exception e) { e.printStackTrace(); } } return(ret); }  static boolean isValid(String paramValue, Object mesgValue); static boolean isValid(org.w3c.dom.Node paramValue, org.w3c.dom.Node mesgValue);  }