private DataSet marshalResponse ( final Message response , final MessageType messageType ) throws SQLException { String dataSet = null ; if ( response instanceof JdbcMessage || response . getPayload ( ) instanceof OperationResult ) { dataSet = response . getPayload ( OperationResult . class ) . getDataSet ( ) ; } else { try { JdbcMarshaller jdbcMarshaller = new JdbcMarshaller ( ) ; jdbcMarshaller . setType ( messageType . name ( ) ) ; Object object = jdbcMarshaller . unmarshal ( new StringSource ( response . getPayload ( String . class ) ) ) ; if ( object instanceof OperationResult && StringUtils . hasText ( ( ( OperationResult ) object ) . getDataSet ( ) ) ) { dataSet = ( ( OperationResult ) object ) . getDataSet ( ) ; } } catch ( CitrusRuntimeException e ) { dataSet = response . getPayload ( String . class ) ; } } if ( isJsonResponse ( messageType ) ) { return new JsonDataSetProducer ( Optional . ofNullable ( dataSet ) . orElse ( "[]" ) ) . produce ( ) ; } else if ( isXmlResponse ( messageType ) ) { return new XmlDataSetProducer ( Optional . ofNullable ( dataSet ) . orElse ( "<dataset></dataset>" ) ) . produce ( ) ; } else { throw new CitrusRuntimeException ( "Unable to create dataSet from data type " + messageType . name ( ) ) ; } }
Marshals the given message to the requested MessageType