1 57 58 package org.apache.soap; 59 60 import java.io.*; 61 import java.util.*; 62 import javax.xml.parsers.*; 63 import org.w3c.dom.*; 64 import org.apache.soap.util.xml.*; 65 66 73 public class Utils 74 { 75 public static String cleanString(String orig) 76 { 77 if (orig == null) 78 { 79 return ""; 80 } 81 82 StringBuffer strBuf = new StringBuffer (); 83 char[] chars = orig.toCharArray(); 84 85 for (int i = 0; i < chars.length; i++) 86 { 87 switch (chars[i]) 88 { 89 case '&' : strBuf.append("&"); 90 break; 91 case '\"' : strBuf.append("""); 92 break; 93 case '\'' : strBuf.append("'"); 94 break; 95 case '<' : strBuf.append("<"); 96 break; 97 case '>' : strBuf.append(">"); 98 break; 99 default : strBuf.append(chars[i]); 100 break; 101 } 102 } 103 104 return strBuf.toString(); 105 } 106 107 public static void marshallNode(Node node, Writer sink) 108 { 109 DOM2Writer.serializeAsXML(node, sink); 110 } 111 112 117 public static Vector buildFaultDetailsFromThrowable (Throwable t) 118 { 119 Vector details = new Vector(); 120 DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder(); 121 Document doc = xdb.newDocument(); 122 Element elem = doc.createElement("stackTrace"); 123 StringWriter sw = new StringWriter(); 124 PrintWriter pw = new PrintWriter(sw); 125 t.printStackTrace(pw); 126 pw.close(); 127 Text tn = doc.createTextNode(cleanString(sw.toString())); 128 elem.appendChild(tn); 129 details.addElement(elem); 130 return details; 131 } 132 133 137 public static void checkMustUnderstands(Header header) throws SOAPException 138 { 139 Vector entries = header.getHeaderEntries(); 140 141 for (int i = 0; i < entries.size(); i++) 142 { 143 Element el = (Element)entries.elementAt(i); 144 String val = el.getAttributeNS(Constants.NS_URI_SOAP_ENV, 145 Constants.ATTR_MUST_UNDERSTAND); 146 147 if (val != null && val.equals("1")) 148 { 149 throw new SOAPException("mustUnderstand", 150 "Didn't understand header '" + 151 el.getLocalName() + "'"); 152 } 153 } 154 } 155 } 156 | Popular Tags |