Ticket #8571: tinyurl.patch

File tinyurl.patch, 2.5 KB (added by Don-vip, 12 years ago)

Fix for bug reports with incomplete stacktraces

  • core/src/org/openstreetmap/josm/tools/OpenBrowser.java

     
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    66import java.awt.Desktop;
     7import java.io.BufferedReader;
    78import java.io.IOException;
     9import java.io.InputStream;
     10import java.net.HttpURLConnection;
    811import java.net.MalformedURLException;
    912import java.net.URI;
     13import java.net.URISyntaxException;
     14import java.net.URL;
    1015
    1116import javax.swing.JApplet;
    1217
    1318import org.openstreetmap.josm.Main;
     19import org.openstreetmap.josm.io.UTFInputStreamReader;
    1420
    1521/**
    1622 * Helper to open platform web browser on different platforms
     
    2834    }
    2935   
    3036    /**
     37     * @param uri The URI to display
    3138     * @return <code>null</code> for success or a string in case of an error.
    3239     * @throws IllegalStateException thrown if no platform is set to which opening the URL can be dispatched,
    3340     * {@link Main#platform}
     
    4249                return mue.getMessage();
    4350            }
    4451        }
     52       
     53        // Windows cannot open URLs longer than 2047 or 2083 characters. Make a tiny url for large URLs (such as bug reports)
     54        // See http://josm.openstreetmap.de/ticket/8571#comment:3
     55        if (Main.platform instanceof PlatformHookWindows && uri.toString().length() > 2047) {
     56            String tinyUrlRequest = "http://tinyurl.com/api-create.php?url="+uri.toString();
     57            try {
     58                HttpURLConnection connection = Utils.openHttpConnection(new URL(tinyUrlRequest));
     59                InputStream inputStream = connection.getInputStream();
     60                BufferedReader br = new BufferedReader(UTFInputStreamReader.create(inputStream, "UTF-8"));
     61                String tinyUrlAnswer = br.readLine();
     62                try {
     63                    uri = new URI(tinyUrlAnswer);
     64                } catch (URISyntaxException e) {
     65                    System.err.println("Cannot create URL "+tinyUrlAnswer);
     66                }
     67                br.close();
     68                connection.disconnect();
     69            } catch (MalformedURLException e) {
     70                System.err.println("Cannot create URL "+tinyUrlRequest);
     71            } catch (IOException e) {
     72                e.printStackTrace();
     73            }
     74        }
    4575
    4676        if (Desktop.isDesktopSupported()) {
    4777            try {