SOAP monitor

zhaozj2021-02-16  45

1. SOAP Monitor Principle: SOAP Monitor Intercepts and forwards SOAP requests through TCPIP protocol, and displays relevant SOAP package information, making developers to debug web services, the principle is as follows:

2. System class diagram:

3. Program source code:

Package eStore.Client.util;

/ * * EStore * * CopyRight (C) 2003 YL Group. All rights reserved. * /

import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JTabbedPane; import javax .swing.JTable; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.ListSelectionModel; import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.border.TitledBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.plaf.basic.BasicButtonListener; import javax.swing.table.DefaultTableModel; import javax.swing .Table.tableModolumn; import javax.swing.table.tablemodel; import javax.swing.text.attributeSet; Import javax.swing.text.badlocationExc eption; import javax.swing.text.Document; import javax.swing.text.PlainDocument; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java .awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowEvent; import java.io.ByteArrayInputStream; import java.io .File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.net.ServerSocket; import java.net. Socket; import java.net.url; import java.text.dateFormat; import java.text.SIMPLEDATEFORMAT; import java.util.date; import java.util.itrator;

Import java.util.resourcebundle; import java.util.vector; / ** * TCP Monitor to log http message and response, Both soap and plain http. * @Author Yellowicq (YELLOWICQ@xinhuaet.com) * /

Public Class TCPMonitor Extends Jframe {Private JTABBEDPANE Notebook = NULL;

private static final int STATE_COLUMN = 0; private static final int TIME_COLUMN = 1; private static final int INHOST_COLUMN = 2; private static final int OUTHOST_COLUMN = 3; private static final int REQ_COLUMN = 4;

Private static final string default_host = "127.0.0.1"; private static final int default_port = 8080;

/ ** * this is the admin page * / class AdminPage extends JPanel {public JRadioButton listenerButton, proxyButton; public JLabel hostLabel, tportLabel; public NumberField port; public HostnameField host; public NumberField tport; public JTabbedPane noteb; public JCheckBox HTTPProxyBox; public HostnameField HTTPProxyHost; public NumberField HTTPProxyPort; public JLabel HTTPProxyHostLabel, HTTPProxyPortLabel; public JLabel delayTimeLabel, delayBytesLabel; public NumberField delayTime, delayBytes; public JCheckBox delayBox;

Public adminPage (jtabbedpane notebook, string name) {jPanel mainpane = null; jbutton addbutton = null;

THIS.SetLayout (New BorderLayout ()); Noteb = Notebook;

GridbagLayout Layout = new gridbagLayout (); gridbagconstraints c = new gridbagconstraints ();

Mainpane = new jPanel (layout);

C. ANCHOR = Gridbagconstros.west; c.GridWidth = Gridbagconstraints.Remainder; mainpane.add (New Jlabel (GetMessage ("NewTCP00", "Create A New TCP / IP Monitor ...") "", c); // Add Some Blank space mainpane.add (Box.Createrigidarea (New Dimension (1, 5)), C);

///// jPanel tmppanel = new jPanel (New gridbagLayout ());

C. ANCHOR = Gridbagconstraints.west; c.GridWidth = 1; TMPPANEL.ADD (New Jlabel (GetMessage ("Listenport00", "Listen Port #") ""), C);

C. gridwidth; c.GridWidth = Gridbagconstraints.Remainder; Tmppanel.Add (port = new numberfield (4), c);

Mainpane.Add (Tmppanel, C);

Mainpane.Add (Box.Createrigidarea (New Dimension (1, 5)), C);

// Group for the radio button button btns = new buttonGroup ();

C. ANCHOR = Gridbagconstraints.west; c.GridWidth = Gridbagconstraints.Remainder; mainpane.add (New Jlabel (GetMess00 "," ACT AS A ... "), C);

// Target Host / Port Section /// C.Anchor = Gridbagconstraints.west; C.GridWidth = Gridbagconstraints.Remainder;

Final String Listener = GetMessage ("Listener00", "Listener");

MAINPANE.ADD (ListenerButton = New Jradiobutton (Listener), C); btns.add (listenerButton); ListenerButton.setSelected (True);

ListenerButton.AddActionListener (actionListener () {public void action {if (listener.equals ())) {boolean state = listenerButton.isSselected ();

TPORT.SETENABLED (State); HostLabel.SetForeground (State? Color.Black: Color.gray); TPORTLABEL.SETFOREGROUND (State? color.black: color.gray);}}}); C .anchor = GridBagConstraints.WEST; c.gridwidth = 1; mainPane.add (Box.createRigidArea (new Dimension (25, 0))); mainPane.add (hostLabel = new JLabel (getMessage ( "targetHostname00", "Target Hostname" ) "" ", c);

C. ANCHOR = Gridbagconstros.west; c.GridWidth = Gridbagconstraints.Remainder; host = new hostnamefield (30); mainpane.add (Host, c); host.settext (Default_host);

C. Anechor = Gridbagconstraints.west; c.GridWidth = 1; mainpane.add (Box.createrigidarea (New Dimension (25, 0))); Mainpane.Add (TportLabel = New Jlabel ("TargetPort00", "Target Port # ") " "", c);

C. ANCHOR = Gridbagconstros.west; c.GridWidth = Gridbagconstraints.Remainder; TPORT = New Numberfield (4); mainpane.add (tport, c); tport.setValue (default_port);

// Act as proxy section /// c.Anchor = Gridbagconstraints.west; c.GridWidth = Gridbagconstraints.Remainder; Final String proxy = getMessage ("proxy00", "proxy");

Mainpane.add (proxybutton = new jradiobutton (proxy), c); btns.add (proxybutton);

ProxyButton.addActionListener (actionListener () {public void activity {if (proxy.equals (event.equals ()) {boolean state = proxyButton.isselected ();

TPORT.SETENABED (! State); Host.setenabled (! State); Hostlabel.SetForeground (State? Color.gray: color.black); TPORTLABEL.SETFOREGROUND (state? color.gray: color.black);}}}) // Spacer / c.anchor = Gridbagconstraints.west; c.GridWidth = Gridbagconstraints.Remainder; mainpane.add (Box.Createrigidarea (New Dimension (1, 10)), C);

// Options section /// jPanel opts = new jPanel (new gridbaglayout ());

OPTS.SetBorder (New Titledborder ("Options", "Options")))))))))))))))))))))))))))))); C.Anchor = Gridbagconstrains.west; c.GridWidth = Gridbagconstraints.Remainder; mainpane.add (OPTS, C);

