DeserializationException handeling in RequestResponseTemplate - spring-kafka

I am having trouble understanding how to handle deserialization exceptions during the use of RequestResponseTemplate. I create this RequestResponseTemplate by configuring DefaultKafkaProducerFactory & KafkaMessageListenerContainer(StringDeserializer, CustomDeserializer)
Problem:
Handle the deserialization error during deserilization of the value (thrown by the CustomDeserializer) by logging and moving to the next record.
Solution (tried and failed):
setCommonErrorHandler(new CommonLoggingErrorHandler()) on KafkaMessageListenerContainer
I thought this class would commit the offset of the failed record as isAckAfterHandle being set to true by default. However the offset is not commited and consumer.poll() enters into an loop.
Question: How to handle deserialization exceptions similar to LogAndContinue manner in spring cloud streams?
Stacktrace:
"#timestamp":"2022-12-13 13:23:19.726","#version":"1","message":"Error occurred while not processing records",
"logger": org.springframework.kafka.listener.CommonLoggingErrorHandler,"thread":"Container-C-1","level":"ERROR",
"stacktrace": org.apache.kafka.common.errors.RecordDeserializationException : Error deserializing key/value for partition politie.sensing.sys.melding-waarneming-response.0-0 at offset 5.
If needed, please seek past the record to continue consumption.\r\n
org.apache.kafka.clients.consumer.internals.Fetcher.parseRecord(Fetcher.java:1448)\r\n
org.apache.kafka.clients.consumer.internals.Fetcher.access$3400(Fetcher.java
:135)\r\n\tat org.apache.kafka.clients.consumer.internals.Fetcher$CompletedFetch.fetchRecords(Fetcher.java:1671)\r\n\tat org.apache.kafka.clients.consumer.internals.Fetcher$CompletedFetch.access$1900(Fetcher.java:1507)\r\n
org.apache.kafka.clients.consumer.internals.Fetcher.fetchRecords(Fetcher.jav
a:733)\r\n
org.apache.kafka.clients.consumer.internals.Fetcher.fetchedRecords(Fetcher.java:684)\r\n
org.apache.kafka.clients.consumer.KafkaConsumer.pollForFetches(KafkaConsumer.java:1277)\r\n
org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1238)\r\n\tat
org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1211)\r\n\tat
org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.pollConsumer(KafkaMessageListenerContainer.java:1529)\r\n
org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doPoll(KafkaMessageListenerContainer.java:1519)\r\n
org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.pollAndInvoke(KafkaMessageListenerContainer.java:1343)\r\n
org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:1255)\r\n
java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)\r\n
java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)\r\n
java.base/java.lang.Thread.run(Thread.java:832)\r\nCaused by: java.lang.IllegalArgumentException: Can't deserialize data [[..content is redacted..]]\r\n
my.library.common.kafka.serializer.JsonDeserializer.deserialize(JsonDeserializer.java:77)\r\n
org.apache.kafka.common.serialization.Deserializer.deserialize(Deserializer.java:60)\r\n\tat org.apache.kafka.clients.consumer.internals.Fetcher.parseRecord(Fetcher.java:1439)\r\n
... 15 common frames omitted\r\n","application":"my-micro-sens-service"

Related

Biztalk Server 2020: Invalid Character found

