You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by doviche <do...@gmail.com> on 2015/10/26 16:21:12 UTC

org.apache.camel.InvalidPayloadException: No body available of type: java.io.InputStream but has value: {......}

I have created a simple splitter implementation which takes in json file as
follow:

[
  {
    "isActive": false,
    "balance": "$3,960.64",
    "age": 30,
    "eyeColor": "blue",
    "name": "Dawn Keith",
    "gender": "female",
    "company": "COSMOSIS",
    "email": "dawnkeith@cosmosis.com",
    "phone": "+1 (839) 437-3421",
    "address": "392 Clifford Place, Fontanelle, Arizona, 2687"
  },
  {
    "isActive": false,
    "balance": "$1,280.14",
    "age": 31,
    "eyeColor": "green",
    "name": "Bettie Eaton",
    "gender": "female",
    "company": "COMTREK",
    "email": "bettieeaton@comtrek.com",
    "phone": "+1 (861) 460-2317",
    "address": "203 Allen Avenue, Elrama, North Carolina, 4453"
  }
]

When the ProducerTemplate tries to send the message 
template.sendBody("direct:accounts", accountStream); then I am getting the
following exceptions:

Caused by: org.apache.camel.InvalidPayloadException: No body available of
type: java.io.InputStream but has value: {isActive=true, balance=$1,424.09,
age=39, eyeColor=blue, name=Tillman Nixon, gender=male, company=PULZE,
email=tillmannixon@pulze.com, phone=+1 (933) 470-2926, address=608 Oriental
Court, Lemoyne, New Hampshire, 4285} of type: java.util.LinkedHashMap on:
Message: {isActive=true, balance=$1,424.09, age=39, eyeColor=blue,
name=Tillman Nixon, gender=male, company=PULZE,
email=tillmannixon@pulze.com, phone=+1 (933) 470-2926, address=608 Oriental
Court, Lemoyne, New Hampshire, 4285}. Caused by: No type converter available
to convert from type: java.util.LinkedHashMap to the required type:
java.io.InputStream with value {isActive=true, balance=$1,424.09, age=39,
eyeColor=blue, name=Tillman Nixon, gender=male, company=PULZE,
email=tillmannixon@pulze.com, phone=+1 (933) 470-2926, address=608 Oriental
Court, Lemoyne, New Hampshire, 4285}. Exchange[Message: {isActive=true,
balance=$1,424.09, age=39, eyeColor=blue, name=Tillman Nixon, gender=male,
company=PULZE, email=tillmannixon@pulze.com, phone=+1 (933) 470-2926,
address=608 Oriental Court, Lemoyne, New Hampshire, 4285}]. Caused by:
[org.apache.camel.NoTypeConversionAvailableException - No type converter
available to convert from type: java.util.LinkedHashMap to the required
type: java.io.InputStream with value {isActive=true, balance=$1,424.09,
age=39, eyeColor=blue, name=Tillman Nixon, gender=male, company=PULZE,
email=tillmannixon@pulze.com, phone=+1 (933) 470-2926, address=608 Oriental
Court, Lemoyne, New Hampshire, 4285}]
	at
org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101)
	at org.apache.camel.jsonpath.JsonPathEngine.read(JsonPathEngine.java:74)
	at
org.apache.camel.jsonpath.JsonPathExpression.evaluateJsonPath(JsonPathExpression.java:67)
	at
org.apache.camel.jsonpath.JsonPathExpression.evaluate(JsonPathExpression.java:50)
	... 48 more
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type
converter available to convert from type: java.util.LinkedHashMap to the
required type: java.io.InputStream with value {isActive=true,
balance=$1,424.09, age=39, eyeColor=blue, name=Tillman Nixon, gender=male,
company=PULZE, email=tillmannixon@pulze.com, phone=+1 (933) 470-2926,
address=608 Oriental Court, Lemoyne, New Hampshire, 4285}
	at
org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:177)
	at
org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)
	... 51 more
 

Here is the responsible code:

          camelContext.addRoutes(new RouteBuilder() {
                public void configure() {

                    Language lan = camelContext.resolveLanguage("jsonpath");
                    Expression exp = lan.createExpression("$.[*]");
                    
                    from("direct:accounts")
                    .split().jsonpath("$.[*]")
                        .log("${body}")
                        .multicast()    
                           .to("direct:active") 
                           .to("direct:nonactive")                                      
                    .end();

                    
                    from("direct:active")
                    .log("Getting active account")     
                    .split().jsonpath("$.[*].isActive")
                    .setBody(new JsonPathExpression("$.[*].name"))
                    .log("${body}")        
                    .end();
                    
                    from("direct:nonactive")
                    .log("Getting non active account")        
                    .split().jsonpath("$.[*].isActive")
                    .setBody(new JsonPathExpression("$.[*].name"))
                    .log("${body}")        
                    .end(); 
                }
            });
            ProducerTemplate template =
camelContext.createProducerTemplate();
            camelContext.start();
            String filename =
this.getClass().getResource("/account.json").getFile();
            InputStream accountStream = new FileInputStream(filename);
            System.out.println(accountStream);
            template.sendBody("direct:accounts", accountStream);

Thanks in advance

Douglas



--
View this message in context: http://camel.465427.n5.nabble.com/org-apache-camel-InvalidPayloadException-No-body-available-of-type-java-io-InputStream-but-has-value-tp5773076.html
Sent from the Camel - Users mailing list archive at Nabble.com.