|
6 | 6 | import com.fasterxml.jackson.databind.JsonNode; |
7 | 7 | import com.fasterxml.jackson.databind.ObjectMapper; |
8 | 8 | import com.google.common.base.Strings; |
| 9 | +import java.awt.Desktop; |
9 | 10 | import java.io.BufferedReader; |
10 | 11 | import java.io.IOException; |
11 | 12 | import java.io.InputStreamReader; |
@@ -69,24 +70,22 @@ public HttpPost build(URI uri) { |
69 | 70 |
|
70 | 71 | @Override |
71 | 72 | public void openBrowser(String ssoUrl) throws SFException { |
| 73 | + if (!URLUtil.isValidURL(ssoUrl)) { |
| 74 | + throw new SFException(ErrorCode.INVALID_CONNECTION_URL, "Invalid SSOUrl found - " + ssoUrl); |
| 75 | + } |
72 | 76 | try { |
73 | 77 | // start web browser |
74 | | - if (!URLUtil.isValidURL(ssoUrl)) { |
75 | | - throw new SFException( |
76 | | - ErrorCode.INVALID_CONNECTION_URL, "Invalid SSOUrl found - " + ssoUrl); |
77 | | - } |
78 | | - if (java.awt.Desktop.isDesktopSupported()) { |
79 | | - URI uri = new URI(ssoUrl); |
80 | | - java.awt.Desktop.getDesktop().browse(uri); |
| 78 | + Runtime runtime = Runtime.getRuntime(); |
| 79 | + Constants.OS os = Constants.getOS(); |
| 80 | + if (Desktop.isDesktopSupported() |
| 81 | + && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) { |
| 82 | + Desktop.getDesktop().browse(new URI(ssoUrl)); |
| 83 | + } else if (os == Constants.OS.MAC) { |
| 84 | + runtime.exec("open " + ssoUrl); |
| 85 | + } else if (os == Constants.OS.WINDOWS) { |
| 86 | + runtime.exec(new String[] {"rundll32", "url.dll,FileProtocolHandler", ssoUrl}); |
81 | 87 | } else { |
82 | | - Runtime runtime = Runtime.getRuntime(); |
83 | | - Constants.OS os = Constants.getOS(); |
84 | | - if (os == Constants.OS.MAC) { |
85 | | - runtime.exec("open " + ssoUrl); |
86 | | - } else { |
87 | | - // linux? |
88 | | - runtime.exec("xdg-open " + ssoUrl); |
89 | | - } |
| 88 | + runtime.exec("xdg-open " + ssoUrl); |
90 | 89 | } |
91 | 90 | } catch (URISyntaxException | IOException ex) { |
92 | 91 | throw new SFException(ex, ErrorCode.NETWORK_ERROR, ex.getMessage()); |
|
0 commit comments