diff --git a/src/com/docuware/dev/Extensions/PlatformClient.java b/src/com/docuware/dev/Extensions/PlatformClient.java index aca91f9..e358678 100644 --- a/src/com/docuware/dev/Extensions/PlatformClient.java +++ b/src/com/docuware/dev/Extensions/PlatformClient.java @@ -13,9 +13,9 @@ import com.sun.jersey.client.apache.config.ApacheHttpClientConfig; import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig; import com.sun.jersey.multipart.impl.MultiPartWriter; -import java.io.File; -import java.io.FileInputStream; + import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.util.Properties; import java.util.logging.Level; @@ -92,11 +92,19 @@ ApacheHttpClient createApacheClientDefault(ServiceConnectionTransportData sctd, * @return the ApacheHttpClient */ ApacheHttpClient createApacheClient(ServiceConnectionTransportData sctd, String baseUri, ClientConfig cc) { - try { - config.load(new FileInputStream(new File("src/com/docuware/dev/Extensions/config.properties"))); - } catch (IOException ex) { - Logger.getLogger(PlatformClient.class.getName()).log(Level.INFO, null, ex); - } + final String applicationName; + final String version; + final String platformClientRequestTimeout; + + // load default properties + readConfigFromClasspath("/docuware-config-default.properties"); + // allow user to override default + readConfigFromClasspath("/docuware-config.properties"); + + platformClientRequestTimeout = config.getProperty("PlatformClientRequestTimeout", "60"); + applicationName = config.getProperty("name", "PlatformJavaClient"); + version = config.getProperty("version", "Hawk"); + // Initialize the HTTP client ApacheHttpClient localClient = ApacheHttpClient.create(cc); if (sctd != null) { @@ -114,19 +122,11 @@ ApacheHttpClient createApacheClient(ServiceConnectionTransportData sctd, String @Override public ClientResponse handle(ClientRequest cr) throws ClientHandlerException { cr.getHeaders().add(HttpHeaders.USER_AGENT, System.getProperty("java.specification.name").replace("Specification", "").trim().replace(" ", "+")+"/"+System.getProperty("java.version")); - cr.getHeaders().add(HttpHeaders.USER_AGENT, config.getProperty("name")+"/"+config.getProperty("version")); + cr.getHeaders().add(HttpHeaders.USER_AGENT, applicationName + "/" + version); return getNext().handle(cr); } }); - String platformClientRequestTimeout = null; - try { - platformClientRequestTimeout = config.getProperty("PlatformClientRequestTimeout"); - } catch (Exception ex) { - Logger.getLogger(PlatformClient.class.getName()).log(Level.INFO, null, ex); - } - if(platformClientRequestTimeout == null){ - platformClientRequestTimeout = "60"; - } + localClient.setReadTimeout(Integer.parseInt(platformClientRequestTimeout)*1000); localClient.setConnectTimeout(Integer.parseInt(platformClientRequestTimeout)*1000); // localClient.addFilter(new LoggingFilter(System.out)); @@ -136,6 +136,23 @@ public ClientResponse handle(ClientRequest cr) throws ClientHandlerException { return localClient; } + /** + * Search on the classpath root if there is a docuware-config-default.properties file and load it info the config field + * @param configFileName + */ + private void readConfigFromClasspath(String configFileName) { + try { + InputStream configStream = getClass().getResourceAsStream(configFileName); + if (configStream != null) { + config.load(configStream); + } else { + Logger.getLogger(PlatformClient.class.getName()).log(Level.INFO, configFileName + " file not found on classpath, default values are applied."); + } + } catch (IOException ex) { + Logger.getLogger(PlatformClient.class.getName()).log(Level.INFO, configFileName + " could not be read, default values are applied.", ex); + } + } + /** * Creates a ApacheHttpClient from an ApacheHttpClientHandler * Be Aware that the clientHandler must hold all information to connect, to make the ApacheHttpClient work diff --git a/src/com/docuware/dev/Extensions/config.properties b/src/docuware-config-default.properties similarity index 100% rename from src/com/docuware/dev/Extensions/config.properties rename to src/docuware-config-default.properties