Class SocketUtils


  • public abstract class SocketUtils
    extends java.lang.Object
    Author:
    Seth, OpenNMS
    • Constructor Summary

      Constructors 
      Constructor Description
      SocketUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean validResponse​(java.lang.String request, java.lang.String responsePattern, java.io.BufferedReader r, java.io.Writer wr)
      Writes request to wr then reads the response from r and validates that it matches the pattern provided in responsePattern.
      static java.net.Socket wrapSocketInSslContext​(java.net.Socket socket)  
      static javax.net.ssl.SSLSocket wrapSocketInSslContext​(java.net.Socket socket, java.lang.String protocol)  
      static javax.net.ssl.SSLSocket wrapSocketInSslContext​(java.net.Socket socket, java.lang.String protocol, java.lang.String[] cipherSuites)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SocketUtils

        public SocketUtils()
    • Method Detail

      • wrapSocketInSslContext

        public static java.net.Socket wrapSocketInSslContext​(java.net.Socket socket)
                                                      throws java.io.IOException
        Throws:
        java.io.IOException
      • wrapSocketInSslContext

        public static javax.net.ssl.SSLSocket wrapSocketInSslContext​(java.net.Socket socket,
                                                                     java.lang.String protocol)
                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • wrapSocketInSslContext

        public static javax.net.ssl.SSLSocket wrapSocketInSslContext​(java.net.Socket socket,
                                                                     java.lang.String protocol,
                                                                     java.lang.String[] cipherSuites)
                                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • validResponse

        public static boolean validResponse​(java.lang.String request,
                                            java.lang.String responsePattern,
                                            java.io.BufferedReader r,
                                            java.io.Writer wr)
                                     throws java.io.IOException

        Writes request to wr then reads the response from r and validates that it matches the pattern provided in responsePattern.

        To obtain r from a java.util.Socket socket:
        new BufferedReader(new InputStreamReader(socket.getInputStream()));

        To obtain wr from a java.util.Socket socket:
        new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

        Parameters:
        request - the String to write to wr
        responsePattern - a String representing a regular expression pattern you expect to match the response received from r after writing request to wr
        r - the BufferedReader from which to get the response
        wr - the Writer on which the request is written
        Throws:
        java.io.IOException