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?
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.
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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With