Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Strange URLConnection behavior

1 view
Skip to first unread message

SteveV

unread,
Feb 7, 2009, 8:08:11 PM2/7/09
to
Can anyone please give me a clue why this might be happening?
I have a simple method called doXmlRequest.It calls a URL returning an
XML Document.

public static Document doXmlRequest(String url){
Document doc = null;
try {
URL urlReq = new URL(url);
URLConnection conn = urlReq.openConnection();
BufferedInputStream bfrinput = new BufferedInputStream
(conn.getInputStream());
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse
(bfrinput);
bfrinput.close();
} catch (Exception e) {
e.printStackTrace();
}
return doc;
}

Now, there werid thing is... have two URLs, say urlGood & urlBad. I
can do any of the following sequential calls:

//This works
doXmlRequest(urlGood);
doXmlRequest(urlGood);

//This works
doXmlRequest(urlBad);
doXmlRequest(urlGood);

//This works
doXmlRequest(urlBad);
doXmlRequest(urlBad);

However... the following call will return the error below

doXmlRequest(urlGood);
doXmlRequest(urlBad); //<< This line blows up

org.xml.sax.SAXParseException: XML document structures must start and
end within the same entity.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse
(DOMParser.java:239)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse
(DocumentBuilderImpl.java:283)
at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:124)
at RTMtest.doXmlRequest(RTMtest.java:34)


Can anyone see any reason why this would happen?
I can't understand why the calls would work individually, but not in
that order.
The only difference between urlGood & urlBad I can think of is that
urlBad returns a larger result.

Thanks for any help, Steve V

Andrew Thompson

unread,
Feb 8, 2009, 8:52:02 PM2/8/09
to
On Feb 8, 12:08 pm, SteveV <sav74...@gmail.com> wrote:
> Can anyone please give me a clue why this might be happening?
>...

> Now, there werid thing is...  have two URLs, say urlGood & urlBad.

An SSCCE 'says' most things better.

--
Andrew T.

Roedy Green

unread,
Feb 14, 2009, 10:48:04 PM2/14/09
to
On Sat, 7 Feb 2009 17:08:11 -0800 (PST), SteveV <sav7...@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>URL urlReq = new URL(url);

What are you feeding this thing as an URL?
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Here is a point of no return after which warming becomes unstoppable
and we are probably going to sail right through it.
It is the point at which anthropogenic (human-caused) warming triggers
huge releases of carbon dioxide from warming oceans, or similar releases
of both carbon dioxide and methane from melting permafrost, or both.
Most climate scientists think that point lies not far beyond 2蚓 (4蚌) C hotter."
~ Gwynne Dyer

Jan Thomä

unread,
Feb 18, 2009, 6:40:35 PM2/18/09
to
On 2009-02-08 02:08:11 +0100, SteveV <sav7...@gmail.com> said:

> doXmlRequest(urlGood);
> doXmlRequest(urlBad); //<< This line blows up

I assume that these Urls somehow affect each other and calling them in
a certain order does not produce valid XML. Without knowing the URLs
its hard to tell. If it's not HTTPs you can use a network sniffer like
Wireshark to see what is going over the network line. Or you just print
out what you got from that input stream. I assume calling badUrl after
goodUrl produces some server side error and this yields an unparseable
response...

Jan

0 new messages