1 55 56 package org.jboss.axis.handlers; 57 58 59 import org.jboss.axis.AxisFault; 60 import org.jboss.axis.Message; 61 import org.jboss.axis.MessageContext; 62 import org.jboss.axis.soap.SOAPConstants; 63 import org.jboss.axis.utils.Messages; 64 import org.jboss.logging.Logger; 65 66 67 71 public class MD5AttachHandler extends org.jboss.axis.handlers.BasicHandler 72 { 73 private static Logger log = Logger.getLogger(MD5AttachHandler.class.getName()); 74 75 public void invoke(MessageContext msgContext) throws AxisFault 76 { 77 log.debug("Enter: EchoHandler::invoke"); 78 try 79 { 80 Message msg = msgContext.getRequestMessage(); 82 SOAPConstants soapConstants = msgContext.getSOAPConstants(); 83 org.jboss.axis.message.SOAPEnvelopeAxisImpl env = (org.jboss.axis.message.SOAPEnvelopeAxisImpl)msg.getSOAPEnvelope(); 84 org.jboss.axis.message.SOAPBodyElementAxisImpl sbe = env.getFirstBody(); org.w3c.dom.Element sbElement = sbe.getAsDOM(); 86 org.w3c.dom.Node n = sbElement.getFirstChild(); 88 89 for (; n != null && !(n instanceof org.w3c.dom.Element ); n = n.getNextSibling()) ; 90 org.w3c.dom.Element paramElement = (org.w3c.dom.Element )n; 91 String href = paramElement.getAttribute(soapConstants.getAttrHref()); 93 org.jboss.axis.Part ap = msg.getAttachmentsImpl().getAttachmentByReference(href); 94 javax.activation.DataHandler dh = org.jboss.axis.attachments.AttachmentUtils.getActivationDataHandler(ap); 95 org.w3c.dom.Node timeNode = paramElement.getFirstChild(); 96 long startTime = -1; 97 98 if (timeNode != null && timeNode instanceof org.w3c.dom.Text ) 99 { 100 String startTimeStr = ((org.w3c.dom.Text )timeNode).getData(); 101 102 startTime = Long.parseLong(startTimeStr); 103 } 104 106 long receivedTime = System.currentTimeMillis(); 107 long elapsedTime = -1; 108 109 if (startTime > 0) elapsedTime = receivedTime - startTime; 112 String elapsedTimeStr = elapsedTime + ""; 113 115 java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); 116 java.io.InputStream attachmentStream = dh.getInputStream(); 117 int bread = 0; 118 byte[] buf = new byte[64 * 1024]; 119 120 do 121 { 122 bread = attachmentStream.read(buf); 123 if (bread > 0) 124 { 125 md.update(buf, 0, bread); 126 } 127 } 128 while (bread > -1); 129 attachmentStream.close(); 130 buf = null; 131 String contentType = dh.getContentType(); 133 134 if (contentType != null && contentType.length() != 0) 135 { 136 md.update(contentType.getBytes("US-ASCII")); 137 } 138 139 sbe = env.getFirstBody(); 140 sbElement = sbe.getAsDOM(); 141 n = sbElement.getFirstChild(); 143 for (; n != null && !(n instanceof org.w3c.dom.Element ); n = n.getNextSibling()) ; 144 paramElement = (org.w3c.dom.Element )n; 145 String MD5String = org.jboss.axis.encoding.Base64.encode(md.digest()); 147 String senddata = " elapsedTime=" + elapsedTimeStr + " MD5=" + MD5String; 148 149 paramElement.appendChild(paramElement.getOwnerDocument().createTextNode(senddata)); 151 152 sbe = new org.jboss.axis.message.SOAPBodyElementAxisImpl(sbElement); 153 env.clearBody(); 154 env.addBodyElement(sbe); 155 msg = new Message(env); 156 157 msgContext.setResponseMessage(msg); 158 } 159 catch (Exception e) 160 { 161 log.error(Messages.getMessage("exception00"), e); 162 throw AxisFault.makeFault(e); 163 } 164 165 log.debug("Exit: EchoHandler::invoke"); 166 } 167 168 } 169 | Popular Tags |