Spring integration Multpart请求通过Junit正常工作,但在IE浏览器中失败
我在我的项目中使用Spring集成。我正在尝试访问多部分Web服务。我正在使用Spring integration Multpart请求通过Junit正常工作,但在IE浏览器中失败,spring-integration,Spring Integration,我在我的项目中使用Spring集成。我正在尝试访问多部分Web服务。我正在使用inthttp:outboundgateway执行Web服务。我可以通过Junit毫无问题地执行rest服务,但奇怪的是,当我尝试使用IE浏览器执行时,同样的服务失败了。 以下是我得到的错误: Caused by: org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageCon
inthttp:outboundgateway
执行Web服务。我可以通过Junit毫无问题地执行rest服务,但奇怪的是,当我尝试使用IE浏览器执行时,同样的服务失败了。
以下是我得到的错误:
Caused by: org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [java.util.HashMap] and content type [text/xml;charset=UTF-8]
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:665)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:481)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:460)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:409)
at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:372)
原因可能是什么?如果您需要更多信息,请告诉我
<int:chain input-channel="Test-Rest-Channel" >
<int:header-filter header-names="accept-encoding"/>
<int:service-activator ref="httpOutboundGatewayHandler" method="buildMultipartHttpOutboundGatewayRequest" />
<int-http:outbound-gateway url-expression="headers.restResourceUrl"
http-method-expression="headers.httpMethod"
extract-request-payload="true"
expected-response-type="java.lang.String">
</int-http:outbound-gateway>
<int:transformer expression="'<response>' + payload + '</response>'"/>
<int:service-activator ref="msgHandler" method="enrichPayloadXml" />
</int:chain>
当我使用内容类型
标题作为多部分/表单数据
时,我得到以下错误:
Caused by: org.springframework.web.client.HttpClientErrorException: 403 Forbidden
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:88)
at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:532)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:488)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:460)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:409)
at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:372)
... 138 more
编辑标题内容类型
为多部分/表单数据
与JUNIT配合良好
当我使用Accept
标题作为multipart/form data
时,我得到以下错误:
Caused by: org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type [java.util.HashMap] and content type [text/xml;charset=UTF-8]
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:665)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:481)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:460)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:409)
at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:372)
... 138 more
没有为请求类型[java.util.HashMap]和内容类型[text/xml;charset=UTF-8]找到合适的HttpMessageConverter
我认为您的JUnit测试使用了稍微不同的负载类型。但是这里有Map
负载,它实际上无法转换为text/xml
或者提供一些转换器将映射转换为适当的XML转换类型,或者更改内容类型
标题以使该映射序列化为应用程序/x-www-form-urlencoded
更新
Caused by: java.lang.ClassCastException: org.springframework.core.io.FileSystemResource cannot be cast to java.lang.String
at org.springframework.http.converter.FormHttpMessageConverter.writeForm(FormHttpMessageConverter.java:232)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:196)
看起来您的Map
包含一些值,这些值是FileSystemResource
,但不是普通的String
。从另一个角度看,你们并没有通过多部分条件,我猜是因为你们有错误的内容类型:
private boolean isMultipart(MultiValueMap<String, ?> map, MediaType contentType) {
if (contentType != null) {
return MediaType.MULTIPART_FORM_DATA.includes(contentType);
}
没有为请求类型[java.util.HashMap]和内容类型[text/xml;charset=UTF-8]找到合适的HttpMessageConverter
我认为您的JUnit测试使用了稍微不同的负载类型。但是这里有Map
负载,它实际上无法转换为text/xml
或者提供一些转换器将映射转换为适当的XML转换类型,或者更改内容类型
标题以使该映射序列化为应用程序/x-www-form-urlencoded
更新
Caused by: java.lang.ClassCastException: org.springframework.core.io.FileSystemResource cannot be cast to java.lang.String
at org.springframework.http.converter.FormHttpMessageConverter.writeForm(FormHttpMessageConverter.java:232)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:196)
看起来您的Map
包含一些值,这些值是FileSystemResource
,但不是普通的String
。从另一个角度看,你们并没有通过多部分条件,我猜是因为你们有错误的内容类型:
private boolean isMultipart(MultiValueMap<String, ?> map, MediaType contentType) {
if (contentType != null) {
return MediaType.MULTIPART_FORM_DATA.includes(contentType);
}
谢谢你的回复。当我将
内容类型
更改为应用程序/x-www-form-urlencoded
时,我得到一个错误org.springframework.core.io.FileSystemResource无法转换为java.lang.String,原因是:java.lang.ClassCastException:org.springframework.core.io.FileSystemResource无法转换为java.lang.String。你能分享吗更多关于这件事的线索?作为你问题的编辑将是最好的选择再次感谢你的支持。我已经在问题中添加了完整的堆栈跟踪。请在我的答案中查找更新。对不起,耽搁了。稍后将研究您的另一个问题。403禁止
表示您已经到达REST服务,但看起来它不喜欢您的请求。请咨询您的服务提供商,以确定您还需要添加或删除哪些内容才能满足他们的要求。感谢您的回复。当我将内容类型
更改为应用程序/x-www-form-urlencoded
时,我得到一个错误org.springframework.core.io.FileSystemResource无法转换为java.lang.String,原因是:java.lang.ClassCastException:org.springframework.core.io.FileSystemResource无法转换为java.lang.String。你能分享吗更多关于这件事的线索?作为你问题的编辑将是最好的选择再次感谢你的支持。我已经在问题中添加了完整的堆栈跟踪。请在我的答案中查找更新。对不起,耽搁了。稍后将研究您的另一个问题。403禁止
表示您已经到达REST服务,但看起来它不喜欢您的请求。请咨询您的服务提供商,以确定您还需要添加或删除哪些内容才能满足他们的要求。