1 16 package org.apache.axis.message; 17 18 import org.apache.axis.AxisFault; 19 import org.apache.axis.Constants; 20 import org.apache.axis.MessageContext; 21 import org.apache.axis.description.FaultDesc; 22 import org.apache.axis.description.OperationDesc; 23 import org.apache.axis.encoding.Callback; 24 import org.apache.axis.encoding.CallbackTarget; 25 import org.apache.axis.encoding.DeserializationContext; 26 import org.apache.axis.encoding.Deserializer; 27 import org.apache.axis.encoding.DeserializerImpl; 28 import org.apache.axis.soap.SOAPConstants; 29 import org.apache.axis.utils.ClassUtils; 30 import org.apache.axis.utils.Messages; 31 import org.xml.sax.Attributes ; 32 import org.xml.sax.SAXException ; 33 34 import javax.xml.namespace.QName ; 35 import java.util.Iterator ; 36 37 43 public class SOAPFaultDetailsBuilder extends SOAPHandler implements Callback 44 { 45 protected SOAPFaultBuilder builder; 46 47 public SOAPFaultDetailsBuilder(SOAPFaultBuilder builder) { 48 this.builder = builder; 49 } 50 51 52 public void startElement(String namespace, String localName, 53 String prefix, Attributes attributes, 54 DeserializationContext context) 55 throws SAXException 56 { 57 SOAPConstants soapConstants = context.getSOAPConstants(); 58 59 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS && 60 attributes.getValue(Constants.URI_SOAP12_ENV, Constants.ATTR_ENCODING_STYLE) != null) { 61 62 AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, 63 null, Messages.getMessage("noEncodingStyleAttrAppear", "Detail"), null, null, null); 64 65 throw new SAXException (fault); 66 } 67 68 super.startElement(namespace, localName, prefix, attributes, context); 69 } 70 71 public SOAPHandler onStartChild(String namespace, 72 String name, 73 String prefix, 74 Attributes attributes, 75 DeserializationContext context) 76 throws SAXException 77 { 78 QName qn = new QName (namespace, name); 80 81 if (name.equals("exceptionName")) { 85 Deserializer dser = context.getDeserializerForType(Constants.XSD_STRING); 87 dser.registerValueTarget(new CallbackTarget(this, "exceptionName")); 88 return (SOAPHandler)dser; 89 } 90 91 MessageContext msgContext = context.getMessageContext(); 94 SOAPConstants soapConstants = Constants.DEFAULT_SOAP_VERSION; 95 OperationDesc op = null; 96 if (msgContext != null) { 97 soapConstants = msgContext.getSOAPConstants(); 98 op = msgContext.getOperation(); 99 } 100 Class faultClass = null; 101 QName faultXmlType = null; 102 if (op != null) { 103 FaultDesc faultDesc = null; 104 faultXmlType = context.getTypeFromAttributes(namespace, 106 name, 107 attributes); 108 if (faultXmlType != null) { 109 faultDesc = op.getFaultByXmlType(faultXmlType); 110 } 111 112 if (faultDesc == null) { 114 faultDesc = op.getFaultByQName(qn); 115 if ((faultXmlType == null) && (faultDesc != null)) { 116 faultXmlType = faultDesc.getXmlType(); 117 } 118 } 119 120 if (faultDesc == null && op.getFaults() != null) { 121 Iterator i = op.getFaults().iterator(); 122 while(i.hasNext()) { 123 FaultDesc fdesc = (FaultDesc) i.next(); 124 if(fdesc.getClassName().equals(name)) { 125 faultDesc = fdesc; 126 faultXmlType = fdesc.getXmlType(); 127 break; 128 } 129 } 130 } 131 132 if (faultDesc != null) { 134 try { 135 faultClass = ClassUtils.forName(faultDesc.getClassName()); 136 } catch (ClassNotFoundException e) { 137 } 139 } 140 } else { 141 faultXmlType = context.getTypeFromAttributes(namespace, 142 name, 143 attributes); 144 } 145 146 if (faultClass == null) { 147 faultClass = 148 context.getTypeMapping().getClassForQName(faultXmlType); 149 } 150 151 if(faultClass != null && faultXmlType != null) { 152 builder.setFaultClass(faultClass); 153 builder.setWaiting(true); 154 Deserializer dser = null; 156 if (attributes.getValue(soapConstants.getAttrHref()) == null) { 157 dser = context.getDeserializerForType(faultXmlType); 158 } else { 159 dser = new DeserializerImpl(); 160 dser.setDefaultType(faultXmlType); 161 } 162 if (dser != null) { 163 dser.registerValueTarget(new CallbackTarget(this, "faultData")); 164 } 165 return (SOAPHandler)dser; 166 } 167 return null; 168 } 169 170 176 public void setValue(Object value, Object hint) 177 { 178 if ("faultData".equals(hint)) { 179 builder.setFaultData(value); 180 } else if ("exceptionName".equals(hint)) { 181 String faultClassName = (String ) value; 182 try { 183 Class faultClass = ClassUtils.forName(faultClassName); 184 builder.setFaultClass(faultClass); 185 } catch (ClassNotFoundException e) { 186 } 188 } 189 190 } 191 } 192 193 194 | Popular Tags |