Changeset 31776


Ignore:
Timestamp:
07/05/17 20:43:44 (3 years ago)
Author:
ak19
Message:

Kathy described a problem on the mailing list about the AutoLoadConverters msg appearing before XML content when connecting with a client-GLI to a remote GS3, which breaks parsing of the XML. (I found it was present in my GS3 installation from 4 May 2016.) I've narrowed it down to running client-gli with the debug flag turned on, which seemed related to the same problem I'd seen when running gli -debug after the change to SafeProcess in Plugins.java, which I fixed by removing lines preceding XML content before parsing the XML. For client-gli, SafeProcess isn't used which is also why the problem with client-gli is much older, but I'm now using a common and existing solution for both: doing what Plugins.java used to do before the change to SafeProcess, which is call XMLTools.readXMLStream(), which would parse out content before XML. The RemoteGreenstoneServer should only call this method if it actually has some XML content it's dealing with. Could have solved this in RemoteGreenstoneServerAction.java's GetScriptOptions, but am solving it in RemoteGreenstoneServer's sendCommandToServerInternal, since there may be many Actions returning XML, not just GetScriptOptions.

Location:
main/trunk/gli/src/org/greenstone/gatherer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/greenstone/Plugins.java

    r31641 r31776  
    165165        // Create the process.
    166166        SafeProcess process = new SafeProcess((String[]) args.toArray(new String[] { }));
     167        process.setSplitStdErrorNewLines(true);
    167168
    168169        // run the SafeProcess
     
    174175        // get the result: We expect XML to have come out of the process std error stream.
    175176        pluginfo_xml = process.getStdError();
     177        // make sure to have parsed out any lines preceding the XML content
     178        pluginfo_xml = XMLTools.readXMLStream(pluginfo_xml).toString();
    176179        ///System.err.println("*********\nPluginInfo, got:\n" + pluginfo_xml + "\n**********\n");
    177180        }
     
    236239        args.add("-listall");
    237240        args.add("-xml");
    238 
     241       
    239242        // Run the pluginfo.pl process:
    240243        // Create the process.
    241244        SafeProcess process = new SafeProcess((String[]) args.toArray(new String[] { }));
     245        process.setSplitStdErrorNewLines(true);
    242246
    243247        // run the SafeProcess
     
    249253        // get the result: We expect XML to have come out of the process std error stream. 
    250254        xml = process.getStdError();
    251 
     255        // make sure to parse out any lines before the XML content, else running "gli -debug" results in an XML error:
    252256        // for pluginfo.pl -listall, we see a "AutoloadConverters" (PDFBox) message
    253         // before actual XML output, which breaks XML parsing. Get rid of output before "<?xml"
    254         int startIndex = xml.indexOf("<?xml");
    255         if(startIndex != 0) {
    256             xml = xml.substring(startIndex);
    257         }
     257        // before actual XML output, which breaks XML parsing.
     258        // This gets rid of output before "<?xml" in the way that the code did before the change to SafeProcess
     259        // Then we can call the same from method RemoteGreenstoneServer.java, so that running "client-gli -debug"
     260        // will work too.
     261        xml = XMLTools.readXMLStream(xml).toString();
     262       
    258263        ///System.err.println("*********\nPluginsList, got:\n" + xml + "\n**********\n");
    259264        }
  • main/trunk/gli/src/org/greenstone/gatherer/remote/RemoteGreenstoneServer.java

    r22692 r31776  
    4444import org.greenstone.gatherer.util.UnzipTools;
    4545import org.greenstone.gatherer.util.Utility;
     46import org.greenstone.gatherer.util.XMLTools;
    4647import org.apache.commons.httpclient.HttpClient;
    4748import org.apache.commons.httpclient.methods.PostMethod;
     
    682683    gliserver_in.close();
    683684
     685   
     686    int startIndex = command_output_buffer.indexOf("<?xml");
     687    if(startIndex > 0) { // not -1, so "<?xml" is present, and not 0, so not at start
     688
     689        // iff dealing with XML, make sure to parse out any lines preceding the XML content
     690        command_output_buffer = XMLTools.readXMLStream(command_output_buffer.toString());
     691        /*if(DebugStream.isDebuggingEnabled()) {
     692        String prefix = command_output_buffer.substring(0, startIndex);
     693        DebugStream.println("Removing the following found before start of XML:");
     694        DebugStream.println("---------------------------------");
     695        DebugStream.println(prefix);
     696        DebugStream.println("---------------------------------");
     697        }
     698        // remove the prefix
     699        return command_output_buffer.substring(startIndex); // remove anything before the start of XML
     700        */
     701    }
     702   
    684703    return command_output_buffer.toString();
    685704    }
  • main/trunk/gli/src/org/greenstone/gatherer/util/XMLTools.java

    r30869 r31776  
    733733    static public StringBuffer readXMLStream(InputStream input_stream)
    734734    {
     735        StringBuffer xml = new StringBuffer("");
     736        try {
     737        InputStreamReader isr = new InputStreamReader(input_stream, "UTF-8");
     738        xml = XMLTools.readXMLStream(new InputStreamReader(input_stream, "UTF-8"));
     739        } catch (UnsupportedEncodingException error) {
     740        System.err.println("Failed when trying to parse XML stream");
     741        error.printStackTrace();
     742        }
     743       
     744        return xml;
     745    }
     746
     747    static public StringBuffer readXMLStream(String s) {
     748    return XMLTools.readXMLStream(new StringReader(s));
     749    }
     750
     751
     752    static public StringBuffer readXMLStream(Reader reader)
     753    {
    735754        StringBuffer xml = new StringBuffer("");
    736755
    737756        try
    738757        {
    739             InputStreamReader isr = new InputStreamReader(input_stream, "UTF-8");
    740             BufferedReader buffered_in = new BufferedReader(isr);
     758            BufferedReader buffered_in = new BufferedReader(reader);
    741759
    742760            String line = "";
Note: See TracChangeset for help on using the changeset viewer.