When sending EDI INVOIC I receive the following error:
Uncaught exception (see the 'inner exception' below) has suspended an instance of service 'Microsoft.BizTalk.Edi.BatchSuspendOrchestration.BatchElementSuspendService(52b477a6-f224-d7ee-a40d-92c8ad5f5544)'.
The service instance will remain suspended until administratively resumed or terminated.
If resumed the instance will continue from its last persisted state and may re-throw the same unexpected exception.
InstanceId: 2194c57a-bdb1-4bb7-9c7b-9e6f884af3a2
Shape name: Throw that an error has occured
ShapeId: 209c5624-f52a-404d-b44d-d8fb41b0fed4
Exception thrown from: segment 2, progress 33
Inner exception: The batch element is being suspended as it either failed schema validation or context properties are not matching batch definition. The error is : Stopping after the first error !!
Error: 1 (Field level error)
SegmentID: FTX
Position in TS: 5
Data Element ID: C10801
Position in Segment: 5
Position in Field: 1
Data Value: Bezüglich der späteren Entgeltminderung verweisen wir auf die
21:
This happens only by two out three identities of the partner and only it the text contains umlauts. Only this partner has this problem, every other partner is not affected.
I've change everything, change encoding, ports, etc.
I ended up deleting the business profiles and agreements, and recreating them with the same settings. That solved my problem but it would be good to know why it didn't work from the beginning.
EDI Character Sets (Microsoft.com)
An EDIFACT-encoded interchange is self-describing in terms of its character set. The UNB1 data element is used. EDIFACT requires that tag names and separators/delimiters are ASCII types; as a result, locating UNB1 to apply the relevant code page for the remaining interchange is possible.
So check the UNB1, and I think you will find that it in probably UNOA or UNOB that don't support those characters. If it is, then your partner needs to update it at their end to have the correct character encoding set in the payload.
See also EDIFACT Encoding – EDI Character Set Support (Sandro Pereira's blog)

How can my Flask app check whether a SQLite3 transaction is in progress?

I am trying to build some smart error messages using the #app.errorhandler (500) feature. For example, my route includes an INSERT command to the database:
if request.method == "POST":
userID = int(request.form.get("userID"))
topicID = int(request.form.get("topicID"))
db.execute("BEGIN TRANSACTION")
db.execute("INSERT INTO UserToTopic (userID,topicID) VALUES (?,?)", userID, topicID)
db.execute("COMMIT")
If that transaction violates a constraint, such as UNIQUE or FOREIGN_KEY, I want to catch the error and display a user-friendly message. To do this, I'm using the Flask #app.errorhandler as follows:
#app.errorhandler(500)
def internal_error(error):
db.execute("ROLLBACK")
return render_template('500.html'), 500
The "ROLLBACK" command works fine if I'm in the middle of a database transaction. But sometimes the 500 error is not related to the db, and in those cases the ROLLBACK statement itself causes an error, because you can't rollback a transaction that never started. So I'm looking for a method that returns a Boolean value that would be true if a db transaction is under way, and false if not, so I can use it to make the ROLLBACK conditional. The only one I can find in the SQLite3 documentation is for a C interface, and I can't get it to work with my Python code. Any suggestions?
I know that if I'm careful enough with my forms and routes, I can prevent 99% of potential violations of db rules. But I would still like a smart error catcher to protect me for the other 1%.
I don't know how transaction works in sqlite but what you are trying to do, you can achieve it by try/except statements
use try/except within the function
try:
db.execute("ROLLBACK")
except:
pass
return render_template('500.html'), 500
Use try/except when inserting data.
from flask import abort
try:
userID = int(request.form.get("userID"))
[...]
except:
db.rollback()
abort(500)
I am not familiar with sqlite errors, if you know what specific error occurs except for that specific error.

Getting a parameter from ServletRequest throws illegalStateException

I have this code in one of the filter which is called on every request.
httpRequest.getParameter(tabId);
My request was failing continuiosly after filters. On debugging I found that this code throws this exception on the first time, now say if I execute this code using "inspect" it throws this exception and if I execute it again using "inspect" or "forward debug" it give "null" and completes the flow. I dont understand why it works like this on first execution of this code as there is not "tabId" in request.
18:44:03,443 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/workbench].[action]] (http-0.0.0.0:8090-5) JBWEB000236: Servlet.service() for servlet action threw exception: java.lang.IllegalStateException: JBWEB002004: More than the maximum number of request parameters (GET plus POST) for a single request (128) were detected. Any parameters beyond this limit have been ignored. To change this limit, set the maxParameterCount attribute on the Connector.
at org.apache.tomcat.util.http.Parameters.addParameter(Parameters.java:184) [jbossweb-7.5.28.Final-redhat-1.jar:7.5.28.Final-redhat-1]
at org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:356) [jbossweb-7.5.28.Final-redhat-1.jar:7.5.28.Final-redhat-1]
at org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:213) [jbossweb-7.5.28.Final-redhat-1.jar:7.5.28.Final-redhat-1]
at org.apache.catalina.connector.Request.parseParameters(Request.java:2885) [jbossweb-7.5.28.Final-redhat-1.jar:7.5.28.Final-redhat-1]
at org.apache.catalina.connector.Request.getParameter(Request.java:1303) [jbossweb-7.5.28.Final-redhat-1.jar:7.5.28.Final-redhat-1]
at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:350) [jbossweb-7.5.28.Final-redhat-1.jar:7.5.28.Final-redhat-1]
**at com.xyz.IdentityFilter.doFilter(IdentityFilter.java:58) [projectX.jar:]**
The request body has already been consumed, you have to wrap it in your filter (before the doFilter(...) call) if you need to do business logic on it. See here for an example.

