Package org.opennms.core.utils
Class SocketUtils
- java.lang.Object
-
- org.opennms.core.utils.SocketUtils
-
-
Constructor Summary
Constructors Constructor Description SocketUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
validResponse(String request, String responsePattern, BufferedReader r, Writer wr)
Writesrequest
towr
then reads the response fromr
and validates that it matches the pattern provided inresponsePattern
.static Socket
wrapSocketInSslContext(Socket socket)
static SSLSocket
wrapSocketInSslContext(Socket socket, String protocol)
static SSLSocket
wrapSocketInSslContext(Socket socket, String protocol, String[] cipherSuites)
-
-
-
Method Detail
-
wrapSocketInSslContext
public static Socket wrapSocketInSslContext(Socket socket) throws IOException
- Throws:
IOException
-
wrapSocketInSslContext
public static SSLSocket wrapSocketInSslContext(Socket socket, String protocol) throws IOException
- Throws:
IOException
-
wrapSocketInSslContext
public static SSLSocket wrapSocketInSslContext(Socket socket, String protocol, String[] cipherSuites) throws IOException
- Throws:
IOException
-
validResponse
public static boolean validResponse(String request, String responsePattern, BufferedReader r, Writer wr) throws IOException
Writes
request
towr
then reads the response fromr
and validates that it matches the pattern provided inresponsePattern
.To obtain
r
from ajava.util.Socket socket
:
new BufferedReader(new InputStreamReader(socket.getInputStream()));
To obtain
wr
from ajava.util.Socket socket
:
new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
- Parameters:
request
- the String to write to wrresponsePattern
- a String representing a regular expression pattern you expect to match the response received fromr
after writing request to wrr
- the BufferedReader from which to get the responsewr
- the Writer on which the request is written- Throws:
IOException
-
-