1

I have the following code in groovy

HTTPBuilder http = new HTTPBuilder("https://ronna-afghan.harmonieweb.org/_layouts/searchrss.aspx")



        http.request(Method.GET, groovyx.net.http.ContentType.XML) {

            // set username and password for basic authentication
            // set username and password for basic auth
            //http.auth.basic(ConfigurationHolder.config.passportService.userName,
            //        ConfigurationHolder.config.passportService.password)
            headers.'User-Agent' = 'Mozilla/5.0'

            uri.query = [k:'execution']

            // response handler for a success response code:
            response.success = {resp, xml ->
                println resp.statusLine



                log.debug "response status: ${resp.statusLine}"
                log.debug xml.toString()

            }

            // handler for any failure status code:
            response.failure = {resp ->
                log.error " ${resp.statusLine.statusCode} : ${resp.statusLine.reasonPhrase}"
            }


        }

when I run the code, it doesn't give me the rss feed which I'm suppose to get

When I have the same code in java

try {
            // Create a URLConnection object for a URL
            URL oracle = new URL(
                    "https://ronna-afghan.harmonieweb.org/_layouts/srchrss.aspx?k=execution&count=1&format=rss");

            URLConnection yc = oracle.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    yc.getInputStream()));
            String inputLine;

            while ((inputLine = in.readLine()) != null) {
                System.out.println(inputLine);
                in.close();
            }

        } catch (Exception e) {
            e.printStackTrace();

        }
    }

it returns the xml Rss. I can't figure what the issue might be. Everything looks okay to me in the groovy code and also the Http return code is 200.

allthenutsandbolts
  • 1,513
  • 1
  • 13
  • 34

1 Answers1

3

The code that you have described in Java is the equivalent of the following code in Groovy:

def oracle = "https://ronna-afghan.harmonieweb.org/_layouts/srchrss.aspx?k=execution&count=1&format=rss".toURL().text
Daniel Woods
  • 1,029
  • 7
  • 10
  • Makes sense. Its working now. I had the URL being read from config file and it had an typo in there. Due to which the get was failing. Both the codes are returning correct results. – allthenutsandbolts Feb 21 '12 at 18:16
  • 1
    Would you say the answer provided is an acceptable answer to the question given the question details? :) – Daniel Woods Feb 21 '12 at 19:41