Using Protégé through an authenticated proxy
I recently struggled with Protégé in order to make it work through an authenticated enterprise proxy, since I wanted to import / extend ontologies from the Web.
When running a Java application, you can pass it the URL of a proxy, but it seems the only way to setup authentication parameters is to modify original source code. I agree a plugin is certainly better, but I don’t have time to invest it, so here’s a simple hack to make Protégé-OWL work with such a proxy.
- First, create a new directory and checkout Protégé-OWL SVN source code.
mkdir protege-owl cd protege-owl svn checkout http://smi-protege.stanford.edu/repos/protege/owl/trunk .
You’ll also need to get the protege.jar file, that can be downloaded here, and move it to the /libs folder.
- Edit
src/edu/stanford/smi/protegex/owl/jena/parser/ProtegeOWLParser.java
Add the following import:
import java.util.Properties;
In getInputStream method, replace
conn.addRequestProperty("Accept", "*/*");
return conn.getInputStream();
By
conn.addRequestProperty("Accept", "*/*");
// Set proxy settings only if the file is outside our domain
if(url.getHost().indexOf("company.host.tld")==-1) {
Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost","proxy_URL");
systemSettings.put("http.proxyPort", "proxy_Port");
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
String encodedUserPwd = encoder.encode("proxy_User:proxy_Pass".getBytes());
conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPwd);
}
return conn.getInputStream();
- Edit
src/edu/stanford/smi/protegex/owl/ui/metadatatab/imports/wizard/URLImportEntry.java
Add the following imports:
import java.util.Properties; import java.io.InputStream; import java.net.URLConnection;
In isPossibleToImport() method, replace:
OntologyNameExtractor extractor = new OntologyNameExtractor(url.openConnection().getInputStream(), url); URI uri = extractor.getOntologyName();
By:
OntologyNameExtractor extractor;
// Set proxy settings only if the file is outside our domain
if(url.getHost().indexOf("edf.fr")==-1) {
URLConnection conn = url.openConnection();
conn.setRequestProperty("Accept", "application/rdf+xml");
conn.addRequestProperty("Accept", "text/xml");
conn.addRequestProperty("Accept", "*/*");
Properties systemSettings = System.getProperties();
systemSettings.put("http.proxyHost","proxy_URL");
systemSettings.put("http.proxyPort", "proxy_Port");
sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder();
String encodedUserPwd = encoder.encode("proxy_User:proxy_Pass".getBytes());
conn.setRequestProperty("Proxy-Authorization", "Basic " + encodedUserPwd);
InputStream stream = conn.getInputStream();
extractor = new OntologyNameExtractor(stream, url);
} else {
extractor = new OntologyNameExtractor(url.openConnection().getInputStream(), url);
}
URI uri = extractor.getOntologyName();
- Compile with
ant(eitherant plugin.jarorant plugin.zip), and replace the originaledu.stanford.smi.protegex.owlfolder by the new one that will be created in the/distsfolder (in.jaror.zipformat).
- Run Protégé, you should be able to import / load both internal and external ontologies trough your proxy !
