java - 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();
}
}
我是集成测试的新手,不知道这个错误意味着什么
感谢您的任何帮助
解决方案
我认为您需要阅读有关如何进行弹簧测试的内容。
@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();
}
}
没试过代码,在手机上写的。
推荐阅读
- ajax - Laravel Ajax 商店更新数据问题
- mysql - MYSQL - 查询获取不同的 sender_id、receiver id 和 richiesta_id
- yocto - U-boot环境与Linux“fw_printenv”不一样
- php - 如何将 .png 显示为框架
- matlab - 如何在散点图上显示有关选定点的信息 - 到 GUIDE 中的文本框
- cypress - 在赛普拉斯禁用日志记录测试结果
- magento - 如何在产品的简短描述中添加通用段落。Magento 1
- css - 为什么我不能用 CSS 删除这个边框?
- node.js - 没有`next()`的表达错误中间件?
- visual-studio - 例外:AspNetCoreModule 不支持进程内托管。将 AspNetCoreModule 更改为至少 AspNetCoreModuleV2