Getting a parameter from ServletRequest throws illegalStateException - servlets

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.

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)

DeserializationException handeling in RequestResponseTemplate

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"

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.

how to force scrapy exit when there is an exception

I wrote a crawler with Scrapy.
There is a function in the pipeline where I write my data to a database. I use the logging module to log runtime logs.
I found that when my string have Chinese logging.error() will throw an exception. But the crawler keeps running!
I know this is a minor error but if there is a critical exception I will miss it if crawler keeps running.
My question is: Is there a setting that I can force Scrapy stop when there is an exception?
You can use CLOSESPIDER_ERRORCOUNT
An integer which specifies the maximum number of errors to receive
before closing the spider. If the spider generates more than that
number of errors, it will be closed with the reason
closespider_errorcount. If zero (or non set), spiders won’t be closed
by number of errors.
By default it is set to 0
CLOSESPIDER_ERRORCOUNT = 0
you can change it to 1 if you want to exit when you have the first error.
UPDATE
Read the answers of this question, you can also use:
crawler.engine.close_spider(self, 'log message')
for more information read :
Close spider extension
In the process_item function of your spider you have an instance of spider.
To solve your problem you could catch the exceptions when you insert your data, then neatly stop you spider if you catch a certain exeption like this:
def process_item(self, item, spider):
try:
#Insert your item here
except YourExceptionName:
spider.crawler.engine.close_spider(self, reason='finished')
I don't know of a setting that would close the crawler on any exception, but you have at least a couple of options:
you can raise CloseSpider exception in a spider callback, maybe when you catch that exception you mention
you can call crawler.engine.close_spider(spider, 'some reason') if you have a reference to the crawler and spider object, for example in an extension. See how the CloseSpider extension is implemented (it's not the same as the CloseSpider exception).
You could hook this with the spider_error signal for example.

JRun Servlet Error when attepting to use java object

We have a site in ColdFusion which integrates with a credit card provider using java components.
When calling a particular function on a java object:
<cfset ResponseObject = AgentObject.request(RequestObject, LogObject)>
Where ResponseObject, AgentObject and LogObject are java object created like:
<cftry>
<cfset AgentObject = createObject("java","com.providername.client.Agent")>
<cfcatch type="any">
Do something.
</cfcatch>
</cftry>
The following is outputted on the page and execution is halted.
<head>
<title>JRun Servlet Error</title>
</head>
<h1>500 Transaction fails verification<br>
BadRequest: Request fails verification checks<br>
BadCardNumber: Card length was 16, but we were expecting 0<br>
</h1>
<body>
Transaction fails verification<br>
BadRequest: Request fails verification checks<br>
BadCardNumber: Card length was 16, but we were expecting 0<br>
</body>
The error is expected (we're checking card details), but I don't seem to be able to catch it. A cftry and cfcatch has no effect, so I'm totally at a loss as to how I can handle this error and continue execution.
Can anyone help?
Cheers,
Tom
Edit - additional error information
I thought it may also be useful to post this stack trace. It's not accessible via Coldfusion, but instead is logged to a file as part of LogObject above presumably in the Java code:
com.providername.client.errors.VerifyErrorReport: Transaction fails verification
com.providername.client.errors.BadRequest: Request fails verification checks
com.providername.client.errors.BadCardNumber: Card length was 16, but we were expecting 0
at com.providername.util.CardInfo.verifyCardNumber(CardInfo.java:412)
at com.providername.util.CardInfo.validateCardInfo(CardInfo.java:789)
at com.providername.util.CardInfo.validateCardInfo(CardInfo.java:838)
at com.providername.client.Agent.setupTransaction(Agent.java:681)
at com.providername.client.Agent.setupTransaction(Agent.java:692)
at com.providername.client.Agent.request(Agent.java:281)
at sun.reflect.GeneratedMethodAccessor53.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:74)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:1634)
at cfprovidername2ecfc526409752$funcSENDXMLOBJECT.runFunction(D:\site\components\providername.cfc:210)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:344)
at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:290)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:254)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:56)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:207)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:169)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:1807)
at cftransactions2ecfc114461696$funcTRANSACTION.runFunction(D:\site\components\transactions.cfc:175)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:344)
at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:290)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:254)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:56)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:207)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:366)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:198)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:157)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:1594)
at coldfusion.tagext.lang.InvokeTag.doEndTag(InvokeTag.java:341)
at cfauthorise2dprovidername2ecfm1546743078._factor7(D:\site\payment\authorise-providername.cfm:224)
at cfauthorise2dprovidername2ecfm1546743078._factor27(D:\site\payment\authorise-providername.cfm:164)
at cfauthorise2dprovidername2ecfm1546743078._factor30(D:\site\payment\authorise-providername.cfm:91)
at cfauthorise2dprovidername2ecfm1546743078.runPage(D:\site\payment\authorise-providername.cfm:1)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:152)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:349)
at coldfusion.runtime.CfJspPage._emptyTag(CfJspPage.java:1915)
at cfauthorise2ecfm767248619.runPage(D:\site\payment\authorise.cfm:10)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:152)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:349)
at coldfusion.runtime.CfJspPage._emptyTag(CfJspPage.java:1915)
at cftemplate2ecfm1091873885._factor4(D:\site\server\template.cfm:247)
at cftemplate2ecfm1091873885.runPage(D:\site\server\template.cfm:1)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:152)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:349)
at coldfusion.runtime.CfJspPage._emptyTag(CfJspPage.java:1915)
at cfapplication2ecfm1526755454._factor31(D:\site\application.cfm:673)
at cfapplication2ecfm1526755454.runPage(D:\site\application.cfm:1)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:152)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:349)
at coldfusion.runtime.CfJspPage._emptyTag(CfJspPage.java:1915)
at cfApplication2ecfm1608241748.runPage(D:\site\payment\Application.cfm:30)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:152)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:349)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.CfincludeFilter.include(CfincludeFilter.java:33)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:172)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:51)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:86)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:69)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:115)
at coldfusion.CfmServlet.service(CfmServlet.java:107)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:78)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:257)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:541)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:204)
at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:318)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:426)
at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:264)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
I'm a bit late to the party on this, but what you're getting is not a JRun error per se. It seems that the error is thrown in the JRE and JRun is showing it as a "Servlet Error". Notice the lines in your stack trace:
com.providername.client.errors.VerifyErrorReport: Transaction fails verification
com.providername.client.errors.BadRequest: Request fails verification checks
com.providername.client.errors.BadCardNumber: Card length was 16, but we were expecting 0
at com.providername.util.CardInfo.verifyCardNumber(CardInfo.java:412)
That looks like an error thrown by the CardInfo class within verifyCardNumber() on line 412. I think JRun just serves the error as a "Servlet Error" because there's a hard stop in com.providername.client.errors.VerifyErrorReport.
This also might be the reason your <cfcatch> won't catch that exception. The Java class might catch that error and throw that exception within Java which causes that ugly JRun 500 error.
If you don't have the source of the Java to inspect why you're getting that exception in CardInfo, then you should contact the people who own the source to see if they have any insight.
I hope this is in some way helpful to you.

Resources