AddTable JAVA » History » Version 1
Tomek Dziemidowicz, 2019-07-18 09:14 PM
1 | 1 | Tomek Dziemidowicz | h1. AddTable JAVA |
---|---|---|---|
2 | |||
3 | <pre><code class="java"> |
||
4 | /** |
||
5 | * Add table to synchronization |
||
6 | * @param tableName table name |
||
7 | * @throws Exception |
||
8 | */ |
||
9 | public void addSynchrnizedTable(String tableName) throws Exception { |
||
10 | HttpURLConnection connection = null; |
||
11 | InputStream resultStream = null; |
||
12 | String resultString = null; |
||
13 | |||
14 | String requestUrl = String.format("%s/AddTable/%s", _serverURL, tableName); |
||
15 | |||
16 | try { |
||
17 | connection = (HttpURLConnection) new URL(requestUrl).openConnection(); |
||
18 | |||
19 | int status = connection.getResponseCode(); |
||
20 | |||
21 | switch (status){ |
||
22 | case HttpURLConnection.HTTP_OK: |
||
23 | resultStream = connection.getInputStream(); |
||
24 | resultString = IOUtils.toString(resultStream, "UTF-8"); |
||
25 | break; |
||
26 | default: |
||
27 | resultStream = connection.getErrorStream(); |
||
28 | resultString = IOUtils.toString(resultStream, "UTF-8"); |
||
29 | throw new Exception(resultString); |
||
30 | } |
||
31 | } |
||
32 | finally { |
||
33 | if (resultStream != null) { |
||
34 | try { |
||
35 | resultStream.close(); |
||
36 | } catch (IOException e) { |
||
37 | } |
||
38 | } |
||
39 | if (connection != null) { |
||
40 | connection.disconnect(); |
||
41 | } |
||
42 | } |
||
43 | } |
||
44 | </code></pre> |