camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CAMEL-11891) XML2JSON Data Format and empty requests
Date Tue, 24 Oct 2017 07:56:00 GMT

    [ https://issues.apache.org/jira/browse/CAMEL-11891?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16216480#comment-16216480
] 

Claus Ibsen commented on CAMEL-11891:
-------------------------------------

Onder, next time be a bit more careful to backport to the 2.19.x branch etc as we should really
only do bug fixes and if its major needed - eg its better to NOT change than to CHANGE. eg
its production usage.

Changes leading up to the first patch release on a new branch, eg 2.20.1 patch is a bit more
open. However the older the branch is the more conservative we should be, as more users are
in production.



> XML2JSON Data Format and empty requests
> ---------------------------------------
>
>                 Key: CAMEL-11891
>                 URL: https://issues.apache.org/jira/browse/CAMEL-11891
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-xmljson
>    Affects Versions: 2.19.3
>            Reporter: Richard Groote
>            Assignee: ├ľnder Sezgin
>             Fix For: 2.19.4, 2.20.1
>
>
> It would be nice if the XmlJsonDataFormat can handle empty body.
> In our project we upgraded from 2.14.0 to 2.19.3. 
> The below code no longer works in 2.19.3 when a GET request is made to a servlet component.
In our situation the body contains a stream cache and the xml2json will fail.
> A possible solution is to check the http method before doing the unmarshalling.
>       <camel:choice>
>         <camel:when>
>           <camel:simple>${body} != null</camel:simple>
>           <camel:unmarshal ref="xml2json"/>
>         </camel:when>
>       </camel:choice>
> The current solution in our project is a extension of the XmlJsonDataFormat.
> In the extension the method unmarshall is overriden
> {code:java}
> 	@Override
> 	public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
>         Object inBody = exchange.getIn().getBody();
>         
>         if(inBody == null) {
>         		return null;
>         }
>         
>         if(inBody instanceof StreamCache) {
>         		long length = ((StreamCache) inBody).length();
>         		if(length <= 0) {
>         			return null;
>         		}
>         } else {
> 	        if(!(inBody instanceof JSON)) {
> 	        	 	String jsonString = exchange.getContext().getTypeConverter().convertTo(String.class,
exchange, inBody);
> 	        	 	if(StringUtils.isEmpty(jsonString)) {
> 	        	 		return null;
> 	        	 	}
> 	        }
>         }
>         
>         
>         
>         return super.unmarshal(exchange, stream);
> 	}
> {code}
> 	



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message