Revision 8959
Added by Jing Tao about 10 years ago
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
3033 | 3033 |
* the server which notify local server the force replication |
3034 | 3034 |
* command |
3035 | 3035 |
*/ |
3036 |
public static String writeReplication(DBConnection conn, String xmlString, |
|
3036 |
public static String writeReplication(DBConnection conn, String xmlString, byte[] xmlBytes,
|
|
3037 | 3037 |
String pub, Reader dtd, String action, String accnum, String user, |
3038 | 3038 |
String[] groups, String homeServer, String notifyServer, |
3039 | 3039 |
String ruleBase, boolean needValidation, String tableName, |
... | ... | |
3095 | 3095 |
isRevision = true; |
3096 | 3096 |
} |
3097 | 3097 |
// detect encoding |
3098 |
XmlStreamReader xsr = new XmlStreamReader(new ByteArrayInputStream(xmlString.getBytes())); |
|
3098 |
//XmlStreamReader xsr = new XmlStreamReader(new ByteArrayInputStream(xmlString.getBytes())); |
|
3099 |
XmlStreamReader xsr = new XmlStreamReader(new ByteArrayInputStream(xmlBytes)); |
|
3099 | 3100 |
String encoding = xsr.getEncoding(); |
3100 | 3101 |
|
3101 | 3102 |
// no need to write the EML-contained access rules for replication |
... | ... | |
3112 | 3113 |
conn.setAutoCommit(true); |
3113 | 3114 |
|
3114 | 3115 |
// Write the file to disk |
3115 |
byte[] bytes = xmlString.getBytes(encoding); |
|
3116 |
writeToFileSystem(bytes, accnum);
|
|
3116 |
//byte[] bytes = xmlString.getBytes(encoding);
|
|
3117 |
writeToFileSystem(xmlBytes, accnum);
|
|
3117 | 3118 |
|
3118 | 3119 |
// write to xml_node complete. start the indexing thread. |
3119 | 3120 |
// this only for xml_documents |
src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java | ||
---|---|---|
64 | 64 |
ruleBase, needValidation, writeAccessRules, xmlBytes); |
65 | 65 |
} |
66 | 66 |
|
67 |
public String writeReplication(DBConnection conn, String xml, String pub, Reader dtd, |
|
67 |
public String writeReplication(DBConnection conn, String xml, byte[]xmlBytes, String pub, Reader dtd,
|
|
68 | 68 |
String action, String accnum, String user, String[] groups, |
69 | 69 |
String homeServer, String notifyServer, Date createDate, Date updateDate) |
70 | 70 |
throws Exception { |
... | ... | |
72 | 72 |
// so rule base is null and need validation is false (first false) |
73 | 73 |
// this method is for force replication. so the table name is xml_documents |
74 | 74 |
// and timed replication is false (last false) |
75 |
return DocumentImpl.writeReplication(conn, xml, pub, dtd, action, accnum, user, |
|
75 |
return DocumentImpl.writeReplication(conn, xml, xmlBytes, pub, dtd, action, accnum, user,
|
|
76 | 76 |
groups, homeServer, notifyServer, ruleBase, false, |
77 | 77 |
DocumentImpl.DOCUMENTTABLE, false, createDate, updateDate); |
78 | 78 |
// last false means is not timed replication |
... | ... | |
96 | 96 |
* @return |
97 | 97 |
* @throws Exception |
98 | 98 |
*/ |
99 |
public String writeReplication(DBConnection conn, String xml, String pub, Reader dtd, |
|
99 |
public String writeReplication(DBConnection conn, String xml, byte[]xmlBytes, String pub, Reader dtd,
|
|
100 | 100 |
String action, String accnum, String user, String[] groups, |
101 | 101 |
String homeServer, String notifyServer, String tableName, |
102 | 102 |
boolean timedReplication, Date createDate, Date updateDate) |
103 | 103 |
throws Exception { |
104 | 104 |
//we don't need to check validation in replication |
105 | 105 |
// so rule base is null and need validation is false |
106 |
return DocumentImpl.writeReplication(conn, xml, pub, dtd, action, accnum, user, |
|
106 |
return DocumentImpl.writeReplication(conn, xml, xmlBytes, pub, dtd, action, accnum, user,
|
|
107 | 107 |
groups, homeServer, notifyServer, ruleBase, false, tableName, |
108 | 108 |
timedReplication, createDate, updateDate); |
109 | 109 |
} |
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java | ||
---|---|---|
364 | 364 |
URL u = new URL(readDocURLString); |
365 | 365 |
|
366 | 366 |
// Get docid content |
367 |
String newxmldoc = ReplicationService.getURLContent(u); |
|
367 |
byte[] xmlBytes = ReplicationService.getURLBytes(u); |
|
368 |
String newxmldoc = new String(xmlBytes, "UTF-8"); |
|
368 | 369 |
// If couldn't get skip it |
369 | 370 |
if ( newxmldoc.indexOf("<error>")!= -1 && newxmldoc.indexOf("</error>")!=-1) |
370 | 371 |
{ |
... | ... | |
444 | 445 |
// Write the document into local host |
445 | 446 |
DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false, false); |
446 | 447 |
String newDocid = wrapper.writeReplication(dbConn, |
447 |
newxmldoc, |
|
448 |
newxmldoc, xmlBytes,
|
|
448 | 449 |
docinfoHash.get("public_access"), |
449 | 450 |
null, /* the dtd text */ |
450 | 451 |
actions, |
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java | ||
---|---|---|
652 | 652 |
URL u = new URL("https://" + server + "?server=" |
653 | 653 |
+ MetacatUtil.getLocalReplicationServerName() + "&action=read&docid=" |
654 | 654 |
+ docid); |
655 |
String xmldoc = ReplicationService.getURLContent(u); |
|
655 |
byte[] xmlBytes = ReplicationService.getURLBytes(u); |
|
656 |
String xmldoc = new String(xmlBytes, "UTF-8"); |
|
656 | 657 |
|
657 | 658 |
// get the document info from server |
658 | 659 |
URL docinfourl = new URL("https://" + server + "?server=" |
... | ... | |
732 | 733 |
DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false, false); |
733 | 734 |
//try this independently so we can set access even if the update action is invalid (i.e docid has not changed) |
734 | 735 |
try { |
735 |
wrapper.writeReplication(dbConn, xmldoc, null, null, |
|
736 |
wrapper.writeReplication(dbConn, xmldoc, xmlBytes, null, null,
|
|
736 | 737 |
dbaction, docid, null, null, homeServer, server, createdDate, |
737 | 738 |
updatedDate); |
738 | 739 |
} finally { |
... | ... | |
2275 | 2276 |
// get the response content |
2276 | 2277 |
InputStream input = getURLStream(u); |
2277 | 2278 |
logReplication.info("ReplicationService.getURLContent - After getting response from: " + u.toString()); |
2278 |
InputStreamReader istream = new InputStreamReader(input); |
|
2279 |
StringBuffer serverResponse = new StringBuffer(); |
|
2280 |
while ((istreamInt = istream.read()) != -1) { |
|
2281 |
istreamChar = (char) istreamInt; |
|
2282 |
serverResponse.append(istreamChar); |
|
2283 |
} |
|
2284 |
istream.close(); |
|
2285 |
input.close(); |
|
2286 |
|
|
2287 |
return serverResponse.toString(); |
|
2279 |
String content = IOUtils.toString(input, "UTF-8"); |
|
2280 |
return content; |
|
2288 | 2281 |
} |
2289 | 2282 |
|
2290 | 2283 |
/** |
... | ... | |
2306 | 2299 |
} |
2307 | 2300 |
|
2308 | 2301 |
/** |
2302 |
* This method returns a byte array after opening a url |
|
2303 |
* @param u the url to return the content from |
|
2304 |
* @return a InputStream representing the content of the url |
|
2305 |
* @throws java.io.IOException |
|
2306 |
*/ |
|
2307 |
public static byte[] getURLBytes(URL u) throws Exception { |
|
2308 |
InputStream input = getURLStream(u); |
|
2309 |
byte[] bytes = IOUtils.toByteArray(input); |
|
2310 |
return bytes; |
|
2311 |
} |
|
2312 |
|
|
2313 |
/** |
|
2309 | 2314 |
* Sets up an HttpClient with SSL connection. |
2310 | 2315 |
* Sends client certificate to the server when doing the request. |
2311 | 2316 |
* @return |
Also available in: Unified diff
During the replication, the remote content will be saved without alteration.