Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection refused: connect while parsing xml with groovy

Tags:

xml

groovy

I have the following xml snippet:

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">
 <sqlMap namespace="reports">

   <typeAlias alias="Header" type="VerificationVO"/>
  </sqlMap>

While trying to parse this xml using:

def sqlMapOld = new XmlParser().parse(file)

I get the following error:

Exception thrown: Connection refused: connect
java.net.ConnectException: Connection refused: connect

This error goes away if I remove the DOCTYPE from the xml snippet. Is there a way to stop groovy script from trying to connect to the URL?

like image 771
Drake Avatar asked Sep 23 '09 20:09

Drake


People also ask

How do I resolve Java net ConnectException Connection refused Connection refused?

ConnectException: Connection refused: 1) First try to ping the destination host, if the host is ping-able it means the client and server machine are in the network. 2) Try connecting to server host and port using telnet. If you are able to connect means something is wrong with your client code.

How do I fix Java net ConnectException?

Q5. How do you handle Java net ConnectException connection refused? Ans: To resolve the Java net error, first try to ping the destination host, if you are able to ping the host means the client and server machine are in the proper network. Your next step should be connecting to the server host and port using telnet.

What does Java net ConnectException Connection refused mean?

Below are some of the possible reason why java.net.ConnectException: Connection refused comes: 1) Client and Server, either or both of them are not in the network. 2) Server is not running. The second most common reason is the server is down and not running.

What is connection exception?

Class ConnectException Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the connection was refused remotely (e.g., no process is listening on the remote address/port).


1 Answers

If you're using an appropriate parser, try the load-external-dtd feature.

def parser= new XmlParser()
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
def sqlMapOld= parser.parse(new FileInputStream(file))

Otherwise I think you'd have to set an EntityResolver that does nothing.

like image 145
bobince Avatar answered Oct 14 '22 04:10

bobince