1 10 11 package org.mule.routing.inbound; 12 13 import org.mule.transformers.simple.ByteArrayToHexString; 14 import org.mule.transformers.simple.SerializableToByteArray; 15 import org.mule.umo.MessagingException; 16 import org.mule.umo.UMOEvent; 17 import org.mule.umo.routing.RoutingException; 18 import org.mule.umo.transformer.TransformerException; 19 20 import java.security.MessageDigest ; 21 import java.security.NoSuchAlgorithmException ; 22 23 40 41 public class IdempotentSecureHashReceiver extends IdempotentReceiver 42 { 43 private static final String messageDigestAlgorithm = "SHA-256"; 44 45 private SerializableToByteArray objectToByteArray = new SerializableToByteArray(); 46 private ByteArrayToHexString byteArrayToHexString = new ByteArrayToHexString(); 47 48 protected String getIdForEvent(UMOEvent event) throws MessagingException 49 { 50 try 51 { 52 MessageDigest md = MessageDigest.getInstance(messageDigestAlgorithm); 53 return (String )byteArrayToHexString.transform(md.digest((byte[])objectToByteArray.transform(event.getMessage() 54 .getPayload()))); 55 } 56 catch (NoSuchAlgorithmException nsa) 57 { 58 throw new RoutingException(event.getMessage(), event.getEndpoint(), nsa); 59 } 60 catch (TransformerException te) 61 { 62 throw new RoutingException(event.getMessage(), event.getEndpoint(), te); 63 } 64 } 65 } 66 | Popular Tags |