连接被拒绝:使用groovy解析xml时连接

Dra*_*ake 5 xml groovy

我有以下xml片段:

<?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>
Run Code Online (Sandbox Code Playgroud)

在尝试使用以下方法解析此xml时:

def sqlMapOld = new XmlParser().parse(file)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Exception thrown: Connection refused: connect
java.net.ConnectException: Connection refused: connect
Run Code Online (Sandbox Code Playgroud)

如果我从xml片段中删除DOCTYPE,则此错误消失.有没有办法阻止groovy脚本尝试连接到URL?

bob*_*nce 5

如果您使用的是适当的解析器,请尝试使用该load-external-dtd功能.

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

否则我认为你必须设置一个什么都不做的EntityResolver.