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 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 15 |
Complexity Density: 0.65 |
|
14 |
|
public class RequestSpy { |
15 |
|
private static final Logger logger = LoggerFactory |
16 |
|
.getLogger(RequestSpy.class); |
17 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 13 |
Complexity Density: 0.65 |
|
18 |
0 |
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 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
56 |
0 |
public RequestSpy(final String host, final int port) {... |
57 |
0 |
this.host = host; |
58 |
0 |
this.port = port; |
59 |
|
} |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
61 |
0 |
public final String spyRequest(final String req) {... |
62 |
0 |
return spyRequest(host, port, req); |
63 |
|
} |
64 |
|
} |