Error with XSL transform: java.lang.String cannot be cast to com.apigee.flow.message.Message

Not applicable

I get a fail when trying to preform a XSL Transform on a XML that is created from JSON to XML policy.

The error is 'java.lang.String cannot be cast to com.apigee.flow.message.Message' but the source variable is set by the JSON to XML policy.

150-screenshot-2015-02-26-010805.png

The policies is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONToXML async="false" continueOnError="false" enabled="true" name="JSONtoXMLSwipBox">
    <DisplayName>JSONtoXMLSwipBox</DisplayName>
    <OutputVariable>SwipboxResponse</OutputVariable>
    <Source>SwipboxResponseJSON</Source>
</JSONToXML>

and

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XSL async="false" continueOnError="false" enabled="true" name="XSLTransformSwipbox">
    <DisplayName>XSLTransformSwipbox</DisplayName>
    <FaultRules/>
    <Properties/>
    <Source>SwipboxResponse</Source>
    <ResourceURL>xsl://XSL-Transform-Postdanmark.xslt</ResourceURL>
    <Parameters ignoreUnresolvedVariables="true" />
</XSL>

I can't seem to grasp what the error means?

Solved Solved
1 2 2,326
1 ACCEPTED SOLUTION

Hi Anders,

The XSL Transform policy expects a MESSAGE as source input. See the reference material here: http://apigee.com/docs/api-services/reference/xsl-transform-policy

You have converted JSON to XML and the result (SwipboxResponse) is not a message but is rather a String.

I think what you need to do is this: use an AssignMessage policy to create a new MESSAGE object. Within that policy, Insert the string (SwipboxResponse) as the payload of the Message. Place the AssignMessage after the JSONToXML, and before the XSLTransform. Modify the XSLTransform to refer to the newly created message, instead of the SwipboxResponse.

The AssignMessage should look something like this:

<AssignMessage name='AssignMessage-1'>
  <DisplayName>AssignMessage</DisplayName>
  <Description>create a new message</Description>
  <AssignTo createNew='true' type='request'>newlyCreatedMessage</AssignTo>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <Set>
    <Payload contentType='application/xml'>{SwipboxResponse}</Payload>
    <StatusCode>200</StatusCode>
    <ReasonPhrase>OK</ReasonPhrase>
  </Set>
</AssignMessage>

And then your XSL policy should look like this:

<XSL name="XSLTransformSwipbox">
    <DisplayName>XSLTransformSwipbox</DisplayName>
    <Source>newlyCreatedMessage</Source>
    <ResourceURL>xsl://XSL-Transform-Postdanmark.xslt</ResourceURL>
    <Parameters ignoreUnresolvedVariables='false' />
</XSL>

NB: The XSL policy type can be a little confusing because the source must be a message but the output is a string. If you want the output to go to the payload, you can use 'response.content' as the output variable name.

View solution in original post

2 REPLIES 2

Hi Anders,

The XSL Transform policy expects a MESSAGE as source input. See the reference material here: http://apigee.com/docs/api-services/reference/xsl-transform-policy

You have converted JSON to XML and the result (SwipboxResponse) is not a message but is rather a String.

I think what you need to do is this: use an AssignMessage policy to create a new MESSAGE object. Within that policy, Insert the string (SwipboxResponse) as the payload of the Message. Place the AssignMessage after the JSONToXML, and before the XSLTransform. Modify the XSLTransform to refer to the newly created message, instead of the SwipboxResponse.

The AssignMessage should look something like this:

<AssignMessage name='AssignMessage-1'>
  <DisplayName>AssignMessage</DisplayName>
  <Description>create a new message</Description>
  <AssignTo createNew='true' type='request'>newlyCreatedMessage</AssignTo>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <Set>
    <Payload contentType='application/xml'>{SwipboxResponse}</Payload>
    <StatusCode>200</StatusCode>
    <ReasonPhrase>OK</ReasonPhrase>
  </Set>
</AssignMessage>

And then your XSL policy should look like this:

<XSL name="XSLTransformSwipbox">
    <DisplayName>XSLTransformSwipbox</DisplayName>
    <Source>newlyCreatedMessage</Source>
    <ResourceURL>xsl://XSL-Transform-Postdanmark.xslt</ResourceURL>
    <Parameters ignoreUnresolvedVariables='false' />
</XSL>

NB: The XSL policy type can be a little confusing because the source must be a message but the output is a string. If you want the output to go to the payload, you can use 'response.content' as the output variable name.

You are brilliant! I hadn't even seen that the XSL Transform policy expects a MESSAGE as source input.

This solved the problem completely!

Thank you so much 🙂