KB Article #177943

java.lang.ClassCastException: java.lang.String cannot be cast to com.vordel.mime.Body

Problem

* You see an exception like the following when trying to replace the contents of content.body with a java.lang.String value:


java.lang.ClassCastException: java.lang.String cannot be cast to com.vordel.mime.Body

Resolution

The class com.vordel.mime.Body has several different sub-types that reference different types of content, so it will break things if you try to replace it with a simple string because there's no associated content-type, no character encoding, and the body has not been parsed by the gateway. You need to use the Set Message filter to create a new, valid content.body with the appropriate content-type. Please refer to the API Gateway javadoc if you need further information about the com.vordel.mime.Body and related classes. To reverse the transformation, use a Set Attribute filter to set your string attribute to the value ${content.body}


This works because the Set Attribute filter converts its values to strings.