2014-04-17 72 views
2

我解決RDF中的URI使用耶拿一個Servlet:如何在從URI檢索RDF時設置HTTP超時?

final Model rdfModel = ModelFactory.createDefaultModel(); 
rdfModel.read(resource); 

是否有設置HTTP連接和Socket耶拿超時的可能性?

或者是做「人工」處理HTTP連接使用Apache的HttpClient唯一的選擇?

final HttpClient httpclient = new DefaultHttpClient(); 
final HttpParams params = httpclient.getParams(); 
params.setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 1000); 
params.setParameter(HttpConnectionParams.SO_TIMEOUT, 5000); 
... 

回答

2

這裏的基礎上@搶大廳的提示代碼:

final Model rdfModel = ModelFactory.createDefaultModel(); 
final HttpClient httpclient = new DefaultHttpClient(); 
final HttpParams params = httpclient.getParams(); 
params.setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, 1000); 
params.setParameter(HttpConnectionParams.SO_TIMEOUT, 5000); 
HttpOp.setDefaultHttpClient(httpclient); 
rdfModel.read(resource); 
+0

是啊,我剛纔應該把解決方案代碼在我的回答結束。 –