CXF中的标头错误

尼斯马

我正在使用CXF WebClient,我尝试做一个webclient服务并使用它进行调用,我在标头中设置了JSON类型,但是在标头中获得了通配符

我这样做是为了使webClient

client = WebClient.create(endPoint,Collections.singletonList(new JacksonJsonProvider())).
            accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON);

    ClientConfiguration config = WebClient.getConfig(client);
    config.getInInterceptors().add(new LoggingInInterceptor());
    config.getOutInterceptors().add(new LoggingOutInterceptor());

而且我有这个可以拨打电话

Response reponse=clientThreadSafe().path("tokens/{id}",virtualToken.getId()).get();

return genericReponse(Token.class,Status.OK,reponse);

使用clientThreadSafe

private WebClient clientThreadSafe() throws CertEuropeException{
    //thread safe, see http://cxf.apache.org/docs/jax-rs-client-api.html#JAX-RSClientAPI-ThreadSafety
    return  WebClient.fromClient(client);
}

和genericResponse

private <T> T genericReponse(Class<T> classReponse, Status status, Response reponse ) throws Exception{

    if(reponse.getStatusInfo()!=status){
        throw new Exception("somthing bad here");
    }
    return  reponse.readEntity(classReponse);

}

但是我在通话中得到了通配符

INFOS: Setting the server's publish address to be 
http://localhost:9090 mars 14, 2016 1:52:31 PM
org.apache.cxf.interceptor.LoggingOutInterceptor INFOS: Outbound
Message
--------------------------- ID: 1 Address: http://localhost:9090/api/v1/tokens/1 Http-Method: GET
Content-Type:  Headers: {Accept=[*/*]}

我得到一个例外

GRAVE: No message body reader has been found for class com.client.Token, ContentType: application/octet-stream
mars 14, 2016 1:52:31 PM
org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper toResponse
AVERTISSEMENT: javax.ws.rs.WebApplicationException: HTTP 415 Unsupported Media Type

我不知道为什么WebClient不采用MediaType.APPLICATION_JSON标头,也许我没有使用正确的函数来设置标头。

如果我尝试使用其他休息客户端,例如邮递员,并且我设置了正确的标题,那么一切似乎都可以正常工作。

尼斯马

经过大量测试,我发现“ Fluent接口”实际上并没有按应有的方式工作,顺序似乎很重要,如果在开始时设置了WebClient的accept和类型,则可以将其重置。

因此,对于每次调用,我都必须accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON)在path方法之后进行,例如:

path("tokens/{id}",token.getId())
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.invoke("GET", "")

如果我更改订单,则接受和类型不会计算在内

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Garmin API中的oAuth标头错误

PHP标头错误

包括肥皂标头-Apache CXF

Ebay API 中的错误请求错误设置标头

如何修复Express中的“错误:发送标头后无法设置标头”

骆驼cxf客户端请求中的HTTP标头Content-Length

如何在beast :: websocket中读取错误请求的标头?

在Code :: Blocks错误中包含多个标头

错误:发送标头后无法设置。在nodejs中

如何修复PHP中的“标头已发送”错误

尽管在Flask中设置了响应标头,但CORS错误

从图像错误处理程序中读取响应标头

转码期间的标头错误

错误:发送标头后无法设置标头

UnhandledPromiseRejectionWarning:错误:发送标头后无法设置标头

NodeJs错误:发送标头后无法设置标头

收到错误-发送标头后无法设置标头

表达错误:发送标头后无法设置标头

错误无法修改标头信息 - 标头已发送

带有节点的Express应用程序中的“错误:发送标头后无法设置标头”

IE中的粘性标头

在C ++中包含标头

在索引中包含标头?

maven2中的编译错误:“无效的CEN标头(错误的签名)”

CXF:为CXF SOAP / REST Web服务的WSDL和WADL响应添加隐式标头

在Jersey JAX_RS中错误,在JDK> 8中带有OPTIONS标头?

在beforeAction中渲染视图时,在Yii中收到“已发送标头”错误

错误R csv:read.table中的错误(文件=文件,标头=标头,sep = sep,引用=引号,:“文件”必须是字符串或连接

目标C Xcode标头错误