1

我需要在通道读取器中从数据库中读取一个 blob 字段,然后通过 TCP 发送它。

我可以使用数据库阅读器轻松完成此操作,除非我有 Blob 字段,因此我尝试使用 JavaScript 阅读器:

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;

正如堆栈跟踪所暗示的,结果似乎需要是一个 XML:

[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)

如何在变压器中使用我的 bytea 字段?

4

2 回答 2

2

这个答案不会是直接的,但希望它会有所帮助。

我从两个方面讲:

1.从数据库中获取HL7数据

我做了类似的事情,除了在我的情况下,HL7 数据以 varchar(max) 的形式存储在 SQL Server 中,并且我调用存储过程而不是传递完整的查询。

返回数据表时,我们将hl7数据提取为clob(不是blob)如下

// the hl7 data is returned as a CLOB, not a string
var hl7MsgClob  = dataTable.getClob("HL7");
var clobLength = hl7MsgClob.length();

// clobs have a starting index of 1, and the getSubString is inclusive on both ends of the range
var hl7Msg = hl7MsgClob.getSubString(1,clobLength);

// This is a code template that decodes characters we escaped prior to writing to SQL Server
var cleanHL7 = Util_DecodeTextFromSQLStorage(hl7Msg);

// convert the message to an XML format
var HL7AsXML = SerializerFactory.getHL7Serializer(false,false,true).toXML(cleanHL7);

2. 在 Mirth 中传递数据

您从 Javascript 阅读器返回的数据类型必须与频道源的数据类型相匹配。我不知道较新的 Mirth 版本,但在 1.8.2 版本中,这是在标记为“传入数据”的下拉列表中的“摘要”选项卡上配置的。

如果您将此设置为 HL7 v2.x,那么所需的数据类型实际上可能是 HL7 v.2.x 的 XML 变体——而不是更熟悉的管道分隔格式。如果您的 hl7 是管道分隔格式,为了进行实验,您可以使用我在上面发布的最后一行代码将其转换为 XML 格式。

于 2012-12-06T18:53:16.897 回答
0

从数据库中获取 blob 的一种简单方法是在您的 select 语句中使用强制转换。

CAST(<Field Name> AS CHAR(10000) CHARACTER SET utf8) AS '<FieldName>'
于 2014-11-28T15:28:03.193 回答