// HTTP Proxy Support section /// c.anchor = GridBagConstraints.WEST; c.gridwidth = GridBagConstraints.REMAINDER; final String proxySupport = getMessage ( "proxySupport00", "HTTP Proxy Support");

Opts.add (httpproxybox = new jcheckbox (proxysupport), c);

c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; opts.add (HTTPProxyHostLabel = new JLabel (getMessage ( "hostname00", "Hostname") ""), c); HTTPProxyHostLabel.setForeground (Color.gray);

C. ANCHOR = GridbagconstRAINTS.WEST; C.GridWidth = Gridbagconstraints.Remainder; OPTS.Add (httpproxyhost = new hostnamefield (30), c); httpproxyhost.setenabled (false);

c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; opts.add (HTTPProxyPortLabel = new JLabel (getMessage ( "port00", "Port #") ""), c); HTTPProxyPortLabel.setForeground (Color.gray) ; c. gridWidth = Gridbagconstraints.Remainder; OPTS.Add (httpproxyport = new numberfield (4), c); httppproxyport.setenabled (false);

HTTPProxyBox.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent event) {if (proxySupport.equals (event.getActionCommand ())) {boolean b = HTTPProxyBox.isSelected (); Color color = b Color.black: Color? .

Httpproxyhost.senabled (b); httppproxyport.setenabled (b); httppproxyhostlabel.setForeground (color); httppproxyportlabel.setForeground;}}});

// set default proxy value ... string tmp = system.getProperty ("http.proxyhost");

