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-config\dsm\src\main\java\org\nhindirect\gateway\smtp\james\mailet | DirectAPI.java | Tue Mar 12 21:52:12 2019 UTC |
| 2 | C:\AraxisMergeCompare\Pri_re\DSM-scrubbed\Direct Implementation\java\dsm-config\dsm\src\main\java\org\nhindirect\gateway\smtp\james\mailet | DirectAPI.java | Wed Mar 13 02:21:00 2019 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 272 |
| 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.Http URLConnect ion; | |
| 12 | import jav a.net.Malf ormedURLEx ception; | |
| 13 | import jav a.net.URL; | |
| 14 | import jav a.security .InvalidKe yException ; | |
| 15 | import jav a.security .NoSuchAlg orithmExce ption; | |
| 16 | import jav a.text.Sim pleDateFor mat; | |
| 17 | import jav a.util.Has hMap; | |
| 18 | import jav a.util.Map ; | |
| 19 | import jav a.util.Pro perties; | |
| 20 | import jav ax.crypto. Mac; | |
| 21 | import jav ax.crypto. spec.Secre tKeySpec; | |
| 22 | import org .apache.co mmons.logg ing.Log; | |
| 23 | import org .apache.co mmons.logg ing.LogFac tory; | |
| 24 | import org .json.simp le.JSONObj ect; | |
| 25 | ||
| 26 | /** | |
| 27 | * | |
| 28 | * @author Elan | |
| 29 | */ | |
| 30 | public cla ss DirectA PI { | |
| 31 | privat e static f inal Log L OGGER = Lo gFactory.g etFactory( ).getInsta nce( | |
| 32 | Direct API.class) ; | |
| 33 | public static bo olean post (String en dpoint, JS ONObject d ata, Strin g expected Response) { | |
| 34 | // Properties props = n ew Propert ies(); | |
| 35 | // props.putA ll(MailetP roperties. getPropert iesList()) ; | |
| 36 | bo olean rtc = false; | |
| 37 | Ht tpURLConne ction conn = null; | |
| 38 | Da taOutputSt ream ds = null; | |
| 39 | Ma p<String, String> pr ops = Mail etProperti es.getProp ertiesList (); | |
| 40 | tr y { | |
| 41 | URL url = new URL( "https://" + props.g et("direct .apiurl") + endpoint ); | |
| 42 | conn = ( HttpURLCon nection) u rl.openCon nection(); | |
| 43 | java.uti l.Date dt = new java .util.Date (); | |
| 44 | SimpleDa teFormat s df = new S impleDateF ormat("MM/ dd/yyyy HH :mm:ss z") ; | |
| 45 | String d str = sdf. format(dt) ; | |
| 46 | String r eqstr = "P OST\n" + d str + "\na pplication /json\n" + (endpoint ); | |
| 47 | Mac sha2 56_HMAC = Mac.getIns tance("Hma cSHA256"); | |
| 48 | SecretKe ySpec secr et_key = n ew SecretK eySpec(((S tring) pro ps.get("di rect.priva tekey")).g etBytes(), "HmacSHA2 56"); | |
| 49 | sha256_H MAC.init(s ecret_key) ; | |
| 50 | byte[] s ha = sha25 6_HMAC.doF inal(reqst r.getBytes ()); | |
| 51 | String e ncsha = ne w sun.misc .BASE64Enc oder().enc ode(sha); | |
| 52 | String a uth = "DAA S " + ((St ring) prop s.get("dir ect.public key")) + " :" + encsh a; | |
| 53 | conn.set RequestPro perty("Aut horization ", auth); | |
| 54 | conn.set RequestPro perty("Dat e", dstr); | |
| 55 | conn.set RequestPro perty("Con tent-Type" , "applica tion/json" ); | |
| 56 | conn.set RequestPro perty("Acc ept", "app lication/j son"); | |
| 57 | // Allow Inputs | |
| 58 | conn.set DoInput(tr ue); | |
| 59 | // Allow Outputs | |
| 60 | conn.set DoOutput(t rue); | |
| 61 | // Don't use a cac hed copy. | |
| 62 | conn.set UseCaches( false); | |
| 63 | // Use a post meth od. | |
| 64 | conn.set RequestMet hod("POST" ); | |
| 65 | try { | |
| 66 | ds = new DataO utputStrea m(conn.get OutputStre am()); | |
| 67 | ds.w rite(data. toString() .getBytes( "UTF-8")); | |
| 68 | ds.f lush(); | |
| 69 | ds.c lose(); | |
| 70 | } finall y { | |
| 71 | if ( ds != null ) { | |
| 72 | ds.close() ; | |
| 73 | } | |
| 74 | } | |
| 75 | ||
| 76 | //added the respon se message on failur e as well, because i t can help with debu gging pote ntially | |
| 77 | if (conn .getRespon seCode() ! = 200) { | |
| 78 | //De bugging co de in-case response 200 is not received | |
| 79 | //LO GGER.error ("DirectAP I: Failed : HTTP err or code : " + conn.g etResponse Code() + " . HTTP res ponse : " + conn.get ResponseMe ssage()); | |
| 80 | retu rn false; | |
| 81 | } | |
| 82 | tr y { | |
| 83 | fina l InputStr eamReader stream = n ew InputSt reamReader ((conn.get InputStrea m())); | |
| 84 | try { | |
| 85 | final BufferedRe ader br = new Buffer edReader(s tream); | |
| 86 | String output; | |
| 87 | String resp = "" ; | |
| 88 | while ((output = br.readLi ne()) != n ull) { | |
| 89 | resp += output; | |
| 90 | } | |
| 91 | LOGGER .info(resp ); | |
| 92 | if (re sp.indexOf ("\"messag e\":\"" + expectedRe sponse + " \"") >= 0) { | |
| 93 | rtc = tr ue; | |
| 94 | } | |
| 95 | } fi nally { | |
| 96 | if(str eam != nul l) { | |
| 97 | try { | |
| 98 | stream.clo se(); | |
| 99 | } catch (IOExcepti on e) { | |
| 100 | LOGGER.err or("Direct API: IO ex ception"); | |
| 101 | } | |
| 102 | } | |
| 103 | } | |
| 104 | } catch (IOE xception e ) { | |
| 105 | LOGG ER.error(" DirectAPI: IO except ion"); | |
| 106 | } | |
| 107 | } catch (NoS uchAlgorit hmExceptio n e) { | |
| 108 | LOGGER.e rror("Dire ctAPI: Hma cSHA256 al grithm was not found "); | |
| 109 | } catch (Inv alidKeyExc eption e) { | |
| 110 | LOGGER.e rror("Dire ctAPI: Sec ret Key is invalid") ; | |
| 111 | } catch (Mal formedURLE xception e ) { | |
| 112 | LOGGER.e rror("Dire ctAPI: mal formed url "); | |
| 113 | } catch (IOE xception e ) { | |
| 114 | LOGGER.e rror("Dire ctAPI: IO exception" ); | |
| 115 | } finally { | |
| 116 | if (conn != null) { | |
| 117 | conn .disconnec t(); | |
| 118 | } | |
| 119 | ||
| 120 | } | |
| 121 | ||
| 122 | re turn rtc; | |
| 123 | } | |
| 124 | ||
| 125 | /* publ ic static void main( String[] a rgs) { | |
| 126 | ||
| 127 | Ma p<String, String> pr ops = new HashMap<St ring, Stri ng>(); | |
| 128 | pr ops.put("d irect.publ ickey", "c a78dacc79b edc0ce2b45 4a20e75700 2f4ee09024 7740bdb366 d2d0d12816 a62"); | |
| 129 | pr ops.put("d irect.priv atekey", " f45b0257e3 d1a8ecefca 1ad724250a 5da63de01b ccc7a1804b 74a40c07fd 4c5c"); | |
| 130 | props.put( "direct.ap iurl", "ap i.dev.dire ct. DOMAIN . EXT "); | |
| 131 | JS ONObject j o = new JS ONObject() ; | |
| 132 | jo .put("mail box", "tau ser"); | |
| 133 | jo .put("id", "4"); | |
| 134 | // System.out .println(p ost(props, "/direct/ messages/p rocess_inc oming", jo , "Message was succe ssfully pr ocessed.") ); | |
| 135 | ||
| 136 | // 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)); | |
| 137 | }*/ | |
| 138 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.