Support Questions
Find answers, ask questions, and share your expertise

Nifi Replace Text Error (Response) : Transferring to failure

Solved Go to solution

Nifi Replace Text Error (Response) : Transferring to failure

Good morning everybody,

 

I have the following JSON return:

{
"RegistrosRecebidos" : 1,
"RegistrosImportados" : 0,
"Erros" : [ "Erro registro 0: The statement has been terminated.\r\nString or binary data would be truncated in table 'Ober_HML.dbo.DB_WS_IMP_CLIENTE', column 'NOME_FANTASIA'. Truncated value: 'ADLER PELZER PERNAMBUCO IND. E COMERCIO '." ]
}

 

By default from our supplier, it comes with some formatting. That in Nifi gives the following error:

 

leandrolinof_0-1620300724595.png


Follow my flow:

 

leandrolinof_1-1620300781412.png

 

How can I do to solve this problem in Nifi?

 

I am trying to use ReplaceText for this but I have not been successful.

 

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Nifi Replace Text Error (Response) : Transferring to failure

Master Guru

@leandrolinof 

The "EvaluateJsonPath" processor you shared has the configured destination as a FlowFile-Attribute and thus leaves the content of the FlowFile unchanged.

So if FlowFile Attribute is where you want this parsed output to reside, you could use "ExtractText" [1] as an alternative solution.

MattWho_0-1620392099103.png

The used value here would be:

.*Erros":\[(.*)\].*

This has only 1 capture group which is for the content you are trying to extract.  That content is then added to the FlowFile in a new FlowFile attribute based on the property name.

 


If you instead want to replace the content of your FlowFile with only the portion of the original content you are trying to extract, you could use the "ReplaceText" [2] processor.

MattWho_1-1620392199474.png

The used Java regex "Search value" here would be:

(.*Erros":\[)(.*)(\].*$)

Which breaks source content into 3 capture groups so regex matches entire content and capture group 2 matches on the string output you are looking for.
So "Replacement Value" is simply set to "$2" so that entire content is replaced with just contents of capture group 2.

[1] http://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.13.2/org.apache...

[2] http://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.13.2/org.apache...

 

If you found this help you with your question, please take a moment to login and click accept on this solution.

Thanks,

Matt

View solution in original post

4 REPLIES 4

Re: Nifi Replace Text Error (Response) : Transferring to failure

Master Guru

@leandrolinof 

The shared bulletin is being produced by the EvaluateJsonPath processor.

It may be helpful if you share your current ReplaceText processor configuration, sample input file (prior to ReplaceText), desired output file (post ReplaceText), and the configuration of your EvaluateJsonPath processor. 

Use case details are also very helpful to understand what your end-to-end goal is here.

Thanks,

Matt

Re: Nifi Replace Text Error (Response) : Transferring to failure

@MattWho  Thank you for your help,

 

This is all my flow:

leandrolinof_0-1620331869054.png

 

I send a JSON like this :

{
"User": "user",
"Key": "ABC",
"Table": "Table",
"Rows": [
{
"CODIGO": 1,
"NOME": "ABC REPRESENTACOES LTDA",
"NOME_FANTASIA": "PEDRO LIMA",
"ENDERECO": "RUA SANTOS, 178",
"BAIRRO": "",
"CIDADE": "SAO PAULO",
"UF": "SP",
"CEP": "11008999",
"TELEFONE": "(11) 99887 1234",
"EMAIL": "pedro.lima@email.com",
"FUNCAO": "REPRESENTANTE",
"CODIGO_SUPERIOR": "",
"CNPJ": "",
"INSCRICAO_ESTADUAL": "",
"NRO_CONTRATO": "8918-A",
"NRO_REG_EMPREGADO": "",
"DATA_CONTRATACAO": "2018/06/28",
"DATA_DESLIGAMENTO": "",
"SITUACAO": "ATIVO",
"REGIAO": "SP"
}
]
}

 

And at some point the API called returns an error, that at some point I need to deal with in order to insert the error in our database. This error is expected in the HTTP response.

 

Follows the configuration of the processors:

 

ReplaceText =

leandrolinof_1-1620332300647.png

 

EvaluateJsonPath = 

leandrolinof_2-1620332356203.png

 

This is Response Before Replace Text = 

{"RegistrosRecebidos":1,"RegistrosImportados":0,"Erros":["Erro registro 0: The statement has been terminated.\r\nString or binary data would be truncated in table \u0027Ober_HML.dbo.DB_WS_IMP_CLIENTE\u0027, column \u0027NOME_FANTASIA\u0027. Truncated value: \u0027ADLER PELZER PERNAMBUCO IND. E COMERCIO \u0027."]}

 

What I need is to take the value of the "Errors" property and save it in my database, only when trying to do this with EvaluateJsonPath it returns the following error:

leandrolinof_3-1620385699582.png

 

For this reason I am trying to use ReplaceText but also without success.

 

I don't know if I managed to be clear enough in my doubt.

Re: Nifi Replace Text Error (Response) : Transferring to failure

Master Guru

@leandrolinof 

The "EvaluateJsonPath" processor you shared has the configured destination as a FlowFile-Attribute and thus leaves the content of the FlowFile unchanged.

So if FlowFile Attribute is where you want this parsed output to reside, you could use "ExtractText" [1] as an alternative solution.

MattWho_0-1620392099103.png

The used value here would be:

.*Erros":\[(.*)\].*

This has only 1 capture group which is for the content you are trying to extract.  That content is then added to the FlowFile in a new FlowFile attribute based on the property name.

 


If you instead want to replace the content of your FlowFile with only the portion of the original content you are trying to extract, you could use the "ReplaceText" [2] processor.

MattWho_1-1620392199474.png

The used Java regex "Search value" here would be:

(.*Erros":\[)(.*)(\].*$)

Which breaks source content into 3 capture groups so regex matches entire content and capture group 2 matches on the string output you are looking for.
So "Replacement Value" is simply set to "$2" so that entire content is replaced with just contents of capture group 2.

[1] http://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.13.2/org.apache...

[2] http://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.13.2/org.apache...

 

If you found this help you with your question, please take a moment to login and click accept on this solution.

Thanks,

Matt

View solution in original post

Re: Nifi Replace Text Error (Response) : Transferring to failure

@MattWho 

 

Thanks for the time available for my problem, the "ExtractText" worked perfectly for my case and the data was saved in my database.

 

Grateful.