1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.cache.keygenerator; |
8 | |
|
9 | |
import org.mule.api.MuleEvent; |
10 | |
|
11 | |
import java.io.NotSerializableException; |
12 | |
import java.io.Serializable; |
13 | |
import java.security.MessageDigest; |
14 | |
|
15 | |
import org.apache.commons.logging.Log; |
16 | |
import org.apache.commons.logging.LogFactory; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | 0 | public class MD5KeyGenerator implements KeyGenerator |
23 | |
{ |
24 | |
|
25 | 0 | protected Log logger = LogFactory.getLog(getClass()); |
26 | |
|
27 | |
public Serializable generateKey(MuleEvent event) throws NotSerializableException |
28 | |
{ |
29 | |
try |
30 | |
{ |
31 | 0 | byte[] bytesOfMessage = event.getMessageAsBytes(); |
32 | 0 | MessageDigest md = MessageDigest.getInstance("MD5"); |
33 | 0 | String key = new String(md.digest(bytesOfMessage)); |
34 | |
|
35 | 0 | if (logger.isDebugEnabled()) |
36 | |
{ |
37 | 0 | logger.debug("Generated key for event: " + event + " key: " + key); |
38 | |
} |
39 | |
|
40 | 0 | return key; |
41 | |
} |
42 | 0 | catch (Exception e) |
43 | |
{ |
44 | 0 | NotSerializableException notSerializableException = new NotSerializableException(e.getMessage()); |
45 | 0 | notSerializableException.initCause(e); |
46 | |
|
47 | 0 | throw notSerializableException; |
48 | |
} |
49 | |
} |
50 | |
} |