Quarkus - 413 Request Entity Too Large - java

I am developing a Quarkus application and using RESTEasy Reactive. One of the endpoints receives a multipart/form-data mime type object but when I try to use it sometimes the "413 - Request Entity too Large" error occurs.

After digging the Quarkus documentation, the property you really need to configure is this:
quarkus.http.limits.max-form-attribute-size
I have set this to 4M (4 megabytes), like this, on my application.yaml file, but of course you can configure it for any value you may want:
quarkus:
http:
limits:
max-form-attribute-size: 4M
Keep in mind that if you are using an application.properties file instead, you should do it like this:
quarkus.http.limits.max-form-attribute-size=4M

Related

Request timeout for endpoint using StreamingResponseBody in Spring

I have a spring MVC endpoint returning StreamingResponseBody so I can stream big file instead of keeping it in memory.
The request can take a while to download so it is timing out. I can fix it by setting spring.mvc.async.request-timeout=360000, but I don't want this setting to apply globally to all endpoints.
Is there way to set request-timeout only for this specific endpoint?
I did find Set timeout for specific async request in Spring-boot, but I don't think that applies to my code using StreamingResponseBody.
I have also found Spring REST endpoint returning StreamingResponseBody: AsyncRequestTimeoutException after 30 seconds, which doesn't have the desired effect.

Configuring thread pool profile in spring boot camel application

We are modernizing one of our applications and we decided to use Spring Boot together with Apache Camel.
One of the configuration files from old version has something like this:
<camel:threadPoolProfile id="myThreadPoolProfile"
poolSize="10" maxPoolSize="20" maxQueueSize="1000" rejectedPolicy="DiscardOldest" />
What I saw in camel documentation on this link is that there is possibility to configure basically the same thing we have in old version. But then I got stuck on id field. It's missing, but there is property camel.threadpool.config which explanation sounds something I need (Adds a configuration for a specific thread pool profile (inherits default values)), but so far I am struggling to make a use of it. I tried something like this:
camel:
threadpool:
pool-size: 10
max-pool-size: 20
max-queue-size: 1000
rejected-policy: discardoldest
config:
id: "myThreadPoolProfile"
I am getting following error:
Description:
Failed to bind properties under 'camel.threadpool.config.id' to org.apache.camel.spring.boot.threadpool.CamelThreadPoolConfigurationProperties$ThreadPoolProfileConfigurationProperties:
Reason: No converter found capable of converting from type [java.lang.String] to type [org.apache.camel.spring.boot.threadpool.CamelThreadPoolConfigurationProperties$ThreadPoolProfileConfigurationProperties]
I guess I don't understand how this spring boot configuration works.
Ok I found an answer, or better to say example here. So the syntax for what I was trying to do would be following:
camel:
threadpool:
pool-size: 10
max-pool-size: 20
max-queue-size: 1000
rejected-policy: discardoldest
config[myThreadPoolProfile]:
id: "myThreadPoolProfile"
If you carefully notice the error you are trying to map String to Properties(Map).
See below there is no such property available in configuration map hence its failing.
I have also checked in detail with latest javadoc for the same class. You can refer the same to check what all fields are available.
https://javadoc.io/doc/org.apache.camel.springboot/camel-spring-boot/latest/org/apache/camel/spring/boot/threadpool/CamelThreadPoolConfigurationProperties.ThreadPoolProfileConfigurationProperties.html
Below are the available properties in spring boot camel starter.
https://camel.apache.org/camel-spring-boot/latest/spring-boot.html

Couchbase DefaultOrphanResponseReporter Orphan responses observed

I have a SpringBoot 2 app that uses using Spring Data Couchbase.
I have this message on the logs every minute
2019-11-12 13:48:48,924 WARN : gid: trace= span= [cb-orphan-1] c.c.c.c.t.DefaultOrphanResponseReporter Orphan responses observed: [{"top":[{"r":"10.120.93.220:8092","s":"view","c":"5BE128F6F96A4D28/FFFFFFFFDA2C8C52","l":"10.125.216.233:49893"}],"service":"view","count":1}]
That is from the new Response Time Observability feature underlying the Java SDK.
It would seem to indicate that you have view requests which are timing out, but eventually received later, but I have no views defined in Couchbase DB
I would like to know if it is possible to disable OrphanResponseLogReporter via YML file config in a SpringBoot app. , setting the logIntervalNanos to 0
No, unfortunately, you cannot do it. Only a subset of Couchbase's configuration properties is supported in the application.yml, namely the ones present in the CouchbaseProperties.java class.
You could although use an environment variable: com.couchbase.orphanResponseReportingEnabled=false. It is independent of Spring, it's read directly by Couchbase SDK.
Edit:
As a workaround, you can set logging level in the application.yml:
logging.level.com.couchbase.client.core.tracing.DefaultOrphanResponseReporter: ERROR

Setting Spring Boot property server.compression.enabled to true doesn't get applied to the autoconfigured Tomcat Server