What is causing the exception HRESULT: 0xC0C01B22 when attempting to enlist a send port with a filter?

This is a simple send port, in which I'm trying to setup a filter over a promoted property. Whenever I attempt to enlist this port, I get the following error:
===================================
Could not update Send Port 'SendPort1' in Message Box. Exception from HRESULT: 0xC0C01B22 (Microsoft.BizTalk.ExplorerOM)
------------------------------
For help, click: http://go.microsoft.com/fwlink/?LinkId=47400&ProdName=Microsoft+BizTalk+Server+2013&ProdVer=3.10.229.0&EvtSrc=Microsoft.BizTalk.ExplorerOM.Resources&EvtID=IDS_ERR_SENDPORT_UPDATE
------------------------------
Program Location:
at Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer.SaveChangesWithTransaction(Object transactionObj)
at Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer.SaveChanges()
at Microsoft.BizTalk.Administration.SnapIn.Forms.Common.ExplorerPropertyPagesContainer.CommitChanges()
at Microsoft.BizTalk.SnapIn.Framework.Forms.PropertyPagesContainer.Store()
at Microsoft.BizTalk.SnapIn.Framework.Forms.SheetFramework.Store()
The filter simply checks for existence of the promoted property in the incoming message. There's only one post in MSDN forums about this exception: HRESULT 0xC0C01B22
Any idea what is causing this?
The answer is in this page: https://learn.microsoft.com/en-us/biztalk/core/promoting-properties
The note there says the following:
XSD Data Type of base64Binary, duration, ENTITES, hexBinary, IDREFS, long, NMTOKENS, and unsignedLong are not supported for promotion.
Turns out, in our case, the promoted property is of xs:long type. I changed the element type to xs:string then the issue in the question went away.
It would make sense to prevent the promotion of the elements if they are of unsupported type, in the beginning itself. But we don't get to see any alerts during the promotion phase for such elements.
Hope this helps someone.

getting 409 error when trying to call table.CreateIfNotExists() for the first time

When starting my program for the first time since the associated table has been deleted I get this error:
An exception of type 'Microsoft.WindowsAzure.Storage.StorageException' occurred in Microsoft.WindowsAzure.Storage.dll but was not handled in user code
Additional information: The remote server returned an error: (409) Conflict.
However if I refresh the crashed page the table will successfully create.
Here is the code just in case:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
Microsoft.WindowsAzure.CloudConfigurationManager.
GetSetting("StorageConnectionString"));
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference("tableTesting");
table.CreateIfNotExists();
I don't really understand how or why I'd be getting a conflict error if there's nothing there.
These errors appear elsewhere in my code as well when I'm working with blob containers, but I can't reproduce them as easily.
If you look at the status codes here: http://msdn.microsoft.com/en-us/library/azure/dd179438.aspx, you will notice that you get 409 error code in two scenarios:
Table already exists
Table is being deleted
If I understand correctly, table.CreateIfNotExists() only handles the 1st situation but not the 2nd one. Please check if that is not the case in your situation. One way to check this would be to see details of Storage Exception. Somewhere you should get the code which would match with the link I mentioned above.
Also one important thing to understand is that when you delete the table, it is actually marked for deletion and is actually deleted through a background process (much like garbage collection). If you try to create a table between these two steps, you will get the 2nd error.

Resources