Produced by Araxis Merge on 3/13/2019 2:49:39 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | C:\AraxisMergeCompare\Pri_un\DSM\Direct Implementation\java\dsm\src\main\java\org\nhindirect\gateway\smtp\james\mailet | DirectAPI.java | Tue Mar 12 21:55:28 2019 UTC |
| 2 | C:\AraxisMergeCompare\Pri_re\DSM-scrubbed\Direct Implementation\java\dsm\src\main\java\org\nhindirect\gateway\smtp\james\mailet | DirectAPI.java | Wed Mar 13 02:20:16 2019 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 324 |
| Changed | 2 | 4 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | /* | |
| 2 | * To chan ge this te mplate, ch oose Tools | Templat es | |
| 3 | * and ope n the temp late in th e editor. | |
| 4 | */ | |
| 5 | package or g.nhindire ct.gateway .smtp.jame s.mailet; | |
| 6 | ||
| 7 | import jav a.io.Buffe redReader; | |
| 8 | import jav a.io.DataO utputStrea m; | |
| 9 | import jav a.io.IOExc eption; | |
| 10 | import jav a.io.Input StreamRead er; | |
| 11 | import jav a.net.Malf ormedURLEx ception; | |
| 12 | import jav a.net.URL; | |
| 13 | import jav a.security .InvalidKe yException ; | |
| 14 | import jav a.security .KeyManage mentExcept ion; | |
| 15 | import jav a.security .NoSuchAlg orithmExce ption; | |
| 16 | import jav a.text.Sim pleDateFor mat; | |
| 17 | import jav a.util.Map ; | |
| 18 | ||
| 19 | import jav ax.crypto. Mac; | |
| 20 | import jav ax.crypto. spec.Secre tKeySpec; | |
| 21 | import jav ax.net.ssl .HttpsURLC onnection; | |
| 22 | import jav ax.net.ssl .SSLContex t; | |
| 23 | ||
| 24 | import org .apache.co mmons.logg ing.Log; | |
| 25 | import org .apache.co mmons.logg ing.LogFac tory; | |
| 26 | import org .json.simp le.JSONObj ect; | |
| 27 | ||
| 28 | /** | |
| 29 | * | |
| 30 | * @author Elan | |
| 31 | */ | |
| 32 | public cla ss DirectA PI { | |
| 33 | privat e static f inal Log L OGGER = Lo gFactory.g etFactory( ).getInsta nce( | |
| 34 | Direct API.class) ; | |
| 35 | public static bo olean post (String en dpoint, JS ONObject d ata, Strin g expected Response) { | |
| 36 | // Properties props = n ew Propert ies(); | |
| 37 | // props.putA ll(MailetP roperties. getPropert iesList()) ; | |
| 38 | bo olean rtc = false; | |
| 39 | Ht tpsURLConn ection con n = null; | |
| 40 | Da taOutputSt ream ds = null; | |
| 41 | Ma p<String, String> pr ops = Mail etProperti es.getProp ertiesList (); | |
| 42 | tr y { | |
| 43 | URL url = new URL( "https://" + props.g et("direct .apiurl") + endpoint ); | |
| 44 | // Added an SSLCon text to fo rce at lea st TLS 1.1 complianc e. If 1.1 does not work, we c an go to 1 .2 | |
| 45 | String t lsVersion = props.ge t("mailet. tls.versio n"); | |
| 46 | if (tlsV ersion == null || tl sVersion.i sEmpty()) { | |
| 47 | tlsV ersion = " TLSv1.1"; | |
| 48 | } | |
| 49 | SSLConte xt sctx = SSLContext .getInstan ce(tlsVers ion); | |
| 50 | sctx.ini t(null, nu ll, new ja va.securit y.SecureRa ndom()); | |
| 51 | conn = ( HttpsURLCo nnection) url.openCo nnection() ; | |
| 52 | java.uti l.Date dt = new java .util.Date (); | |
| 53 | SimpleDa teFormat s df = new S impleDateF ormat("MM/ dd/yyyy HH :mm:ss z") ; | |
| 54 | String d str = sdf. format(dt) ; | |
| 55 | String r eqstr = "P OST\n" + d str + "\na pplication /json\n" + (endpoint ); | |
| 56 | Mac sha2 56_HMAC = Mac.getIns tance("Hma cSHA256"); | |
| 57 | SecretKe ySpec secr et_key = n ew SecretK eySpec(((S tring) pro ps.get("di rect.priva tekey")).g etBytes(), "HmacSHA2 56"); | |
| 58 | sha256_H MAC.init(s ecret_key) ; | |
| 59 | byte[] s ha = sha25 6_HMAC.doF inal(reqst r.getBytes ()); | |
| 60 | String e ncsha = ne w sun.misc .BASE64Enc oder().enc ode(sha); | |
| 61 | String a uth = "DAA S " + ((St ring) prop s.get("dir ect.public key")) + " :" + encsh a; | |
| 62 | conn.set RequestPro perty("Aut horization ", auth); | |
| 63 | conn.set RequestPro perty("Dat e", dstr); | |
| 64 | conn.set RequestPro perty("Con tent-Type" , "applica tion/json" ); | |
| 65 | conn.set RequestPro perty("Acc ept", "app lication/j son"); | |
| 66 | // Allow Inputs | |
| 67 | conn.set DoInput(tr ue); | |
| 68 | // Allow Outputs | |
| 69 | conn.set DoOutput(t rue); | |
| 70 | // Don't use a cac hed copy. | |
| 71 | conn.set UseCaches( false); | |
| 72 | // Use a post meth od. | |
| 73 | conn.set RequestMet hod("POST" ); | |
| 74 | conn.set SSLSocketF actory(sct x.getSocke tFactory() ); | |
| 75 | try { | |
| 76 | ds = new DataO utputStrea m(conn.get OutputStre am()); | |
| 77 | ds.w rite(data. toString() .getBytes( "UTF-8")); | |
| 78 | ds.f lush(); | |
| 79 | ds.c lose(); | |
| 80 | } finall y { | |
| 81 | if ( ds != null ) { | |
| 82 | ds.close() ; | |
| 83 | } | |
| 84 | } | |
| 85 | ||
| 86 | //added the respon se message on failur e as well, because i t can help with debu gging pote ntially | |
| 87 | if (conn .getRespon seCode() ! = 200) { | |
| 88 | //De bugging co de in-case response 200 is not received | |
| 89 | //LO GGER.error ("DirectAP I: Failed : HTTP err or code : " + conn.g etResponse Code() + " . HTTP res ponse : " + conn.get ResponseMe ssage()); | |
| 90 | retu rn false; | |
| 91 | } | |
| 92 | tr y { | |
| 93 | fina l InputStr eamReader stream = n ew InputSt reamReader ((conn.get InputStrea m())); | |
| 94 | try { | |
| 95 | final BufferedRe ader br = new Buffer edReader(s tream); | |
| 96 | String output; | |
| 97 | String resp = "" ; | |
| 98 | while ((output = br.readLi ne()) != n ull) { | |
| 99 | resp += output; | |
| 100 | } | |
| 101 | LOGGER .info(resp ); | |
| 102 | if (re sp.indexOf ("\"messag e\":\"" + expectedRe sponse + " \"") >= 0) { | |
| 103 | rtc = tr ue; | |
| 104 | } | |
| 105 | } fi nally { | |
| 106 | if(str eam != nul l) { | |
| 107 | try { | |
| 108 | stream.clo se(); | |
| 109 | } catch (IOExcepti on e) { | |
| 110 | LOGGER.err or("Direct API: IO ex ception"); | |
| 111 | St ackTraceEl ement[] el ems = e.ge tStackTrac e(); | |
| 112 | fo r(StackTra ceElement el : elems ) { | |
| 113 | LOGGER.d ebug("Dire ctAPI:" + el.toStrin g()); | |
| 114 | } | |
| 115 | ||
| 116 | } | |
| 117 | } | |
| 118 | } | |
| 119 | } catch (IOE xception e ) { | |
| 120 | LOGG ER.error(" DirectAPI: IO except ion"); | |
| 121 | } | |
| 122 | } catch (Key Management Exception e) { | |
| 123 | LOGG ER.error(" DirectAPI: Key Manag ement Exce ption"); | |
| 124 | StackTra ceElement[ ] elems = e.getStack Trace(); | |
| 125 | for(Stac kTraceElem ent el : e lems) { | |
| 126 | LOGG ER.debug(" DirectAPI: " + el.toS tring()); | |
| 127 | } | |
| 128 | ||
| 129 | } catch (NoS uchAlgorit hmExceptio n e) { | |
| 130 | LOGGER.e rror("Dire ctAPI: Hma cSHA256 al grithm was not found "); | |
| 131 | } catch (Inv alidKeyExc eption e) { | |
| 132 | LOGGER.e rror("Dire ctAPI: Sec ret Key is invalid") ; | |
| 133 | } catch (Mal formedURLE xception e ) { | |
| 134 | LOGGER.e rror("Dire ctAPI: mal formed url "); | |
| 135 | } catch (IOE xception e ) { | |
| 136 | LOGGER.e rror("Dire ctAPI: IO exception" ); | |
| 137 | StackTra ceElement[ ] elems = e.getStack Trace(); | |
| 138 | for(Stac kTraceElem ent el : e lems) { | |
| 139 | LOGG ER.debug(" DirectAPI: " + el.toS tring()); | |
| 140 | } | |
| 141 | } fi nally { | |
| 142 | if (conn != null) { | |
| 143 | conn .disconnec t(); | |
| 144 | } | |
| 145 | ||
| 146 | } | |
| 147 | ||
| 148 | re turn rtc; | |
| 149 | } | |
| 150 | ||
| 151 | /* publ ic static void main( String[] a rgs) { | |
| 152 | ||
| 153 | Ma p<String, String> pr ops = new HashMap<St ring, Stri ng>(); | |
| 154 | pr ops.put("d irect.publ ickey", "c a78dacc79b edc0ce2b45 4a20e75700 2f4ee09024 7740bdb366 d2d0d12816 a62"); | |
| 155 | pr ops.put("d irect.priv atekey", " f45b0257e3 d1a8ecefca 1ad724250a 5da63de01b ccc7a1804b 74a40c07fd 4c5c"); | |
| 156 | props.put( "direct.ap iurl", "ap i.dev.dire ct. DOMAIN . EXT "); | |
| 157 | JS ONObject j o = new JS ONObject() ; | |
| 158 | jo .put("mail box", "tau ser"); | |
| 159 | jo .put("id", "4"); | |
| 160 | // System.out .println(p ost(props, "/direct/ messages/p rocess_inc oming", jo , "Message was succe ssfully pr ocessed.") ); | |
| 161 | ||
| 162 | // System. out.printl n("send ta user@test. direct. DOMAIN . EXT : " + test .send("tau ser@test.d irect. DOMAIN . EXT ", "tauser @test.dire ct. DOMAIN . EXT ", "", "", "", "Test subject", "Test bod y", null, props)); | |
| 163 | }*/ | |
| 164 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.