1 16 17 package org.apache.axis.transport.http; 18 19 import org.apache.axis.MessageContext; 20 import org.apache.axis.AxisFault; 21 import org.apache.axis.Constants; 22 import org.apache.axis.Message; 23 import org.apache.axis.utils.Messages; 24 import org.apache.axis.utils.XMLUtils; 25 import org.apache.commons.logging.Log; 26 import org.w3c.dom.Element ; 27 28 import javax.servlet.http.HttpServletResponse ; 29 import java.io.PrintWriter ; 30 31 35 public abstract class AbstractQueryStringHandler implements QSHandler { 36 37 private boolean development; 38 39 protected Log exceptionLog; 40 41 42 protected Log log; 43 44 48 49 protected boolean isDevelopment () { 50 return this.development; 51 } 52 53 58 protected void configureFromContext(MessageContext msgContext) { 59 this.development = ((Boolean ) msgContext.getProperty 60 (HTTPConstants.PLUGIN_IS_DEVELOPMENT)).booleanValue(); 61 this.exceptionLog = (Log) msgContext.getProperty 62 (HTTPConstants.PLUGIN_EXCEPTION_LOG); 63 this.log = (Log) msgContext.getProperty(HTTPConstants.PLUGIN_LOG); 64 } 65 66 72 73 protected void processAxisFault (AxisFault fault) { 74 76 Element runtimeException = fault.lookupFaultDetail 77 (Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION); 78 79 if (runtimeException != null) { 80 exceptionLog.info (Messages.getMessage ("axisFault00"), fault); 81 82 84 fault.removeFaultDetail 85 (Constants.QNAME_FAULTDETAIL_RUNTIMEEXCEPTION); 86 } 87 88 else if (exceptionLog.isDebugEnabled()) { 89 exceptionLog.debug (Messages.getMessage ("axisFault00"), fault); 90 } 91 92 94 if (!isDevelopment()) { 95 97 fault.removeFaultDetail (Constants.QNAME_FAULTDETAIL_STACKTRACE); 98 } 99 } 100 101 107 108 protected void configureResponseFromAxisFault (HttpServletResponse response, 109 AxisFault fault) { 110 114 int status = getHttpServletResponseStatus (fault); 115 116 if (status == HttpServletResponse.SC_UNAUTHORIZED) { 117 120 response.setHeader ("WWW-Authenticate", "Basic realm=\"AXIS\""); 121 } 122 123 response.setStatus (status); 124 } 125 126 136 137 protected Message convertExceptionToAxisFault (Exception exception, 138 Message responseMsg) { 139 logException (exception); 140 141 if (responseMsg == null) { 142 AxisFault fault = AxisFault.makeFault (exception); 143 144 processAxisFault (fault); 145 146 responseMsg = new Message (fault); 147 } 148 149 return responseMsg; 150 } 151 152 158 159 private int getHttpServletResponseStatus (AxisFault af) { 160 163 return af.getFaultCode().getLocalPart().startsWith ("Server.Unauth") 164 ? HttpServletResponse.SC_UNAUTHORIZED 165 : HttpServletResponse.SC_INTERNAL_SERVER_ERROR; 166 167 } 170 171 175 176 private void logException (Exception e) { 177 exceptionLog.info (Messages.getMessage ("exception00"), e); 178 } 179 180 186 187 protected void writeFault (PrintWriter writer, AxisFault axisFault) { 188 String localizedMessage = XMLUtils.xmlEncodeString 189 (axisFault.getLocalizedMessage()); 190 191 writer.println ("<pre>Fault - " + localizedMessage + "<br>"); 192 writer.println (axisFault.dumpToString()); 193 writer.println ("</pre>"); 194 } 195 } 196 | Popular Tags |