bug-wget
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-wget] Scheme missing error from Java program


From: Marc Stein
Subject: [Bug-wget] Scheme missing error from Java program
Date: Fri, 25 Mar 2016 22:57:29 +0000

Howdy,

I'm using wget to down report files from an Oracle CRMOD Report Server. When I 
use the command from Windows Powershell it works fine, but when I make the 
exact same call from a Java program I get the scheme missing error. I 
downloaded wget 1.17.1-win64. I'm using Java version 1.7.0_51.

I have a login URL which works fine from both Powershell and the program, but 
the report download command works from Powershell and fails in the program. 
Here's the command:

wget --no-check-certificate --load-cookie "cookiefile.txt" --output-document 
"C:\Users\Hal\OpptyAnalysis.pdf" 
'https://secure-ausomxesa.crmondemand.com/OnDemand/user/ReportService?Method=ReportExecute&Path=OpptyAnalysis&Format=pdf&Refresh=Y'
 --max-redirect=100

Here is what is logged in the log file. The first line is the text of the 
command written out as a string for comparison to the text used in Powershell:

wget --no-check-certificate --load-cookie "cookiefile.txt" --output-document 
"C:\Users\Hal\OpptyAnalysis.pdf" 
'https://secure-ausomxesa.crmondemand.com/OnDemand/user/ReportService?Method=ReportExecute&Path=OpptyAnalysis&Format=pdf&Refresh=Y'
 --max-redirect=100

ERR>'https://secure-ausomxesa.crmondemand.com/OnDemand/user/ReportService?Method=ReportExecute&Path=OpptyAnalysis&Format=pdf&Refresh=Y':
 Scheme missing.
ExitValue: 1
Here is the code used for the program:
package reports;

import java.util.*;
import java.io.*;
import java.io.InputStream;
import java.io.OutputStream;

public class Distribute {

    //Constructor
    public Distribute() {
        super();
    }

    public static void main(String args[])
    {
        Distribute d = new Distribute();
        try
        {
            Login("IIE_CTE02/MSTEIN", "xxxxxxxx");
            Thread.sleep(1000);
            GetReport();
            Logout();
        }
        catch (Throwable t)
        {
            t.printStackTrace();
        }
}

    //Login function
    public static void Login(String username, String password)
    {
        try
        {
            String cmd = "wget --no-check-certificate 
--user-agent=\"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 
Firefox/17.0\" --keep-session-cookies --save-cookies \"cookiefile.txt\" 
--post-data \"j_username=" + username + "&j_password=" + password + 
"&langCode=ENU\" 
https://secure-ausomxesa.crmondemand.com/OnDemand/authenticate";;
            //System.out.println(cmd);
            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec(cmd);

            // any error message?
            StreamGobbler errorGobbler = new
                StreamGobbler(proc.getErrorStream(), "ERR");

            // any output?
            StreamGobbler outputGobbler = new
                StreamGobbler(proc.getInputStream(), "OUT");

            // kick them off
            errorGobbler.start();
            outputGobbler.start();

            // any error???
            int exitVal = proc.waitFor();
            System.out.println("ExitValue: " + exitVal);
        }
        catch (Throwable t)
        {
            t.printStackTrace();
        }
    }

    //Get Report
    public static void GetReport()
    {
        int exitVal = 5;
        //Try to get the report 3 times
        for (int count = 0; count < 3; count++)
        {
            if(exitVal == 0) break;
            try
            {
                String cmd = "wget --no-check-certificate --load-cookie 
\"cookiefile.txt\" --output-document \"C:\\Users\\Hal\\OpptyAnalysis.pdf\" 
'https://secure-ausomxesa.crmondemand.com/OnDemand/user/ReportService?Method=ReportExecute&Path=OpptyAnalysis&Format=pdf&Refresh=Y'
 --max-redirect=100";
                System.out.println("");
                System.out.println("Report: " + cmd);
                System.out.println("");
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec(cmd);

                // any error message?
                StreamGobbler errorGobbler = new
                    StreamGobbler(proc.getErrorStream(), "ERR");

                // any output?
                StreamGobbler outputGobbler = new
                    StreamGobbler(proc.getInputStream(), "OUT");

                // kick them off
                errorGobbler.start();
                outputGobbler.start();

                // any error???
                exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);
            }
            catch (Throwable t)
            {
                t.printStackTrace();
            }
        }
    }

    //Logout function
    public static void Logout()
    {
        try
        {
            String cmd = "wget --no-check-certificate --load-cookie 
\"cookiefile.txt\" 
https://secure-ausomxesa.crmondemand.com/OnDemand/logoff.jsp";;
            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec(cmd);

            // any error message?
            StreamGobbler errorGobbler = new
                StreamGobbler(proc.getErrorStream(), "ERR");

            // any output?
            StreamGobbler outputGobbler = new
                StreamGobbler(proc.getInputStream(), "OUT");

            // kick them off
            errorGobbler.start();
            outputGobbler.start();

            // any error???
            int exitVal = proc.waitFor();
            System.out.println("ExitValue: " + exitVal);
        }
        catch (Throwable t)
        {
            t.printStackTrace();
        }
    }

    private static class StreamGobbler extends Thread
    {
        InputStream is;
        String type;
        OutputStream os;

        StreamGobbler(InputStream is, String type)
        {
            this(is, type, null);
        }

        StreamGobbler(InputStream is, String type, OutputStream redirect)
        {
            this.is = is;
            this.type = type;
            this.os = redirect;
        }

        public void run()
        {
            try
            {
                PrintWriter pw = null;
                if (os != null)
                    pw = new PrintWriter(os);

                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line = null;
                while ((line = br.readLine()) != null) {
                    if (pw != null)
                        pw.println(line);
                    System.out.println(type + ">" + line);
                }
                if (pw != null)
                    pw.flush();
            }
            catch (IOException ioe)
            {
                ioe.printStackTrace();
            }
        }
    }
}

Any help with this would be greatly appreciated.

Thanks, Marc


Marc Stein | CRM Technical Development
[Apex Logo]<http://www.apexit.com/>
*: 719.351.8578  *: address@hidden

PNG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]