首页 > 解决方案 > com.sun.xml.messaging.saaj.SOAPExceptionImpl:无效的内容类型:文本/纯文本。这是错误消息而不是 SOAP 响应吗?

问题描述

您好,我正在尝试为我的肥皂集成测试创建一个脏测试。我刚刚让 SSL 在我的 spring boot 应用程序上工作,我想看看它是否会达到我的肥皂终点。

当我在集成测试中运行 man verify 时,出现此错误:

com.sun.xml.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/plain. Is this an error message instead of a SOAP response?

这是我的测试代码:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {EndPointTestConfiguration.class
})


public class SoapIT {
private static ApplicationContext context;
    @BeforeClass
    static public void  setup(){
        SpringApplication springApplication = new SpringApplicationBuilder()           
                .sources(MockServerApp.class)
                .build();
        context = springApplication.run();
    }


    @Autowired
    private String studyDetailDemo;
    @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(studyDetailDemo, ContentType.TEXT_PLAIN)
                .execute().returnContent().asString();

    }
}

我是集成测试的新手,不知道这个错误意味着什么

感谢您的任何帮助

标签: javaspring-bootsoapintegration-testing

解决方案


我认为您需要阅读有关如何进行弹簧测试的内容。

使用模拟环境进行测试

@SpringBootTest将自动扫描带有注释的 spring 类并为您加载一个 mockspringcontext,因此您无需执行所有@BeforeClass操作。

如果你想调用这个“模拟上下文”,你需要在 MockMvc、WebTestClient 或 TestRestTemplate 中配置和自动装配。

另一方面,如果你想启动一个真正的服务器,你需要指定@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)(或定义的端口)。

您可以在上面的链接文档中阅读所有相关信息。

顺便说一句,你不能在字符串中自动装配。

您的代码应如下所示:

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
public class SoapIT {

    @LocalServerPort
    private int port;

    private String studyDetailDemo = "some body text";

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

    }
}

没试过代码,在手机上写的。


推荐阅读