src/share/classes/javax/net/ssl/SNIHostName.java

Print this page




 278      * <P>
 279      * This method can be used by a server to verify the acceptable
 280      * {@code SNIHostName}s.  For example,
 281      * <pre>
 282      *     SNIMatcher matcher =
 283      *         SNIHostName.createSNIMatcher("www\\.example\\.com");
 284      * </pre>
 285      * will accept the hostname "www.example.com".
 286      * <pre>
 287      *     SNIMatcher matcher =
 288      *         SNIHostName.createSNIMatcher("www\\.example\\.(com|org)");
 289      * </pre>
 290      * will accept hostnames "www.example.com" and "www.example.org".
 291      *
 292      * @param  regex
 293      *         the <a href="{@docRoot}/java/util/regex/Pattern.html#sum">
 294      *         regular expression pattern</a>
 295      *         representing the hostname(s) to match
 296      * @throws NullPointerException if {@code regex} is
 297      *         {@code null}
 298      * @throws PatternSyntaxException if the regular expression's syntax
 299      *         is invalid
 300      */
 301     public static SNIMatcher createSNIMatcher(String regex) {
 302         if (regex == null) {
 303             throw new NullPointerException(
 304                 "The regular expression cannot be null");
 305         }
 306 
 307         return new SNIHostNameMatcher(regex);
 308     }
 309 
 310     // check the validity of the string hostname
 311     private void checkHostName() {
 312         if (hostname.isEmpty()) {
 313             throw new IllegalArgumentException(
 314                 "Server name value of host_name cannot be empty");
 315         }
 316 
 317         if (hostname.endsWith(".")) {
 318             throw new IllegalArgumentException(
 319                 "Server name value of host_name cannot have the trailing dot");




 278      * <P>
 279      * This method can be used by a server to verify the acceptable
 280      * {@code SNIHostName}s.  For example,
 281      * <pre>
 282      *     SNIMatcher matcher =
 283      *         SNIHostName.createSNIMatcher("www\\.example\\.com");
 284      * </pre>
 285      * will accept the hostname "www.example.com".
 286      * <pre>
 287      *     SNIMatcher matcher =
 288      *         SNIHostName.createSNIMatcher("www\\.example\\.(com|org)");
 289      * </pre>
 290      * will accept hostnames "www.example.com" and "www.example.org".
 291      *
 292      * @param  regex
 293      *         the <a href="{@docRoot}/java/util/regex/Pattern.html#sum">
 294      *         regular expression pattern</a>
 295      *         representing the hostname(s) to match
 296      * @throws NullPointerException if {@code regex} is
 297      *         {@code null}
 298      * @throws java.util.regex.PatternSyntaxException if the regular expression's
 299      *         syntax is invalid
 300      */
 301     public static SNIMatcher createSNIMatcher(String regex) {
 302         if (regex == null) {
 303             throw new NullPointerException(
 304                 "The regular expression cannot be null");
 305         }
 306 
 307         return new SNIHostNameMatcher(regex);
 308     }
 309 
 310     // check the validity of the string hostname
 311     private void checkHostName() {
 312         if (hostname.isEmpty()) {
 313             throw new IllegalArgumentException(
 314                 "Server name value of host_name cannot be empty");
 315         }
 316 
 317         if (hostname.endsWith(".")) {
 318             throw new IllegalArgumentException(
 319                 "Server name value of host_name cannot have the trailing dot");