I need to read a blob field from a database, in a channel reader, then send it through TCP.
I can do this easily with a Database Reader, except when I have Blob fields, so I'm trying to use a JavaScript reader instead:
var dbConn = DatabaseConnectionFactory.createDatabaseConnection('org.postgresql.Driver','jdbc:postgresql://127.0.0.1:5432/ris','postgres','postgres');
// You may access this result below with $('column_name')
var resultQuery = "select mensajehl7, p.ip, p.port from turnohl7 h7 join pacs p on p.idpacs=h7.idpacs where h7.estado='NW'";
var qryResult = dbConn.executeCachedQuery(resultQuery);
var result = new Packages.java.util.ArrayList();
while(qryResult.next())
{
var columna = new Array();
columna['hl7'] = qryResult.getBytes(1);
result.add(columna);
}
dbConn.close();
return result;
It seems that the result needs to be an XML, as the stacktrace suggests:
[2012-12-04 12:56:29,227] ERROR (org.mule.impl.DefaultComponentExceptionStrategy:95): Caught exception in Exception Strategy for: f4a3cccb-902e-4504-86f5-0bfa473ad144: org.mule.umo.routing.RoutingException: Failed to transform message before applying the filter. Failed to route event via endpoint: ImmutableMuleEndpoint{connector=com.mirth.connect.connectors.js.JavaScriptConnector@379cf50c, endpointUri=js://sink, transformer=Transformer{name='ResultMapToXML', returnClass=false, returnClass=false, sourceTypes=[interface java.util.Map, class java.lang.String]}, name='_jsEndpoint#-1389160782', type='receiver', properties={}, transactionConfig=org.mule.impl.MuleTransactionConfig@44adab2d, filter=null, deleteUnacceptedMessages=false, initialised=true, securityFilter=null, synchronous=true, initialState=started, createConnector=0}. Message payload is of type: java.lang.String
org.mule.umo.routing.RoutingException: Failed to transform message before applying the filter. Failed to route event via endpoint: ImmutableMuleEndpoint{connector=com.mirth.connect.connectors.js.JavaScriptConnector@379cf50c, endpointUri=js://sink, transformer=Transformer{name='ResultMapToXML', returnClass=false, returnClass=false, sourceTypes=[interface java.util.Map, class java.lang.String]}, name='_jsEndpoint#-1389160782', type='receiver', properties={}, transactionConfig=org.mule.impl.MuleTransactionConfig@44adab2d, filter=null, deleteUnacceptedMessages=false, initialised=true, securityFilter=null, synchronous=true, initialState=started, createConnector=0}. Message payload is of type: java.lang.String
at org.mule.routing.inbound.SelectiveConsumer.isMatch(SelectiveConsumer.java:64)
at org.mule.routing.inbound.InboundMessageRouter.route(InboundMessageRouter.java:79)
at org.mule.providers.AbstractMessageReceiver$DefaultInternalMessageListener.onMessage(AbstractMessageReceiver.java:487)
at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:266)
at org.mule.providers.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:225)
at com.mirth.connect.connectors.js.JavaScriptMessageReceiver.processMessage(JavaScriptMessageReceiver.java:101)
at com.mirth.connect.connectors.js.JavaScriptMessageReceiver.poll(JavaScriptMessageReceiver.java:82)
at org.mule.providers.PollingMessageReceiver.run(PollingMessageReceiver.java:97)
at org.mule.impl.work.WorkerContext.run(WorkerContext.java:290)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1061)
at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:575)
at java.lang.Thread.run(Unknown Source)Caused by: org.mule.umo.transformer.TransformerException: java.lang.StringIndexOutOfBoundsException: String index out of range: -2 (com.mirth.connect.server.mule.adaptors.AdaptorException)
at com.mirth.connect.server.mule.transformers.JavaScriptTransformer.transform(JavaScriptTransformer.java:285)
at org.mule.transformers.AbstractEventAwareTransformer.doTransform(AbstractEventAwareTransformer.java:48)
at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:197)
at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:200)
at org.mule.transformers.AbstractTransformer.transform(AbstractTransformer.java:200)
How can I use my bytea field in a transformer?