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

have a string "X°XX" which RabbitMQ writes out as "X?XX"I understand that this hap

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1738407424a4047620.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信