1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package no.sesat.search.util;
18
19 import java.security.MessageDigest;
20 import java.security.NoSuchAlgorithmException;
21 import java.util.UUID;
22 import javax.servlet.http.Cookie;
23 import javax.servlet.http.HttpServletRequest;
24 import org.apache.commons.codec.binary.Hex;
25
26
27
28
29
30
31
32
33 public final class TradeDoubler {
34
35 private final static String secretCode = "997";
36 private final static String organization = "1064392";
37 private final static String event = "46757";
38 private final HttpServletRequest request;
39
40 public TradeDoubler(HttpServletRequest request) {
41 this.request = request;
42 }
43
44 public String getChecksum(
45 final String orderNumber,
46 final String orderValue) throws RuntimeException {
47
48 MessageDigest digest = null;
49 try {
50 digest = MessageDigest.getInstance("MD5");
51 } catch(NoSuchAlgorithmException e) {
52 throw new RuntimeException(e.getMessage());
53 }
54 final String s = new String(TradeDoubler.getSecretCode() + orderNumber + orderValue);
55 digest.update(s.getBytes());
56 return new String(Hex.encodeHex(digest.digest()));
57 }
58
59 public String getUUID() {
60 return UUID.randomUUID().toString();
61 }
62
63 public static String getEvent() {
64 return event;
65 }
66
67 public static String getOrganization() {
68 return organization;
69 }
70
71 public static String getSecretCode() {
72 return secretCode;
73 }
74
75 public String getCookieTDUID() {
76 return getCookie("TRADEDOUBLER");
77 }
78
79 public String getCookieOrderNumber(){
80 return getCookie("TRADEDOUBLER-onr");
81 }
82
83 public String getCookieChecksum(){
84 return getCookie("TRADEDOUBLER-cs");
85 }
86
87 public String getCookieReportInfo(){
88 return getCookie("TRADEDOUBLER-ri");
89 }
90
91 private String getCookie(String name){
92 if (this.request == null){
93 return "";
94 }
95 String value = "";
96 final Cookie[] cookies = this.request.getCookies();
97 if (cookies != null){
98 for (int i = 0; i < cookies.length; i++) {
99 if (cookies[i].getName().equals(name)) {
100 if (cookies[i].getValue() != null) {
101 value = cookies[i].getValue();
102 }
103 }
104 }
105 }
106 return value;
107 }
108 }