最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Apache Camel, RabbitMQ, special character is transforrmed into a Question Mark - Stack Overflow

programmeradmin21浏览0评论

have a string "X°XX" which RabbitMQ writes out as "X?XX"

I understand that this happens, when you stream a string into bytes with one charset UTF-8. And write the bytes back to a string using another charset such as US_ASCII.

I am using Camel to set up the message and route

from(requestUrl)
        .routeId(JourneyConstants.BACKEND_ROUTE_ID)
        .routeProperty(CommonConstants.ROUTE_TYPE, RouteIdGenerator.RouteType.AMQP_CONSUMER.name())
        .log(JourneyConstants.BACKEND_ROUTE_ID +" Received, payload ${body} and headers, ${headers}")
        .removeHeader(JourneyConstants.CONTENT_LENGTH) // Due to a new ISTIO we had to remove the content length header
        .setExchangePattern(ExchangePattern.InOnly)
        .setHeader(CommonConstants.JOURNEY_NAME, constant(JourneyConstants.JOURNEY_NAME_VALUE))
        .setHeader(Exchange.CONTENT_TYPE, constant("application/json;charset=utf-8"))
        .convertBodyTo(String.class)
        .setProperty(CommonConstants.ORIGINAL_MESSAGE, body())
        .setProperty(CommonConstants.BACKEND_URL, constant(backendUrl))
        .setProperty(CommonConstants.FAILURE_QUEUE_URL, constant(queueUrls))
        .setProperty(CommonConstants.CODES_TRANSIENT_QUEUE, constant("50[0-9]|40[1,3,4,8]"))
        .setProperty(CommonConstants.CODES_PERSISTENT_QUEUE, constant("4[0,2,5,6,7,9]"))
        .convertBodyTo(String.class)
        .setHeader(CommonConstants.USE_HEADER_STRATEGY,constant("true"))
        .setHeader(CommonConstants.HMRC_ASSETS_OPERATION_TYPE, constant(CommonConstants.VALIDATION_JSON))
        .toD(assetEndpointUrl)

So we have

.setHeader(Exchange.CONTENT_TYPE, constant("application/json;charset=utf-8"))

and

.convertBodyTo(String.class)

But since I have still getting the charector ?. Do I need To set a setProperty to make sure that convertBodyTo(String.class) uses charset=utf-8

Thank you for any help

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论