IF (TMP! = null && tmp.equals (")) {tmp = null;}

HTTPProxyBox.setSelected (tmp = null!); HTTPProxyHost.setEnabled (tmp = null!); HTTPProxyPort.setEnabled (tmp = null!); HTTPProxyHostLabel.setForeground (tmp = null Color.black: Color.gray!?); HTTPProxyPortLabel. SetForeground (tmp! = null? color.black: color.gray);

IF (TMP! = NULL) {httpproxybox.setselected (true); httpproxyhost.settext (tmp); tmp = system.getProperty ("http.proxyport"); if (tmp! = null && tmp.equals (")) {TMP = NULL;} if (tmp == null) {TMP = "80";} httpproxyport.settext (tmp);} // add byte delay fields opts.add (Box.createrigidarea (New Dimension (1, 10) ), c); c.anchor = GridBagConstraints.WEST; c.gridwidth = GridBagConstraints.REMAINDER; final String delaySupport = getMessage ( "delay00", "Simulate Slow Connection"); opts.add (delayBox = new JCheckBox (delaySupport), c);

// bytes per pause c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; delayBytesLabel = new JLabel (getMessage ( "delay01", "Bytes per Pause")); opts.add (delayBytesLabel, c); delayBytesLabel.setForeground (Color.gray); c. gridwidth = gridbagconstraints.remainder; opts.add (delaybytes = new numberfield (6), c); delayBytes.senabled (false);

// delay interval c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; delayTimeLabel = new JLabel (getMessage ( "delay02", "Delay in Milliseconds")); opts.add (delayTimeLabel, c); delayTimeLabel.setForeground ( Color.gray); c. gridwidth = gridbagconstraints.remainder; opts.add (delayTime = new number; delaytime.senable);

// enabler callback delayBox.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent event) {if (delaySupport.equals (event.getActionCommand ())) {boolean b = delayBox.isSelected (); Color color = b Color? . Black: color.gray; delayBytes.setenabled (b); delayTime.senabled (b); delayByteslabel.setForeground; delayTimeLabel.setForeGround;}}};

// Spacer // mainpane.add (Box.Createrigidarea (New Dimension (1, 10)), C);

// add button /// C. Gridbagconstraints.west; c.GridWidth = gridbagconstraints.remainder; Final String add = getMessage ("add00", "add");

Mainpane.add (addbutton = new jbutton (add), c);

This.Add (New Jscrollpane (Mainpane), BorderLayout.center;

addButton.addActionListener (new ActionListener () {public void actionPerformed (ActionEvent event) {if (add.equals (event.getActionCommand ())) {String text; Listener l = null; int lPort; lPort = port.getValue (0) ; If (lport == 0) {// no port, button does Nothing return;} String thost = host.gettext (); int tport = 0; tport = tport.getValue (0); SlowlinkSimulator Slowlink = NULL; if (IF) DELAYBOX.ISselected ()) {INT BYTES = delayBytes.getValue (0); int Time = delayTime.getValue (0); SlowLink = New SlowlinkSimulator (bytes, time);} l = new listener (Noteb, Null, Lport, thove , tport, proxybutton.isselected (), slowlink; // pick-up the http proxy settings /// text = httpproxyhost.getText (); if ("" .equals (text)) { text = null;} l.HTTPProxyHost = text; text = HTTPProxyPort.getText (); int proxyPort = HTTPProxyPort.getValue (-1); if (! proxyPort = -1) {l.HTTPProxyPort = Integer.parseInt (text); } // reset the port port.settext (null);}}});

Notebook.addtab (Name, this); Notebook.Repaint (); Notebook.setSelectedIndex (Notebook.gettabCount () - 1);}

}

. / ** * wait for incoming connections, spawn a connection thread when * stuff comes in * / class SocketWaiter extends Thread {ServerSocket sSocket = null; Listener listener; int port; boolean pleaseStop = false; public SocketWaiter (Listener l, int p ) {Listener = L; port = p; start ();

Public void run () {Try {listener.Setleft (New Jlabel ("Waiting for Connection ...))); Listener.Repaint (); SSOCKET = New ServerSocket (Port); for ;) {Socket insocket = ssocket.accept ();

IF (pleasestop) {Break;} new connection (listener, insocket); insocket = null;}} catch (exception exp) {if (! "socket closed" .Equals (exp.getMessage ())) {JLabel TMP = New EXP.TOSTRING ());

Tmp.SetForeground (color.red); listener.setleft (tmp); listener.setright (New Jlabel (")); listener.stop ();}}}

/ ** * force a halt by connection to self and kil vid Halt () {try {please; new socket ("127.0.0.1", port); if (SSOCKET! = NULL) {SSOCKET.CLOSE ();}} catch (exception e) {logpage.loginfor (E.getMessage ());}}}

/ ** * class to simulate slow connections by slowing down the system * / static class SlowLinkSimulator {private int delayBytes; private int delayTime; private int currentBytes; private int totalBytes;

/ ** * construct * @param delayBytes bytes per delay; set to 0 for no delay * @param delayTime delay time per delay in milliseconds * / public SlowLinkSimulator (int delayBytes, int delayTime) {this.delayBytes = delayBytes; this.delayTime = delayTime;} / ** * construct by copying delay bytes and time, but not current * count of bytes * @param that source of data * / public SlowLinkSimulator (SlowLinkSimulator that) {this.delayBytes = that.delayBytes; this.delayTime = That.delayTime;}

/ ** * How much BYTES HAVE GONE PAST? * @Return * / public int gettotalbytes () {Return TotalBytes;

/ ** * log #of Bytes Pumped. Will Pause When Necessary. This method is not * synchronized * @Param BYTES * / PUBLIC VOID PUMP (INT BYTES) {TOTALBYTES = BYTES; if (DelayBytes == 0) {//// when not delaying, we are just a byte counter return;} currentBytes = bytes; if (currentBytes> delayBytes) {// we have overshot lets find out how far int delaysize = currentBytes / delayBytes;. long delay = delaysize * (long ) delayTime; // move byte counter down to the remainder of bytes currentBytes = currentBytes% delayBytes; // now wait try {Thread.sleep (delay);} catch (InterruptedException e) {; // ignore the exception}}}

/ ** * Get the current byte count * @return * / public int getCurrentBytes () {Return CurrentBytes;

/ ** * set the current byte count * @Param currentBytes * / public void setcurrentBytes (int currentbytes) {this.currentbytes = currentbytes;}}

/ ** * this class handles the pumping of data from the incoming socket to the * outgoing socket * / class SocketRR extends Thread {Socket inSocket = null; Socket outSocket = null; JTextArea textArea; InputStream in = null; OutputStream out = null; Boolean XMLFormat; Volatile Boolean Done = false; TableModel TMODEL = NULL; int TableIndex = 0; string type = null; connection myconnection = null; Slowlinksimulator Slowlink;

public SocketRR (Connection c, Socket inputSocket, InputStream inputStream, Socket outputSocket, OutputStream outputStream, JTextArea _textArea, boolean format, TableModel tModel, int index, final String type, SlowLinkSimulator slowLink) {inSocket = inputSocket; in = inputStream; outSocket = outputSocket; OUT = OUTPUTSTREAM; Textarea = _Textarea; XMLFormat = Format; TMODEL = TMODEL; TableIndex = Index; this.type = type; myconnection = c; this.slowlink = SlowLink; start ();}

Public boolean isdone () {return (done);

Public void run () {Try {byte [] buffer = new byte [4096]; byte [] tmpbuffer = new byte [8192]; int SAVED = 0; int Len; Int i1, i2; int i; int correa 0 ; int tabWidth = 3; boolean atMargin = true; int thisIndent = -1, nextIndent = -1, previousIndent = -1; if (! tmodel = null) {String tmpStr = (String) tmodel.getValueAt (tableIndex, REQ_COLUMN);

IF (! "". Equals (tmpstr)) {reqsaved = tmpstr.length ();}}

A: for (;;) {if (done) {Break;}

Len = Buffer.Length; // used to be 1, but if we block itesn't mat //however 1 will break with some if (len == 0) {len = buffer.length;} (Saved Len> Buffer.Length) {len = Buffer.Length - Saved;} int LEN1 = 0;

While (len1 == 0) {Try {len1 = in.read (buffer, saved, len);} catch (exception ex) {if (done && saved == 0) {Break a;} len1 = -1; break ;}}.

IF (len == -1 && saved == 0) {Break;} if (len == -1) {done = true;

// No Matter How We May (or May Not) Format IT, Send It // ON Unformatted - We don't want to mess with how it it it it, just how it it is displayed if (out! = Null &&len> 0) {SlowLink.Pump (LEN); OUT.WRITE (Buffer, Saved, Len);} IF (TMODEL! = Null && ReqSaved <50) {string Old = (String) TMODEL.GETVALUEAT (TableIndex, Req_column );

Old = Old New String (Buffer, Saved, Len); IF (Old.Length ()> 50) {OLD = Old.Substring (0, 50);

REQSAVED = Old.length ();

IF ((i = old.indexof ('/ n'))> 0) {OLD = Old.Substring (0, i - 1); reqsaved = 50;}

TMODEL.SETVALUEAT (OLD, TableIndex, Req_Column);

IF (XMLFORMAT) {// do xml formatting boolean inxml = false; int bufferlen = saved;

IF (len! = -1) {bufferlen = len;} i1 = 0; I2 = 0; saved = 0; for (; I1 Nextindent) {thisindent = Next Ltd "; inxml = true;} if (buffer [i1) == '/' && buffer [i1 1] == '>) {previousindent = nextindent-; inxml = true; IF (thisinde) NT! = -1) {IF (thisindent> 0) {TmpBuffer [i2 ] = (byte) '/ n';} for (i = tabwidth * thisindent; i> 0; i -) {TmpBuffer [i2 ] = (Byte) '';}} atmargin = (buffer [i1] == '/ n' || buffer [i1] == '/ r');

IF (! inxml ||! atmargin) {TmpBuffer [i2 ] = buffer [i1];}} textarea.Append (NEW STRING (TmpBuffer, 0, I2));

// shift saved bytes to the beginning for (i = 0; i

Public void halt () {type {if (INSOCKET! = null) {insocket.close ();} if (outsocket! = null) {outsocket.close ();} insocket = null; Outsocket = null; if (in! = NULL) {in .close ();} if (out! = null) {out.close ();} in = null; out = null; done = true;} catch (exception e) {LOGPAGE.LOGINFOR (E .getMessage ());}}} / ** * a connection listens to a single current connection * / class Connection extends Thread {listener listener; boolean active; String fromHost; String time; JTextArea inputText = null; JScrollPane inputScroll = null; JTextArea outputText = null; JScrollPane outputScroll = null; Socket inSocket = null; Socket outSocket = null; Thread clientThread = null; Thread serverThread = null; SocketRR rr1 = null; SocketRR rr2 = null; inputStream inputStream = null;

String httpproxyhost = null; int httppproxyport = 80; Private Slowlinksimulator Slowlink;

Public Connection (Listener L) {listener = L; httpproxyhost = l.httppproxyhost; httppproxyport = l.httpProxyport; Slowlink = L.SlowLink;}

Public Connection (Listener L, Socket S) {this (l); insocket = s; start ();

Public Connection (Listener L, InputStream IN) {this (L); InputStream = in; start ();}

Public void run () {Try {Active = True;

HTTPProxyHost = System.getProperty ( "http.proxyHost"); if (! HTTPProxyHost = null && HTTPProxyHost.equals ( "")) {HTTPProxyHost = null;} if (! HTTPProxyHost = null) {String tmp = System.getProperty ( " http.proxyport ");

IF (tmp! = null && tmp.equals (")) {tmp = null;} if (tmp == null) {httpproxyport = 80;} else {httpproxyport = integer.parseint (TMP);}}

IF (Insocket! = null) {fromhost = (INSOCKET.GETITITADDRESS ()). gethostname ();} else {fromhost = "resend";

String DateFormat = GetMessage ("DateFormat", "YYYY-MM-DD HH: MM: SS"); DateFormat DF = New SimpleDateFormat;

Time = DF.FORMAT (new date ());

INT count = listener.connections.size ();

Listener.TableModel.inSertrow (Count 1, New Object [] {GetMessage ("Active00", "Active"), Time, FromHost, Listener.hostfield.getText (), "}); Listener.Connections.add (this ); inputText = new JTextArea (null, null, 20, 80); inputScroll = new JScrollPane (inputText); outputText = new JTextArea (null, null, 20, 80); outputScroll = new JScrollPane (outputText);

ListSelectionModel LSM = listener.ConnectionTable.getSelectionModel ();

if (count == 0 || lsm.getLeadSelectionIndex () == 0) {listener.outPane.setVisible (false); int divLoc = listener.outPane.getDividerLocation (); listener.setLeft (inputScroll); listener.setRight (outputScroll );

listener.removeButton.setEnabled (false); listener.removeAllButton.setEnabled (true); listener.saveButton.setEnabled (true); listener.resendButton.setEnabled (true); listener.outPane.setDividerLocation (divLoc); listener.outPane.setVisible (TRUE);

String TargetHost = listener.hostfield.getText (); int targetport = integer.parseint (listener.tportfield.getText ());

InputStream Tmpin1 = INPUTSTREAM; OUTPUTSTREAM TMPOUT1 = NULL;

InputStream Tmpin2 = NULL; OUTPUTSTREAM TMPOUT2 = NULL;

IF (tmpin1 == null) {tmpin1 = insocket.getinputStream ();}

IF (insocket! = null) {tmpout1 = insocket.getOutputStream ();}

String buffereddata = null; stringbuffer buf = null;

INDEX = listener.connections.indexof (this);

IF (listener.isproxybox.isselected () || httpproxyhost! = null) {// check if we're a proxy byte [] b = new byte [1];

BUF = new stringbuffer (); string s;

For (;;) {int LEN;

LEN = tmpin1.read (b, 0, 1); if (len == -1) {Break;} s = new string (b); buf.append (s); if (b [0]! = '/ N ') {Continue;} Break;

BufferedData = buf.tostring (); inputText.Append (buffereddata);

IF (BufferedData.StartSwith ("get") || bufferedData.startSwith ("post") {int start, end; url url; start = buffereddata.indexof ('') 1; while (buffereddata.charat (start) == ') {start ;} end = buffereddata.indexof (' ', start); string urlstring = bufferedData.substring (start, end);

IF (UrlString.Charat (0) == '/') {urlstring = urlstring.substring (1);} if (listener.isproxybox.isselected ()) {url = new url (urlstring); targethost = url.gethost ); Targetport = url.getPort (); if (targetport == -1) {targetport = 80;}

listener.tableModel.setValueAt (targetHost, index 1, OUTHOST_COLUMN); bufferedData = bufferedData.substring (0, start) url.getFile () bufferedData.substring (end);} else {url = new URL ( "http: // " TargetHost ": " TargetPort " / " URLString);

Listener.TableModel.SetValueat (TargetHost, Index 1, Outhost_Column); BufferedData = BufferedData.Substring (0, start) URL.TOEXTERNALM () BufferedData.substring (End);

TargetHost = httppproxyhost; targetport = httpproxyport;

}}} Else {// // Change Host: Header to Point To Correct Host // Byte [] b1 = new byte [1]; buf = new stringbuffer (); string s1; string lastline = null;

For (;;) {int LEN;

Len = tmpin1.read (b1, 0, 1); if (len == -1) {Break;} S1 = new string (b1); buf.append (s1); if (b1 [0]! = '/ N ') {Continue;} // We Have a completion line string line = buf.tostring ();

BUF.SETLENGTH (0); // Check to see if we have found host: header if (line.startswith ("Host:")) {// We need to update the hostname to target host string newhost = "Host:" TargetHost "/ r / n";

BufferedData = BufferedData.concat; Break;} // add it to {buffereddata == null) {buffereddata = line;} else {buffereddata = bufferedData.concat (line);}

// Failsafe if (line.equals ("/ r / n")) {Break;} IF ("/N") && line.equals ("/ n")) {Break;} lastline = line } If (buffereddata! = Null) {INPUTTEXT.APpend (BufferedData); int idx = buffereddata.length (): 50; s1 = bufferedData.substring (0, IDX); int i = s1.indexof ('/ n');

IF (i> 0) {s1 = s1.substring (0, i - 1);} S1 = S1 " " "; S1 = s1.substring (0, 51); Listener.TableModel.SetValueat (S1, Index 1, Req_column);}} f (targetport == -1) {targetport = 80;} outsocket = new socket (targethost, targetport);

Tmpin2 = outsocket.getinputStream (); tmpout2 = outsocket.getOutputStream ();

IF (buffereddata! = null) {byte [] b = bufferedData.getbytes (); tmpout2.write (b); slowlink.pump (b.ley);}

Boolean format = listener.xmlformatbox.isselected ();

// this is the channel to the endpoint rr1 = new SocketRR (this, inSocket, tmpIn1, outSocket, tmpOut2, inputText, format, listener.tableModel, index 1, "request:", slowLink); // create the response slow link from the inbound slow link SlowLinkSimulator responseLink = new SlowLinkSimulator (slowLink); // this is the channel from the endpoint rr2 = new SocketRR (this, outSocket, tmpIn2, inSocket, tmpOut1, outputText, format, null, 0, "response: ", responselink);

While (RR1! = NULL || RR2! = null) {// only loop as long as the connection to the target // Machine Is Available - ONCE THAT THE's GONE We ​​can stop. // The old way, loop unsil Both Are Closed , Left US // Looping Forever Since No One Closed The 1st One. if (Null! = RR1 && r1.Isdone ()) {IF (INDEX> = 0 && r2! = null) {listener.tableModel.setValueat (GetMessage "resp00", "resp", 1 index, state_column);} rr1 = null;} if (null! = rr2 && r2.isdone ()) {if (index> = 0 && r1! = null) {listener .TableModel.SetValueat ("REQ00", "Req"), 1 index, state_column;} rr2 = null;} synchronized (this) {this.wait (1000); // Safety Just Incase We're Not Told to Wake Up.}

Active = false;

IF (index> = 0) {listener.tableModel.setValueat ("Done00", "DONE"), 1 index, state_column;

}}} Catch (exception e) {stringwriter st = new stringwriter (); PrintWriter WR = new PrintWriter (st); int index = listener.connections.indexof (this);

IF (index> = 0) {listener.tableModel.setValueat ("Error00", "Error"), 1 index, state_column;} E.PrintStackTrace (WR); Wr.Close (); if (OutputText! = NULL) {OutputText.Append (st.tostring ());} else {// Something WRONGBEFORE We Had The Output Area Logpage.LoginFor ("OutputText Is Null, SO Log The Infor AS / N '" ST. Tostring () "'");} Halt ();}} synchronized void wakeup () {this.notifyall ();

Public void Halt () {try {if (rr1! = null) {r1.halt ();} if (rr2! = null) {r2.halt ();} if (insocket! = null) {INSOCKET.CLOSE );} INSOCKET = NULL; IF (outsocket! = Null) {outsocket.close ();} outsocket = null;} catch (excetion e) {logpage.loginfor (E.getMessage ());}}

Public void remove () {int index = -1;

Try {halt (); index = listener.connections.indexof (this); listener.tableModel.remOverow (Index 1); listener.connections.remove (index);} catch (Exception E) {LOGPAGE.LOGINFOR ("INDEX : = " Index this);}}}

/ ** * this is the log page * / class LogPage extends JPanel {// Monitor log section /// public JPanel logPanel = new JPanel (new BorderLayout ()); public static JTextArea textArea = null; public LogPage (JTabbedPane notebook, String name) {LogPanel.setBorder (NEW TITLEDBORDER (TCPMonitor.getMessage)); Textarea = New Jtextarea (Null, NULL, 27, 93); LogPanel.Add (New Jscrollpane (Textarea ), BorderLayout.CENTER); this.setLayout (new BorderLayout ()); this.add (logPanel, BorderLayout.CENTER); notebook.addTab (name, this); notebook.repaint (); notebook.setSelectedIndex (notebook.getTabCount () - 1); TextArea.seteditable (TRUE);} public static void loginfor (string infor) {textarea.append (Infor "/ n");}} // EOC

转载请注明原文地址:https://www.9cbs.com/read-26309.html

New Post(0)