3214. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/9/2017 3:49:58 PM Eastern 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.

3214.1 Files compared

# Location File Last Modified
1 Fri Jun 9 19:49:58 2017 UTC
2 eHealth_Exch (eHealth Exchange Enhancements) Build 3 docs & code_May_2017.zip\VAP_CIF_CODE0502.zip\VAP_CIF_CODE0502\VAP_CIF_CODE0502\nvap-common\src\main\java\gov\va\nvap\common\transceiver\client SocketTransceiver.java Fri Apr 21 20:03:26 2017 UTC

3214.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 0 0
Changed 0 0
Inserted 1 212
Removed 0 0

3214.3 Comparison options

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

3214.4 Active regular expressions

No regular expressions were active.

3214.5 Comparison detail

        1   package go v.va.nvap. common.tra nsceiver.c lient;
        2  
        3   import gov .va.nvap.c ommon.vali dation.Ass ert;
        4   import gov .va.nvap.c ommon.vali dation.Nul lChecker;
        5  
        6   import jav a.io.IOExc eption;
        7   import jav a.io.Input Stream;
        8   import jav a.io.Outpu tStream;
        9   import jav a.net.Inet SocketAddr ess;
        10   import jav a.net.Sock et;
        11   import jav a.net.Sock etTimeoutE xception;
        12   import jav a.net.Unkn ownHostExc eption;
        13  
        14   import org .apache.co mmons.logg ing.Log;
        15   import org .apache.co mmons.logg ing.LogFac tory;
        16   import org .springfra mework.bea ns.factory .annotatio n.Required ;
        17  
        18   /**
        19    * SocketT ransceiver .
        20    *
        21    * @author  Asha Amri traj
        22    */
        23   public abs tract clas s SocketTr ansceiver  implements  Transceiv er<String>
        24   {
        25       privat e static f inal int D EFAULT_BUF FER = 512;
        26       privat e static f inal int D EFAULT_TIM EOUT = 100 00;
        27       privat e static f inal Log L OG = LogFa ctory.getL og(SocketT ransceiver .class);
        28       privat e long end Time;
        29       privat e String h ost;
        30       privat e int port ;
        31       privat e int conn ectTimeout ;
        32           pr ivate int  readTimeou t;
        33       privat e int retr ies;
        34  
        35       protec ted Socket Transceive r()
        36       {
        37       }
        38  
        39       protec ted final  Socket con nect(int r etriesUsed ) {
        40                    fina l long sta rtTime = S ystem.curr entTimeMil lis();
        41                    this .setEndTim e(startTim e + this.r eadTimeout );
        42           fi nal Socket  socket =  new Socket ();
        43           tr y {
        44                final In etSocketAd dress isoc  = new Ine tSocketAdd ress(this. host, this .port);
        45                socket.s etSoTimeou t(this.rea dTimeout);
        46                             socket .connect(i soc, this. connectTim eout);
        47           }
        48           ca tch (final  UnknownHo stExceptio n e) {
        49                final St ring msg =  "Unable t o contact  remote hos t at addre ss "
        50                         + this.hos t + " and  port " + t his.port;
        51                throw ne w RuntimeE xception(m sg, e);
        52           }
        53           //  catch Soc ketTimeout Exception  for retrie s while co nnecting
        54           ca tch(final  SocketTime outExcepti on e) {
        55                if(retri esUsed < r etries) {
        56                    this .connect(r etriesUsed +1);
        57                }
        58                else {
        59                    fina l String m sg = "Exha usted " +  retriesUse d + " retr ies, unabl e to conta ct remote  host at ad dress "
        60                             + this .host + "  and port "  + this.po rt;
        61                    LOG. warn(msg);
        62                    thro w new Runt imeExcepti on(msg, e) ;
        63                }
        64           }
        65           // catches ot her IOExce ptions, li ke Connect ionExcepti on (Connec tion refus ed)
        66           ca tch (final  IOExcepti on e) {
        67                final St ring msg =  "Unable t o contact  remote hos t at addre ss "
        68                         + this.hos t + " and  port " + t his.port;
        69                throw ne w RuntimeE xception(m sg, e);
        70           }
        71           re turn socke t;
        72       }
        73  
        74       privat e void dis connect(fi nal Socket  socket)
        75       {
        76           if  (!NullChe cker.isEmp ty(socket) ) {
        77                try {
        78                    if ( socket.isC onnected()  && !socke t.isClosed ()) {
        79                         final Inpu tStream is  = socket. getInputSt ream();
        80                         final Outp utStream o s = socket .getOutput Stream();
        81  
        82                         if (NullCh ecker.isNo tEmpty(is) ) {
        83                             is.clo se();
        84                         }
        85                         if (NullCh ecker.isNo tEmpty(os) ) {
        86                             os.clo se();
        87                         }
        88                         if (NullCh ecker.isNo tEmpty(soc ket)) {
        89                             socket .close();
        90                         }
        91                    }
        92                }
        93                catch (f inal IOExc eption e)  {
        94                    // D o Nothing.
        95                    Sock etTranscei ver.LOG.wa rn("Except ion in dis connect",  e);
        96                }
        97           }
        98       }
        99  
        100       protec ted abstra ct String  formatInco mingMessag e(String p ayload);
        101  
        102       protec ted abstra ct String  formatOutg oingMessag e(String p ayload);
        103  
        104       protec ted abstra ct String  getEndMark er();
        105  
        106       protec ted abstra ct int get EndMarkerP osition();
        107  
        108       privat e InputStr eam getInp utStream(f inal Socke t socket)  throws IOE xception
        109       {
        110           As sert.asser tNotEmpty( socket, "S ocket cann ot be null !");
        111           As sert.asser tFalse(soc ket.isClos ed(), "Tra ncseiver i s not conn ected.");
        112           re turn socke t.getInput Stream();
        113       }
        114  
        115       privat e OutputSt ream getOu tputStream (final Soc ket socket ) throws I OException
        116       {
        117           As sert.asser tNotEmpty( socket, "S ocket cann ot be null !");
        118           As sert.asser tFalse(soc ket.isClos ed(), "Tra ncseiver i s not conn ected.");
        119           re turn socke t.getOutpu tStream();
        120       }
        121  
        122       privat e String r eceive(fin al Socket  socket, fi nal String  endMarker ) throws I OException , SocketTi meoutExcep tion
        123       {
        124           As sert.asser tNotEmpty( socket, "S ocket cann ot be null !");
        125           As sert.asser tFalse(soc ket.isClos ed(), "Tra ncseiver i s not conn ected.");
        126  
        127           fi nal String Buffer buf fer = new  StringBuff er();
        128           //  final Inp utStreamRe ader reade r = new In putStreamR eader(this
        129           //  .getInput Stream(soc ket));
        130           in t i = 0;
        131           fi nal byte[]  arr = new  byte[Sock etTranscei ver.DEFAUL T_BUFFER];
        132           In putStream  in = getIn putStream( socket);
        133                while (( i != -1)
        134                         && (buffer .indexOf(e ndMarker)  < this.get EndMarkerP osition()) ) {
        135                    i =  in.read(ar r, 0, arr. length);
        136                    if ( i > 0) {
        137                         for (int j  = 0; j <  i; j++) {
        138                             buffer .append((c har) arr[j ]);
        139                         }
        140                    }
        141                    Asse rt.assertF alse(Syste m.currentT imeMillis( ) > this.e ndTime,
        142                             "Recei ve operati on timed o ut.");
        143                }
        144           re turn buffe r.toString ();
        145       }
        146  
        147       privat e void sen d(final So cket socke t, final S tring data ) throws I OException
        148       {
        149           As sert.asser tNotEmpty( socket, "S ocket cann ot be null !");
        150           As sert.asser tFalse(soc ket.isClos ed(), "Tra ncseiver i s not conn ected.");
        151           Ou tputStream  out = get OutputStre am(socket) ;
        152           ou t.write(da ta.getByte s());
        153           ou t.flush();
        154           As sert.asser tTrue(Syst em.current TimeMillis () <= this .endTime,
        155                    "Sen d operatio n timed ou t.");
        156       }
        157  
        158       privat e void set EndTime(fi nal long v alue)
        159       {
        160           th is.endTime  = value;
        161       }
        162  
        163       @Requi red
        164       public  final voi d setHost( final Stri ng theHost )
        165       {
        166           th is.host =  theHost;
        167       }
        168  
        169       @Requi red
        170       public  final voi d setPort( final int  thePort)
        171       {
        172           th is.port =  thePort;
        173       }
        174  
        175       @Requi red
        176           pu blic final  void setR eadTimeout (final int  theReadTi meout) {
        177                    this .readTimeo ut = theRe adTimeout;
        178           }
        179  
        180           @R equired
        181           pu blic final  void setC onnectTime out(final  int theCon nectTimeou t) {
        182                    this .connectTi meout = th eConnectTi meout;
        183           }
        184  
        185           @R equired
        186           pu blic final  void setR etries(fin al int the Retries) {
        187                    this .retries =  theRetrie s;
        188           }
        189  
        190       @Overr ide
        191       public  final Str ing transc eive(final  String pa yload)
        192       {
        193           St ring ret =  null;
        194           So cket socke t = null;
        195           tr y {
        196                // Conne ct
        197                socket =  this.conn ect(0);
        198                Assert.a ssertNotEm pty(socket , "Socket  cannot be  null!");
        199                // Send  - format o utgoing
        200                this.sen d(socket,  this.forma tOutgoingM essage(pay load));
        201                // Recei ve and for mat incomi ng
        202                ret = th is.formatI ncomingMes sage(this. receive(so cket, this .getEndMar ker()));
        203           }
        204           ca tch (IOExc eption ioe ) {
        205  
        206           }
        207           fi nally {
        208                this.dis connect(so cket);
        209           }
        210           re turn ret;
        211       }
        212   }