Revision 9156
Added by rnahf over 9 years ago
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java | ||
---|---|---|
43 | 43 |
import java.util.TimerTask; |
44 | 44 |
import java.util.Vector; |
45 | 45 |
|
46 |
import org.apache.commons.io.IOUtils; |
|
46 | 47 |
import org.apache.log4j.Logger; |
47 | 48 |
import org.dataone.service.types.v2.SystemMetadata; |
48 | 49 |
import org.dataone.service.util.DateTimeMarshaller; |
... | ... | |
259 | 260 |
"because "+ e.getMessage()); |
260 | 261 |
continue; |
261 | 262 |
} |
263 |
finally |
|
264 |
{ |
|
265 |
IOUtils.closeQuietly(responses.elementAt(i)); |
|
266 |
} |
|
262 | 267 |
//v is the list of updated documents |
263 | 268 |
Vector<Vector<String>> updateList = new Vector<Vector<String>>(message.getUpdatesVect()); |
264 | 269 |
logReplication.info("ReplicationHandler.update - The document list size is "+updateList.size()+ " from "+message.getServerName()); |
... | ... | |
558 | 563 |
logReplication.info("ReplicationHandler.handleSingleDataFile - Try to replicate data file: " + accNumber); |
559 | 564 |
DBConnection dbConn = null; |
560 | 565 |
int serialNumber = -1; |
566 |
InputStream input = null; |
|
561 | 567 |
try |
562 | 568 |
{ |
563 | 569 |
// Get DBConnection from pool |
... | ... | |
621 | 627 |
"&action=readdata&docid="+accNumber; |
622 | 628 |
readDataURLString = MetacatUtil.replaceWhiteSpaceForURL(readDataURLString); |
623 | 629 |
URL u = new URL(readDataURLString); |
624 |
InputStream input = ReplicationService.getURLStream(u);
|
|
630 |
input = ReplicationService.getURLStream(u); |
|
625 | 631 |
//register data file into xml_documents table and wite data file |
626 | 632 |
//into file system |
627 | 633 |
if ( input != null) |
... | ... | |
720 | 726 |
} |
721 | 727 |
finally |
722 | 728 |
{ |
729 |
IOUtils.closeQuietly(input); |
|
723 | 730 |
//return DBConnection |
724 | 731 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
732 |
|
|
733 |
|
|
725 | 734 |
}//finally |
726 | 735 |
logMetacat.info("replication.create localId:" + accNumber); |
727 | 736 |
} |
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java | ||
---|---|---|
2281 | 2281 |
char istreamChar; |
2282 | 2282 |
int istreamInt; |
2283 | 2283 |
// get the response content |
2284 |
InputStream input = getURLStream(u); |
|
2285 |
logReplication.info("ReplicationService.getURLContent - After getting response from: " + u.toString()); |
|
2286 |
String content = IOUtils.toString(input, "UTF-8"); |
|
2284 |
InputStream input = null; |
|
2285 |
String content = null; |
|
2286 |
try { |
|
2287 |
input = getURLStream(u); |
|
2288 |
logReplication.info("ReplicationService.getURLContent - After getting response from: " + u.toString()); |
|
2289 |
content = IOUtils.toString(input, "UTF-8"); |
|
2290 |
} |
|
2291 |
finally { |
|
2292 |
IOUtils.closeQuietly(input); |
|
2293 |
} |
|
2287 | 2294 |
return content; |
2288 | 2295 |
} |
2289 | 2296 |
|
... | ... | |
2332 | 2339 |
* @throws java.io.IOException |
2333 | 2340 |
*/ |
2334 | 2341 |
public static byte[] getURLBytes(URL u) throws Exception { |
2335 |
InputStream input = getURLStream(u); |
|
2336 |
byte[] bytes = IOUtils.toByteArray(input); |
|
2337 |
return bytes; |
|
2342 |
InputStream input = null; |
|
2343 |
try { |
|
2344 |
input = getURLStream(u); |
|
2345 |
byte[] bytes = IOUtils.toByteArray(input); |
|
2346 |
return bytes; |
|
2347 |
} |
|
2348 |
finally { |
|
2349 |
IOUtils.closeQuietly(input); |
|
2350 |
} |
|
2338 | 2351 |
} |
2339 | 2352 |
|
2340 | 2353 |
/** |
Also available in: Unified diff
ReplicationServices.getUrlStream(url) callers were not closing the inputstream properly, as was revealed when switching to libclient v2 (a pooling connection manager in HttpClient) and encountering reasource leaks.