0
votes

I am working on an application where I am connecting to SQS queue through Apache Camel which requires only AmazonSQS client (I couldn't find any references of Camel + AWS SDK and Java 2.x) as parameter as part of SQS queue URL.

As part of the same application I am doing different operations in SQS one among them is delete message. While deleting the message from AWS SQS queue using AmazonSQS.delete(queueURL, receiptHanlde). Below is the exception being thrown by the same. However the message is being deleted from the queue. Looks like it's trying to parse the response after deleting the message and failing.

Please suggest how to resolve the exception.

com.amazonaws.SdkClientException: Unable to unmarshall response (ParseError at [row,col]:[1,1] Message: Content is not allowed in prolog.). Response Code: 200, Response Text: at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleResponse(AmazonHttpClient.java:1681) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleSuccessResponse(AmazonHttpClient.java:1422) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1344) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1127) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:784) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:752) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:726) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:686) at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:668) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:532) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:512) at com.amazonaws.services.sqs.AmazonSQSClient.doInvoke(AmazonSQSClient.java:2207) at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2174) at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2163) at com.amazonaws.services.sqs.AmazonSQSClient.executeDeleteMessage(AmazonSQSClient.java:893) at com.amazonaws.services.sqs.AmazonSQSClient.deleteMessage(AmazonSQSClient.java:865) at com.orchestrator.api.processor.BenefitFocusSoldCaseProcessor.soldCaseProcess(BenefitFocusSoldCaseProcessor.java:72) at com.orchestrator.api.processor.BenefitFocusSoldCaseProcessor.process(BenefitFocusSoldCaseProcessor.java:35) at org.apache.camel.support.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:66) at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:395) at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:148) at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:60) at org.apache.camel.processor.Pipeline.process(Pipeline.java:147) at org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:312) at org.apache.camel.component.aws.sqs.SqsConsumer.processBatch(SqsConsumer.java:213) at org.apache.camel.component.aws.sqs.SqsConsumer.poll(SqsConsumer.java:111) at org.apache.camel.support.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:190) at org.apache.camel.support.ScheduledPollConsumer.run(ScheduledPollConsumer.java:107) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1] Message: Content is not allowed in prolog. at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:604) at com.sun.xml.internal.stream.XMLEventReaderImpl.peek(XMLEventReaderImpl.java:276) at com.amazonaws.transform.StaxUnmarshallerContext.nextEvent(StaxUnmarshallerContext.java:220) at com.amazonaws.services.sqs.model.transform.DeleteMessageResultStaxUnmarshaller.unmarshall(DeleteMessageResultStaxUnmarshaller.java:40) at com.amazonaws.services.sqs.model.transform.DeleteMessageResultStaxUnmarshaller.unmarshall(DeleteMessageResultStaxUnmarshaller.java:28) at com.amazonaws.http.StaxResponseHandler.handle(StaxResponseHandler.java:106) at com.amazonaws.http.StaxResponseHandler.handle(StaxResponseHandler.java:42) at com.amazonaws.http.response.AwsResponseHandlerAdapter.handle(AwsResponseHandlerAdapter.java:69) at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleResponse(AmazonHttpClient.java:1657) ... 34 more

1
Better practice to use V2, see my answer below.smac2020

1 Answers

0
votes

You are using V1 which is com.amazonaws.services.sqs.AmazonSQSClient.

Amazon recommends using AWS SDK for Java 2.x, which is a major rewrite of the 1.11.x code base built on top of Java 8+. Java SDK 2.x has improved consistency, ease of use, and strongly enforced immutability. It also has support for non-blocking I/O and the ability to plug in a different HTTP implementation at run time.

You can find the V2 example for this use case here.

https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javav2/example_code/sqs/src/main/java/com/example/sqs/SQSExample.java

If you are not famalar with the AWS SDK for Java V2, may I suggest that you read this doc:

Get started with the AWS SDK for Java 2.x

Just tested that code example and it works without issue.