问题描述
问题:我无法通过更改服务器代码而非客户端代码来在客户端消息中获得内容类型*/*
来映射到服务器端的application/json
。 (太多的已部署客户端无法执行后者)
在WildFly 10上,一切正常(使用*/*
),但是在WildFly 14/18上,它失败并
RESTEASY002010: Failed to execute: javax.ws.rs.NotSupportedException: RESTEASY003200: Could not find message body reader for type: class xxxx of content type: */* at org.jboss.resteasy.resteasy-
[email protected]//org.jboss.resteasy.core.interception.ServerReaderInterceptorContext.throwReaderNotFound
以上所有操作均在Java 8上进行。下面的代码显示了客户端更改,该更改将使WF14 +在不进行服务器端编辑的情况下可以正常工作:
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type","*/*"); // works for WF10,not WF14+
// conn.setRequestProperty("Content-Type","application/json; charset=UTF-8"); // works for all
适用的服务器端代码如下:
@POST
@Path("fileDownload")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_OCTET_STREAM)
// Consume options tried that still failed:
// @Consumes({ MediaType.APPLICATION_JSON,MediaType.WILDCARD,MediaType.APPLICATION_OCTET_STREAM,"*/*","*/*\r\n","*/*; charset=UTF-8" } )
public Response fileDownload(@HeaderParam("Range") String range,FileDownloadRequest fileDwnReq) throws IOException { ... }
我的网络搜索全部指向客户端更改(这将起作用),但是我们必须更改服务器端或保留WF10。我也尝试过设置字符集行为或在 web.xml 中映射媒体类型,但这没有什么区别。例如:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>MyRestServices</display-name>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<!--
To specify the previous behavior,in which UTF-8 was used for text media types,but
the explicit charset was not appended,the context parameter "resteasy.add.charset" may be
set to "false". It defaults to "true".
See https://docs.jboss.org/resteasy/docs/3.1.2.Final/userguide/html_single/index.html
This did not work.
-->
<!-- <context-param> -->
<!-- <param-name>resteasy.add.charset</param-name> -->
<!-- <param-value>false</param-value> -->
<!-- </context-param> -->
<context-param>
<param-name>resteasy.media.type.mappings</param-name>
<param-value>*/* : application/json</param-value>
<!-- <param-value>html : text/html,json : application/json,xml : application/xml</param-value> -->
</context-param>
我很困惑。任何建议/指针将不胜感激。
编辑:以下是失败的http请求的转储:
URI=/xxx/fileDownload
characterEncoding=null
contentLength=94
contentType=[*/*]
header=Accept=text/html,image/gif,image/jpeg,*; q=.2,*/*; q=.2
header=Connection=keep-alive
header=Content-Type=*/*
header=Content-Length=94
header=User-Agent=Java/1.8.0_152
header=Host=127.0.0.1:8014
locale=[]
method=POST
protocol=HTTP/1.1
queryString=
remoteAddr=/127.0.0.1:59867
remoteHost=127.0.0.1
scheme=http
host=127.0.0.1:8014
serverPort=8014
isSecure=false
--------------------------RESPONSE--------------------------
contentLength=0
contentType=null
header=Connection=keep-alive
header=Content-Length=0
header=Date=Thu,20 Aug 2020 13:36:44 GMT
status=415
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)