Interface URLConnectionFactory


  • public interface URLConnectionFactory

    An interface that can be implemented to override or extend the Report Generators method of resolving URLs. For example, for more control over how redirections are done on HTTP:

     ReportParser.registerURLConnectionFactory("http", new URLConnectionFactory() {
         public URLConnection openURLConnection(String url) throws IOException {
             HttpURLConnection con;
             int redirectcount = 0;
             while (true) {
                 con = (HttpURLConnection)new URL(url).openConnection();
                 int code = con.getResponseCode();
                 if (code == 301 || code == 302 && ++redirectcount < 5) {
                     url = con.getHeaderField("Location");
                 } else if (code != 200) {
                     con.disconnect();
                     throw new IOException("HTTP "+code+": "+con.getResponseMessage()+" for "+url);
                 } else {
                     return con;
                 }
             }
         }
     });
     
    Since:
    1.1.67
    See Also:
    ReportParser.registerURLConnectionFactory(java.lang.String, org.faceless.report.URLConnectionFactory)
    • Method Detail

      • openURLConnection

        java.net.URLConnection openURLConnection​(java.lang.String url)
                                          throws java.io.IOException
        Return a URLConnection for the specified uri. The URI will have a scheme that is a case-insensitive match for one of the schemes this factory was registered with. If this method returns null, the default method of opening a URL will be used.
        Parameters:
        url - the URL to be opened, as a string.
        Returns:
        a URLConnection that was opened to the specified URL, or null if the default approach should be used.
        Throws:
        java.io.IOException - if the URL cannot be opened for any reason