Produced by Araxis Merge on 6/9/2017 3:51:15 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.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | Fri Jun 9 19:51:15 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-server\src\test\java\gov\va\nvap\server\test\endpoint\th\mpi | MockSocketServer.java | Fri Apr 21 20:03:30 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 1 | 162 |
| 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 | package go v.va.nvap. server.tes t.endpoint .th.mpi; | |||||
| 2 | ||||||
| 3 | import gov .va.nvap.m ock.endpoi nt.mvi.Moc kSocketTra nsceiver; | |||||
| 4 | ||||||
| 5 | import jav a.io.Buffe redReader; | |||||
| 6 | import jav a.io.Buffe redWriter; | |||||
| 7 | import jav a.io.IOExc eption; | |||||
| 8 | import jav a.io.Input StreamRead er; | |||||
| 9 | import jav a.io.Outpu tStreamWri ter; | |||||
| 10 | import jav a.net.Serv erSocket; | |||||
| 11 | import jav a.net.Sock et; | |||||
| 12 | ||||||
| 13 | import org .apache.co mmons.logg ing.Log; | |||||
| 14 | import org .apache.co mmons.logg ing.LogFac tory; | |||||
| 15 | ||||||
| 16 | /** | |||||
| 17 | * Mock MP I Socket T ransceiver | |||||
| 18 | * | |||||
| 19 | * @author Asha Amri traj | |||||
| 20 | */ | |||||
| 21 | public cla ss MockSoc ketServer implements Runnable { | |||||
| 22 | ||||||
| 23 | /* * ASCII co de for car riage retu rn. */ | |||||
| 24 | pr ivate stat ic final b yte CR = 0 x0D; | |||||
| 25 | ||||||
| 26 | /* * End of b lock byte definition . */ | |||||
| 27 | pr ivate stat ic final b yte EOB = 0x1C; | |||||
| 28 | ||||||
| 29 | pr ivate stat ic final L og log = L ogFactory. getLog(Moc kSocketSer ver.class) ; | |||||
| 30 | ||||||
| 31 | pr ivate stat ic final b yte SOB = 0x0B; | |||||
| 32 | ||||||
| 33 | pu blic stati c void mai n(final St ring[] arg s) { | |||||
| 34 | try { | |||||
| 35 | final ServerSock et serverS ocket = ne w ServerSo cket(5001) ; | |||||
| 36 | Socket clientSoc ket = null ; | |||||
| 37 | while (true) { | |||||
| 38 | try { | |||||
| 39 | clientSock et = serve rSocket.ac cept(); | |||||
| 40 | final Mock SocketServ er clientS ocketServe r = new Mo ckSocketSe rver(); | |||||
| 41 | clientSock etServer.s etClientSo cket(clien tSocket); | |||||
| 42 | final Thre ad newThre ad = new T hread(clie ntSocketSe rver); | |||||
| 43 | newThread. start(); | |||||
| 44 | MockSocket Server.log .error("Mo ckSocketSe rver start ed..."); | |||||
| 45 | } catch (final IOE xception e ) { | |||||
| 46 | throw new RuntimeExc eption(e); | |||||
| 47 | } | |||||
| 48 | } | |||||
| 49 | ||||||
| 50 | } ca tch (final IOExcepti on e) { | |||||
| 51 | throw new Runtim eException (e); | |||||
| 52 | } | |||||
| 53 | ||||||
| 54 | } | |||||
| 55 | ||||||
| 56 | pr ivate Buff eredReader reader; | |||||
| 57 | pr ivate Sock et socket; | |||||
| 58 | pr ivate bool ean stop = false; | |||||
| 59 | ||||||
| 60 | pr ivate Buff eredWriter writer; | |||||
| 61 | ||||||
| 62 | pu blic MockS ocketServe r() { | |||||
| 63 | } | |||||
| 64 | ||||||
| 65 | pu blic Strin g formatOu tgoing(fin al String msg) { | |||||
| 66 | fina l StringBu ffer buf = new Strin gBuffer(); | |||||
| 67 | buf. append((ch ar) MockSo cketServer .SOB); | |||||
| 68 | buf. append(msg ); | |||||
| 69 | buf. append((ch ar) MockSo cketServer .CR); | |||||
| 70 | buf. append((ch ar) MockSo cketServer .EOB); | |||||
| 71 | buf. append((ch ar) MockSo cketServer .CR); | |||||
| 72 | buf. append((ch ar) MockSo cketServer .CR); | |||||
| 73 | ||||||
| 74 | retu rn buf.toS tring(); | |||||
| 75 | } | |||||
| 76 | ||||||
| 77 | pu blic Strin g getNextM essage(fin al Buffere dReader re ader) { | |||||
| 78 | try { | |||||
| 79 | final char[] buf fer = new char[2048] ; | |||||
| 80 | final int len = reader.rea d(buffer, 0, buffer. length); | |||||
| 81 | if (le n > 0) { | |||||
| 82 | return n ew String( buffer, 0, len); | |||||
| 83 | } else { | |||||
| 84 | return n ull; | |||||
| 85 | } | |||||
| 86 | } ca tch (final IOExcepti on ex) { | |||||
| 87 | throw new Runtim eException (ex); | |||||
| 88 | } | |||||
| 89 | } | |||||
| 90 | ||||||
| 91 | pu blic boole an quit() { | |||||
| 92 | retu rn false; | |||||
| 93 | } | |||||
| 94 | ||||||
| 95 | @O verride | |||||
| 96 | pu blic void run() { | |||||
| 97 | try { | |||||
| 98 | ||||||
| 99 | if ((t his.reader == null) && (this.s ocket != n ull)) { | |||||
| 100 | this.rea der = new BufferedRe ader(new I nputStream Reader( | |||||
| 101 | th is.socket. getInputSt ream())); | |||||
| 102 | this.wri ter = new BufferedWr iter(new O utputStrea mWriter( | |||||
| 103 | th is.socket. getOutputS tream())); | |||||
| 104 | } | |||||
| 105 | } ca tch (final IOExcepti on ex) { | |||||
| 106 | MockSo cketServer .log.error ("MockSock etServer f ailed " | |||||
| 107 | + Thread.c urrentThre ad().getNa me() + " " + ex); | |||||
| 108 | MockSo cketServer .log.error ("Exiting " | |||||
| 109 | + Thread.c urrentThre ad().getNa me()); | |||||
| 110 | return ; | |||||
| 111 | } | |||||
| 112 | ||||||
| 113 | whil e (!this.s top) { | |||||
| 114 | try { | |||||
| 115 | final St ring reque st = this. getNextMes sage(this. reader); | |||||
| 116 | if (requ est == nul l) { | |||||
| 117 | try { | |||||
| 118 | Th read.sleep (5000); | |||||
| 119 | } catch (f inal Inter ruptedExce ption ex) { | |||||
| 120 | } | |||||
| 121 | continue; | |||||
| 122 | } | |||||
| 123 | ||||||
| 124 | String r esponse = (String) t his.transc eive(reque st); | |||||
| 125 | if (resp onse != nu ll) { | |||||
| 126 | response = this.form atOutgoing (response) ; | |||||
| 127 | this.write r.write(re sponse); | |||||
| 128 | this.write r.flush(); | |||||
| 129 | } | |||||
| 130 | ||||||
| 131 | } catc h (final I OException ex) { | |||||
| 132 | throw ne w RuntimeE xception(e x); | |||||
| 133 | } | |||||
| 134 | } | |||||
| 135 | try { | |||||
| 136 | if (nu ll != this .reader) { | |||||
| 137 | this.rea der.close( ); | |||||
| 138 | } | |||||
| 139 | if (nu ll != this .writer) { | |||||
| 140 | this.wri ter.close( ); | |||||
| 141 | } | |||||
| 142 | } ca tch (final IOExcepti on ex) { | |||||
| 143 | throw new Runtim eException (ex); | |||||
| 144 | } | |||||
| 145 | Mock SocketServ er.log | |||||
| 146 | .info("E xiting " + Thread.cu rrentThrea d().getNam e()); | |||||
| 147 | } | |||||
| 148 | ||||||
| 149 | pu blic void setClientS ocket(fina l Socket c lientSocke t) { | |||||
| 150 | this .socket = clientSock et; | |||||
| 151 | } | |||||
| 152 | ||||||
| 153 | pu blic void setStop() { | |||||
| 154 | this .stop = tr ue; | |||||
| 155 | } | |||||
| 156 | ||||||
| 157 | pu blic Objec t transcei ve(final O bject msg) { | |||||
| 158 | fina l MockSock etTranscei ver transc eiver = ne w MockSock etTranscei ver(); | |||||
| 159 | retu rn transce iver.trans ceive((Str ing) msg); | |||||
| 160 | } | |||||
| 161 | ||||||
| 162 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.