Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions src/com/docuware/dev/Extensions/PlatformClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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));
Expand All @@ -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
Expand Down