1 4 package com.tc.config.schema.setup.sources; 5 6 import com.tc.config.schema.setup.ConfigurationSetupException; 7 import com.tc.util.Assert; 8 9 import java.io.File ; 10 import java.io.IOException ; 11 import java.io.InputStream ; 12 import java.net.MalformedURLException ; 13 import java.net.URL ; 14 import java.net.URLConnection ; 15 16 21 public class ServerConfigurationSource implements ConfigurationSource { 22 23 private final String host; 24 private final int port; 25 26 public ServerConfigurationSource(String host, int port) { 27 Assert.assertNotBlank(host); 28 Assert.assertTrue(port > 0); 29 this.host = host; 30 this.port = port; 31 } 32 33 public InputStream getInputStream(long maxTimeoutMillis) throws IOException , ConfigurationSetupException { 34 try { 35 URL theURL = new URL ("http", host, port, "/config"); 36 37 System.setProperty("sun.net.client.defaultConnectTimeout", String.valueOf(maxTimeoutMillis)); 39 System.setProperty("sun.net.client.defaultReadTimeout", String.valueOf(maxTimeoutMillis)); 40 41 URLConnection connection = theURL.openConnection(); 42 return connection.getInputStream(); 43 } catch (MalformedURLException murle) { 44 throw new ConfigurationSetupException("Can't load configuration from "+this+"."); 45 } 46 } 47 48 public File directoryLoadedFrom() { 49 return null; 50 } 51 52 public boolean isTrusted() { 53 return true; 54 } 55 56 public String toString() { 57 return "server at '" + this.host + ":" + this.port + "'"; 58 } 59 60 } 61 | Popular Tags |