Produced by Araxis Merge on 5/25/2018 9:21:42 AM 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\ZIP\DSM-cif\Direct Implementation\java\direct-msg-monitor\src\main\java\org\nhindirect\monitor\processor | DSNMailSender.java | Tue May 22 13:40:34 2018 UTC |
| 2 | C:\AraxisMergeCompare\Pri_re\ZIP\DSM-cif\Direct Implementation\java\direct-msg-monitor\src\main\java\org\nhindirect\monitor\processor | DSNMailSender.java | Wed May 23 16:53:06 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 2 | 360 |
| Changed | 1 | 2 |
| 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 | Copyright (c) 2010, NHIN Direc t Project | |
| 3 | All rights reserved. | |
| 4 | ||
| 5 | Authors: | |
| 6 | Greg Me yer g m2552@cern er.com | |
| 7 | ||
| 8 | Redistribu tion and u se in sour ce and bin ary forms, with or w ithout mod ification, are permi tted provi ded that t he followi ng conditi ons are me t: | |
| 9 | ||
| 10 | Redistribu tions of s ource code must reta in the abo ve copyrig ht notice, this list of condit ions and t he followi ng disclai mer. | |
| 11 | Redistribu tions in b inary form must repr oduce the above copy right noti ce, this l ist of con ditions an d the foll owing disc laimer | |
| 12 | in the doc umentation and/or ot her materi als provid ed with th e distribu tion. Nei ther the n ame of the The NHIN Direct Pro ject (nhin direct.org ). | |
| 13 | nor the na mes of its contribut ors may be used to e ndorse or promote pr oducts der ived from this softw are withou t specific prior wri tten permi ssion. | |
| 14 | THIS SOFTW ARE IS PRO VIDED BY T HE COPYRIG HT HOLDERS AND CONTR IBUTORS "A S IS" AND ANY EXPRES S OR IMPLI ED WARRANT IES, INCLU DING, BUT NOT LIMITE D TO, | |
| 15 | THE IMPLIE D WARRANTI ES OF MERC HANTABILIT Y AND FITN ESS FOR A PARTICULAR PURPOSE A RE DISCLAI MED. IN NO EVENT SHA LL THE COP YRIGHT HOL DER OR CON TRIBUTORS | |
| 16 | BE LIABLE FOR ANY DI RECT, INDI RECT, INCI DENTAL, SP ECIAL, EXE MPLARY, OR CONSEQUEN TIAL DAMAG ES (INCLUD ING, BUT N OT LIMITED TO, PROCU REMENT OF SUBSTITUTE | |
| 17 | GOODS OR S ERVICES; L OSS OF USE , DATA, OR PROFITS; OR BUSINES S INTERRUP TION) HOWE VER CAUSED AND ON AN Y THEORY O F LIABILIT Y, WHETHER IN CONTRA CT, | |
| 18 | STRICT LIA BILITY, OR TORT (INC LUDING NEG LIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF TH E USE OF T HIS SOFTWA RE, EVEN I F ADVISED OF | |
| 19 | THE POSSIB ILITY OF S UCH DAMAGE . | |
| 20 | */ | |
| 21 | ||
| 22 | package or g.nhindire ct.monitor .processor ; | |
| 23 | ||
| 24 | import jav a.io.ByteA rrayOutput Stream; | |
| 25 | import jav a.io.IOExc eption; | |
| 26 | import jav a.io.Write r; | |
| 27 | import jav a.net.Inet Address; | |
| 28 | import jav a.net.URI; | |
| 29 | import jav a.net.URIS yntaxExcep tion; | |
| 30 | ||
| 31 | import jav ax.mail.in ternet.Mim eMessage; | |
| 32 | ||
| 33 | import org .apache.ca mel.Exchan ge; | |
| 34 | import org .apache.ca mel.Handle r; | |
| 35 | import org .apache.co mmons.io.I OUtils; | |
| 36 | import org .apache.co mmons.net. smtp.SMTPC lient; | |
| 37 | import org .nhindirec t.common.m ail.MailSt andard; | |
| 38 | ||
| 39 | /** | |
| 40 | * Camel p rocessor f or sending DSN messa ges via an SMTP gate way. Mess ages in th e incoming exchange are expect ed to be o f type | |
| 41 | * MimeMes sage | |
| 42 | * @author Greg Meye r | |
| 43 | * @since 1.0 | |
| 44 | */ | |
| 45 | public cla ss DSNMail Sender | |
| 46 | { | |
| 47 | pr otected st atic final int SMTP_ OK = 250; | |
| 48 | ||
| 49 | pr otected SM TPClientFa ctory clie ntFactory; | |
| 50 | ||
| 51 | pr otected St ring gatew ayHost; | |
| 52 | pr otected in t gatewayP ort = PORT ; | |
| 53 | pr otected St ring local host = "lo calhost"; | |
| 54 | ||
| 55 | /* * | |
| 56 | * Empty con structor | |
| 57 | * / | |
| 58 | pu blic DSNMa ilSender() | |
| 59 | { | |
| 60 | try | |
| 61 | { | |
| 62 | localh ost = Inet Address.ge tLocalHost ().getHost Name(); | |
| 63 | } | |
| 64 | catc h (Excepti on e) | |
| 65 | { | |
| 66 | ||
| 67 | } | |
| 68 | } | |
| 69 | ||
| 70 | /* * | |
| 71 | * Construct or | |
| 72 | * @param ga tewayURL T he URL of the SMTP g ateway | |
| 73 | * @param cl ientFactor y Client f actory for generatin g SMTPClie nt objects | |
| 74 | * / | |
| 75 | pu blic DSNMa ilSender(S tring gate wayURL, SM TPClientFa ctory clie ntFactory) | |
| 76 | { | |
| 77 | this (); | |
| 78 | setS MTPClientF actory(cli entFactory ); | |
| 79 | setG atewayURL( gatewayURL ); | |
| 80 | ||
| 81 | } | |
| 82 | ||
| 83 | /* * | |
| 84 | * Sets the SMTP gatew ay factory | |
| 85 | * @param cl ientFactor y The fact ory object | |
| 86 | * / | |
| 87 | pu blic void setSMTPCli entFactory (SMTPClien tFactory c lientFacto ry) | |
| 88 | { | |
| 89 | this .clientFac tory = cli entFactory ; | |
| 90 | } | |
| 91 | ||
| 92 | /* * | |
| 93 | * Sets the SMTP gatew ay URL (ex : smtp://m ailserver. domain.com :25). If the port i s not spec ified, the n | |
| 94 | * 25 is ass umed. | |
| 95 | * @param ga tewayURL T he SMTP ga teway URL | |
| 96 | * / | |
| 97 | pu blic void setGateway URL(String gatewayUR L) | |
| 98 | { | |
| 99 | try | |
| 100 | { | |
| 101 | final URI gatewa y = new UR I(gatewayU RL); | |
| 102 | if (ga teway.getP ort() > 0) | |
| 103 | gatewayP ort = gate way.getPor t(); | |
| 104 | ||
| 105 | gatewa yHost = ga teway.getH ost(); | |
| 106 | } | |
| 107 | catc h (URISynt axExceptio n e) | |
| 108 | { | |
| 109 | throw new Illega lArgumentE xception(" Invalid ga teway URL. ", e); | |
| 110 | } | |
| 111 | } | |
| 112 | ||
| 113 | /* * | |
| 114 | * Processor handler m ethod. Th is method sends the message to SMTP gate way specif ied in the gateway U RL. | |
| 115 | * The SMTP to and fro m headers and taken from the a ctual mess age. | |
| 116 | * @param ex change The exchange that holds the messa ge. | |
| 117 | * @throws E xception | |
| 118 | * / | |
| 119 | @Handl er | |
| 120 | public void send Mail(Excha nge exchan ge) throws Exception | |
| 121 | { | |
| 122 | if (gatewayH ost == nul l || gatew ayHost.isE mpty()) | |
| 123 | thro w new Ille galStateEx ception("G ateway URL is null o r empty"); | |
| 124 | ||
| 125 | // simple SM TP convera tion | |
| 126 | if (clientFa ctory == n ull) | |
| 127 | thro w new Ille galStateEx ception("S MTP client cannot be null"); | |
| 128 | ||
| 129 | if (exchange .getIn() = = null || exchange.g etIn().get Body() == null) | |
| 130 | retu rn; | |
| 131 | ||
| 132 | fi nal MimeMe ssage dsnM essage = ( MimeMessag e)exchange .getIn().g etBody(); | |
| 133 | fi nal String recpList = dsnMessa ge.getHead er(MailSta ndard.Head ers.To, ", "); | |
| 134 | fi nal String sender = dsnMessage .getHeader (MailStand ard.Header s.From, ", "); | |
| 135 | ||
| 136 | SM TPClient c lient = cl ientFactor y.createIn stance(); | |
| 137 | cl ient.conne ct(gateway Host, gate wayPort); | |
| 138 | cl ient.helo( localhost) ; | |
| 139 | ||
| 140 | ||
| 141 | if (!client. setSender( sender)) | |
| 142 | thro w new IOEx ception("F ailed to s et sender. "); | |
| 143 | ||
| 144 | fi nal String [] recips = recpList .split("," ); | |
| 145 | fo r (String recip : re cips) | |
| 146 | { | |
| 147 | if ( !client. a ddRecipien t(recip)) | |
| 148 | throw new IOExce ption("Fai led to set recipient " + recip ); | |
| 149 | } | |
| 150 | ||
| 151 | fi nal Writer writer = client.sen dMessageDa ta(); | |
| 152 | ||
| 153 | if (writer = = null) | |
| 154 | thro w new IOEx ception("F ailed to g et data bo dy writer. "); | |
| 155 | ||
| 156 | ||
| 157 | fi nal ByteAr rayOutputS tream writ erStream = new ByteA rrayOutput Stream(); | |
| 158 | ||
| 159 | tr y | |
| 160 | { | |
| 161 | dsnM essage.wri teTo(write rStream); | |
| 162 | ||
| 163 | IOUt ils.write( writerStre am.toByteA rray(), wr iter); | |
| 164 | ||
| 165 | writ er.close() ; | |
| 166 | ||
| 167 | clie nt.complet ePendingCo mmand(); | |
| 168 | ||
| 169 | if ( client.get ReplyCode( ) != SMTP_ OK) | |
| 170 | throw new IOExce ption("Fai led comple te data co mmand with error cod e " + clie nt.getRepl yCode()); | |
| 171 | } | |
| 172 | fi nally | |
| 173 | { | |
| 174 | IOUt ils.closeQ uietly(wri terStream) ; | |
| 175 | IOUt ils.closeQ uietly(wri ter); | |
| 176 | ||
| 177 | clie nt.quit(); | |
| 178 | clie nt.disconn ect(); | |
| 179 | } | |
| 180 | } | |
| 181 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.