GROOVY 使用 MTOM - 如何切割 XML

GROOVY with MTOM - how to cut XML

我正在尝试删除 mtom soap xml 响应以仅从整体响应中检索真实响应。

纯文本:

------=_Part_406790_188859372.1611576835975
Content-Type: application/xop+xml;charset=UTF-8;type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <67b0f124-2a07-4c56-a6f2-7db282ad7f65>

<?xml version="1.0" encoding="UTF-8" ?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header/><env:Body>><ns2:Service IdcService="GET_FILE"></env:Body></env:Envelope>
------=_Part_406790_188859372.1611576835975
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <582442cb-3d80-4eaa-b723-0ef901d11c4f>

<?xml version="1.0" encoding="UTF-8" ?> <DATA_DS><G_1><PAYROLL_ACTION_ID>4119</PAYROLL_ACTION_ID><G_2><FILE_FRAGMENT><Feed_V7><REP_CATEGORY_NAME>Blubblub</REP_CATEGORY_NAME><parameters><request_id>234234</request_id><FLOW_NAME>Lalelu 25-01-2021 10:49:33 | Blub</FLOW_NAME><legislative_data_group_id/><effective_date>2021-01-01</effective_date><start_date/><report_category_id>21321</report_category_id><action_parameter_group_id/><changes_only>N</changes_only></parameters></Person></Feed_V7></FILE_FRAGMENT></G_2></G_1></DATA_DS>
------=_Part_406790_188859372.1611576835975--

这就是我想要的:

<?xml version="1.0" encoding="UTF-8" ?><DATA_DS>.....all between.....</DATA_DS>

Groovy 通过子字符串试用:

def bodySize = body.length()
def String subString = body.toString().substring(566)
def otherString = subString.substring(0,76)
println(otherString)

这确实是一种糟糕的做法,但我 运行 不知道如何完全动态地检索 xml。

感谢您的输入(甚至仅针对方法 - 不要求完成代码而是使用哪些方法在响应中找到正确的部分)。

不合时宜:

String txt = '''
------=_Part_406790_188859372.1611576835975
Content-Type: application/xop+xml;charset=UTF-8;type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <67b0f124-2a07-4c56-a6f2-7db282ad7f65>

<?xml version="1.0" encoding="UTF-8" ?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header/><env:Body>><ns2:Service IdcService="GET_FILE"></env:Body></env:Envelope>
------=_Part_406790_188859372.1611576835975
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <582442cb-3d80-4eaa-b723-0ef901d11c4f>

<?xml version="1.0" encoding="UTF-8" ?><DATA_DS><G_1>4119</G_1></DATA_DS>
------=_Part_406790_188859372.1611576835975--'''

def matches = ( txt =~ /<\?xml.*><DATA_DS>.*<\/DATA_DS>/ ).findAll()
String match = matches ? matches.first() : null
assert match == '<?xml version="1.0" encoding="UTF-8" ?><DATA_DS><G_1>4119</G_1></DATA_DS>'