monitorUrl– http://host03:8810/solr/admin/stats.jsp which contains this xml file.
<?xml-stylesheet type="text/xsl" href="stats.xsl"?>
<solr>
<core></core>
<schema>test</schema>
<host>domain.host.com</host>
<now>Fri Nov 11 11:14:01 PST 2011</now>
<start>Thu Sep 22 18:33:06 PDT 2011</start>
<solr-info>
<CORE>
<entry>
<name>
core
</name>
<class>
</class>
<version>
1.0
</version>
<description>
SolrCore
</description>
<stats>
<stat name="coreName" >
</stat>
<stat name="startTime" >
Thu Sep 22 18:33:06 PDT 2011
</stat>
<stat name="refCount" >
2
</stat>
<stat name="aliases" >
[]
</stat>
</stats>
</entry>
<entry>
<name>
searcher
</name>
<class>
org.apache.solr.search.SolrIndexSearcher
</class>
<version>
1.0
</version>
<description>
index searcher
</description>
<stats>
<stat name="searcherName" >
Searcher@5b637a2d main
</stat>
<stat name="caching" >
true
</stat>
<stat name="numDocs" >
111959
</stat>
<stat name="maxDoc" >
112310
</stat>
<stat name="reader" >
DirectoryReader(segments_h0 _1zn:Cv101710/351 _1zl:Cv8026 _1zp:Cv2574)
</stat>
<stat name="readerDir" >
org.apache.lucene.store.NIOFSDirectory@/es_idx_prd/projects/index/solr-agile/document/data/index lockFactory=org.apache.lucene.store.NativeFSLockFactory@2c164804
</stat>
<stat name="indexVersion" >
1313979005459
</stat>
<stat name="openedAt" >
Fri Nov 11 11:00:04 PST 2011
</stat>
<stat name="registeredAt" >
Fri Nov 11 11:00:04 PST 2011
</stat>
<stat name="warmupTime" >
0
</stat>
</stats>
</entry>
</solr-info>
</solr>
And I want to extract the numDocs value from the above xml means 111959–
111959
And the below fetchlog method is just reading each line of that jsp file. So how can I retrieve numDocs value by fetching it directly by reading it line by line.
The monitorUrl is a .jsp file which is in xml format.
public void fetchlog() {
InputStream is = null;
FileOutputStream fos = null;
try {
is = HttpUtil.getFile(monitorUrl);
BufferedReader in =
new BufferedReader (new InputStreamReader (is));
String line;
while ((line = in.readLine()) != null) {
if(line.contains("numDocs")) {
//Extract numDocs value- How to do this?
}
System.out.println(line);
}
fos = new FileOutputStream(buildTargetPath());
IOUtils.copy(is, fos);
} catch (FileNotFoundException e) {
log.error("File Exception in fetching monitor logs :" + e);
} catch (IOException e) {
log.error("Exception in fetching monitor logs :" + e);
}
}
To follow up on my comments, if the XML/text structure is going to be the same, then you can do,