Changeset 404:c71b73a9271b
- Timestamp:
- 09/17/09 10:36:43 (4 years ago)
- Author:
- tgambet
- Branch:
- default
- convert_revision:
- svn:cdcfb263-7567-472c-a848-e2c2df3466e7/trunk@405
- Message:
-
test connection exceptions
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r223
|
r404
|
|
| 1 | 1 | package org.w3c.unicorn; |
| 2 | 2 | |
| 3 | | import java.util.Locale; |
| | 3 | import java.io.FileNotFoundException; |
| | 4 | import java.io.IOException; |
| | 5 | import java.net.ConnectException; |
| | 6 | import java.net.HttpURLConnection; |
| | 7 | import java.net.MalformedURLException; |
| | 8 | import java.net.SocketTimeoutException; |
| | 9 | import java.net.URL; |
| | 10 | import java.net.URLConnection; |
| | 11 | import java.net.UnknownHostException; |
| | 12 | |
| | 13 | import javax.net.ssl.SSLException; |
| | 14 | |
| | 15 | //import sun.net.www.protocol.http.HttpURLConnection; |
| | 16 | |
| | 17 | |
| 4 | 18 | |
| 5 | 19 | public class Test { |
| … |
… |
|
| 7 | 21 | /** |
| 8 | 22 | * @param args |
| | 23 | * @throws MalformedURLException |
| 9 | 24 | */ |
| 10 | 25 | public static void main(String[] args) { |
| … |
… |
|
| 27 | 42 | //replaceAll(repl)*/ |
| 28 | 43 | |
| 29 | | Locale loc = new Locale("sssqn"); |
| 30 | | |
| 31 | | System.out.println("z" + loc.getLanguage()); |
| | 44 | URL docUrl = null; |
| | 45 | try { |
| | 46 | docUrl = new URL("http://www.w3.org:9788"); |
| | 47 | //docUrl = new URL("http://qa-dev.w3.org/app"); |
| | 48 | //docUrl = new URL("http://www.w3.org/Team"); |
| | 49 | //docUrl = new URL("http://snowball.w3.org/unicorn/observe?ucn_uri=beta.w3.org&ucn_task=conformance"); |
| | 50 | //System.out.println(docUrl.getContent().toString()); |
| | 51 | //System.out.println(docUrl2.getContent().toString().length()); |
| | 52 | URLConnection con = docUrl.openConnection(); |
| | 53 | System.out.println(con.getConnectTimeout()); |
| | 54 | con.setConnectTimeout(1000); |
| | 55 | con.setReadTimeout(1000); |
| | 56 | con.getContent(); |
| | 57 | } catch (MalformedURLException e) { |
| | 58 | e.printStackTrace(); |
| | 59 | } catch (ConnectException e) { |
| | 60 | e.printStackTrace(); |
| | 61 | } catch (FileNotFoundException e) { |
| | 62 | e.printStackTrace(); |
| | 63 | } catch (UnknownHostException e) { |
| | 64 | e.printStackTrace(); |
| | 65 | } catch (SSLException e) { |
| | 66 | e.printStackTrace(); |
| | 67 | } catch (SocketTimeoutException e) { |
| | 68 | e.printStackTrace(); |
| | 69 | if (e.getMessage().contains("Read timed out")) |
| | 70 | System.out.println("a"); |
| | 71 | if (e.getMessage().contains("connect timed out")) |
| | 72 | System.out.println("b"); |
| | 73 | } catch (IOException e) { |
| | 74 | try { |
| | 75 | int responseCode; |
| | 76 | if (docUrl != null) { |
| | 77 | responseCode = ((HttpURLConnection) docUrl.openConnection()).getResponseCode(); |
| | 78 | switch (responseCode) { |
| | 79 | case HttpURLConnection.HTTP_UNAUTHORIZED: |
| | 80 | System.out.println("HTTP_UNAUTHORIZED"); |
| | 81 | break; |
| | 82 | } |
| | 83 | } |
| | 84 | } catch (Exception e2) { |
| | 85 | System.out.println("e2"); |
| | 86 | e2.printStackTrace(); |
| | 87 | } |
| | 88 | e.printStackTrace(); |
| | 89 | } |
| 32 | 90 | } |
| 33 | 91 | |