【问题标题】:com.sun.xml.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/plain. Is this an error message instead of a SOAP response?com.sun.xml.messaging.saaj.SOAPExceptionImpl:无效的内容类型:文本/纯文本。这是错误消息而不是 SOAP 响应吗?
【发布时间】:2019-08-26 22:36:39
【问题描述】:

您好,我正在尝试为我的 soap 集成测试创建一个脏测试。我刚刚在我的 Spring Boot 应用程序上运行 SSL,我想看看它是否会达到我的肥皂终点。

当我在集成测试中运行 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();

    }
}

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

感谢您的帮助

【问题讨论】:

  • 您以纯文本形式发送请求,这就是ContentType.TEXT_PLAIN 的含义。相反,您应该发送 XML 的内容类型。

标签: java spring-boot soap integration-testing


【解决方案1】:

我认为你需要阅读一下如何进行弹簧测试。

testing-with-mock-environment

@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();

    }
}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-12
    • 2022-06-13
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    • 1970-01-01
    相关资源
    最近更新 更多