I'm using Spring Boot 2.0.6.RELEASE and trying to get the internal Tomcat server to GZip the responses from the API I'm working on. As per the spring boot documentation https://docs.spring.io/spring-boot/docs/2.0.6.RELEASE/reference/htmlsingle/#how-to-enable-http-response-compression adding server.compression.enabled=true to the application.properties should enable embedded web server's compression.
However the response I'm getting from the API doesn't look compressed.
I've followed this question Spring boot response compression not working and when inspecting the ServerProperties's Compression object when application starts up, it looks like the enabled property is set to false.
What am I missing here?
Specify mime-types with compression like below.
server.compression.enabled=true
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain
Compression is disabled if strong Etag is enabled. I was using ShallowEtagHeaderFilter and as soon as I removed it, compression started working.

AWS Instance Profile doesn't work with Spring Cloud AWS

I have a small Spring Boot app, using Spring Cloud AWS (1.0.0.RELEASE) to access SQS queue. It is beeing deployed on an EC2 instance with Instance Profile set. It appears that AWS side of things is working, as I can access both relevant metadata links: iam/info and iam/security-credentials/role-name, and they do contain correct information. Just to be sure, I've used aws cmdline utility (aws sqs list-queues) and it does work, so I guess setup is ok. However, when the app starts, it reads application.properties (which contains line cloud.aws.credentials.instanceProfile=true) then drops following warning: com.amazonaws.util.EC2MetadataUtils: Unable to retrieve the requested metadata and finally throws following exception:
Caused by: com.amazonaws.AmazonServiceException: The security token included in the request is invalid. (Service: AmazonSQS; Status Code: 403; Error Code: InvalidClientTokenId; Request ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:1071)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:719)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:454)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:294)
at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2291)
at com.amazonaws.services.sqs.AmazonSQSClient.getQueueUrl(AmazonSQSClient.java:516)
at com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient.getQueueUrl(AmazonSQSBufferedAsyncClient.java:278)
at org.springframework.cloud.aws.messaging.support.destination.DynamicQueueUrlDestinationResolver.resolveDestination(DynamicQueueUrlDestinationResolver.java:78)
at org.springframework.cloud.aws.messaging.support.destination.DynamicQueueUrlDestinationResolver.resolveDestination(DynamicQueueUrlDestinationResolver.java:37)
at org.springframework.messaging.core.CachingDestinationResolverProxy.resolveDestination(CachingDestinationResolverProxy.java:88)
at org.springframework.cloud.aws.messaging.listener.AbstractMessageListenerContainer.start(AbstractMessageListenerContainer.java:295)
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.start(SimpleMessageListenerContainer.java:38)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
... 17 common frames omitted
...which means that for some reason Spring Cloud AWS is not picking up on Instance Profile credentials. I've enabled debug log level on com.amazonaws.request and it appears that request is sent without access key and secret key.
DEBUG --- com.amazonaws.request : Sending Request: POST https://sqs.eu-west-1.amazonaws.com / Parameters: (Action: GetQueueUrl, Version: 2012-11-05, QueueName: xxxxxxxxxxxxx, ) Headers: (User-Agent: aws-sdk-java/1.9.3 Linux/3.14.35-28.38.amzn1.x86_64 Java_HotSpot(TM)_64-Bit_Server_VM/25.45-b02/1.8.0_45 AmazonSQSBufferedAsyncClient/1.9.3, )
Anybody has any idea what am I missing or at least any hints how to further debug this?
EDIT: After going through spring-cloud-aws code a bit, I've kinda moved forward. Configuration file application.properties bundled with jar had some text value for accessKey and secretKey. My customized application.properties haven't got those properties and that probably caused spring to use values in bundled file as defaults. I've included them with empty values, which changed the exception to com.amazonaws.AmazonClientException: Unable to load AWS credentials from any provider in the chain. It appears that AWS SDK is configured with DefaultProviderChain, yet it still fails to pick up instance profile credentials.
The solution to this problem comes from two distinct facts.
Instance profile credentials are going to be used only and only if application.properties has instanceProfile property set to true and accessKey set to null (ContextCredentialsAutoConfiguration).
Even if you will provide your custom application.properties file, Spring is going to read application.properties file bundled with app jar (if it does exist). If that's the case, properties from both files will sum up to create an execution enviroment. I suspect that bundled file is parsed first, then custom second, overriding any property present in bundled file.
In my case, bundled application.properties had accessKey and secretKey placeholders (with phony values) which were filled out by developer whenever he wanted some testing outside of EC2 enviroment. That made accessKey not null and therefore, excluded instance profile path. I just removed the application.properties file from jar and that solved the problem.
cloud:
aws:
credentials:
accessKey:
secretKey:
instanceProfile: true
useDefaultAwsCredentialsChain: true
This would do the trick, if you were using the latest (2.X.X) Spring AWS Cloud.

Categories

Resources