質問

I have a Apache camel application which mediates between rest services and web services. Rest services are callers and web services are the back end. I have made progress till the point where I get response from web service and it is transformed to into a xml. Now I have to send JSON response to my caller in a particular format (say with some additional transaction and session id's) extracting data from the xml. What are the options available to me for this? Are there any tools available which can create a scripted JSON template using the XSD OR I have to write the scripts manually? If we have to go with the second option, what is the scripting language I have to use?

In other words, I want to write a velocity template which extracts data from the xml file. I am not sure what is the best approach to do so.

Thanking you in advance.

役に立ちましたか?

解決

My opinion is that you should first convert your XML into a DTO, and then your DTO into Json. You should split your architecture in more than just one layer. The data access layer will handle the WS call and the controller will know how to answer the REST call. Velocity is just a template engine, not a converting tool. You should check Jackson or Gson. Hope this helps

Edit: If you want a specific format for your DTOs, you could extend Jacksons converters or if you only want to use Velocity just render it putting your DTO in the VelocityContext and then you use it just like you always do, but I don't think it's the best way to do it.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top