首页 > 解决方案 > Spring Boot 在 SOAP 集成测试请求中添加信封

问题描述

我正在尝试进行 SOAP 集成测试。我有一个 XML 文件作为请求,在 SOAPUI 中它有一个肥皂信封页眉和页脚,如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.billing.nulogix.com">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:analyze>
         <ser:studyContainer>
<![CDATA[

]]>
         </ser:studyContainer>
         <ser:studyContainerVersion>3.17.6.12</ser:studyContainerVersion>
      </ser:analyze>
   </soapenv:Body>
</soapenv:Envelope>

我需要将其包含在集成测试中。到目前为止,我这样做了:

private String studyDetailDemo;

    private String header = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.billing.nulogix.com\">\n" + 
            "   <soapenv:Header/>\n" + 
            "   <soapenv:Body>\n" + 
            "      <ser:analyze>\n" + 
            "         <ser:studyContainer>\n" + 
            "<![CDATA[\n";
    private String footer = "]]>\n" + 
            "         </ser:studyContainer>\n" + 
            "         <ser:studyContainerVersion>3.17.6.12</ser:studyContainerVersion>\n" + 
            "      </ser:analyze>\n" + 
            "   </soapenv:Body>\n" + 
            "</soapenv:Envelope>";

    private String request = header + studyDetailDemo + footer;
    @Test
    public void soapTest() throws ClientProtocolException, IOException {
        String result = Request.Post("https://127.0.0.1:28443/nulogix/ws/billingtool")
                .connectTimeout(2000)
                .socketTimeout(2000)
                .bodyString(request, ContentType.TEXT_XML)
                .execute().returnContent().asString();

当我在 mvn 中运行它时,我得到了这个错误:

StudyDetails unmarshal failed due to JAXBException javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.]

标签: javaspring-bootsoapheaderintegration-testing

解决方案


推荐阅读