1. Project Clover database Mon Aug 27 2018 22:12:52 BRT
  2. Package net.technearts.rip

File RequestSpy.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
50% of files have more coverage

Code metrics

4
23
3
1
64
55
15
0.65
7.67
3
5

Classes

Class Line # Actions
RequestSpy 14 23 0% 15 30
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package net.technearts.rip;
2   
3    import java.io.BufferedReader;
4    import java.io.BufferedWriter;
5    import java.io.IOException;
6    import java.io.InputStreamReader;
7    import java.io.OutputStreamWriter;
8    import java.io.StringReader;
9    import java.net.Socket;
10   
11    import org.slf4j.Logger;
12    import org.slf4j.LoggerFactory;
13   
 
14    public class RequestSpy {
15    private static final Logger logger = LoggerFactory
16    .getLogger(RequestSpy.class);
17   
 
18  0 toggle public static final String spyRequest(final String host, final int port,
19    final String req) {
20  0 final StringBuilder result = new StringBuilder();
21  0 try (Socket socket = new Socket(host, port);
22  0 BufferedWriter out = new BufferedWriter(
23    new OutputStreamWriter(socket.getOutputStream(), "UTF8"));
24  0 BufferedReader in = new BufferedReader(
25    new InputStreamReader(socket.getInputStream()));
26  0 BufferedReader lin = new BufferedReader(new StringReader(req));) {
27  0 logger.info(req);
28  0 String line = null;
29  0 while ((line = lin.readLine()) != null) {
30  0 try {
31  0 out.write(line + "\r\n");
32    } catch (final IOException e) {
33  0 logger.error(
34    "Erro ao enviar request para o socket em " + host + ":" + port,
35    e);
36    }
37    }
38  0 out.write("\r\n");
39  0 out.flush();
40   
41  0 line = null;
42  0 while ((line = in.readLine()) != null) {
43  0 result.append(line);
44    }
45  0 logger.info(result.toString());
46    } catch (final IOException e) {
47  0 logger.error("Erro ao espionar o request em " + host + ":" + port, e);
48    }
49  0 return result.toString();
50    }
51   
52    private final String host;
53   
54    private final int port;
55   
 
56  0 toggle public RequestSpy(final String host, final int port) {
57  0 this.host = host;
58  0 this.port = port;
59    }
60   
 
61  0 toggle public final String spyRequest(final String req) {
62  0 return spyRequest(host, port, req);
63    }
64    }