Spring Boot on Windows, invalid temporary upload location - spring-boot

I have a web service built in Spring Boot 2.0.2 and deployed on a Windows 10 based machine.
One of the tasks of the application is to accept an image via a POST request and then move the image to a specific location on the system, i.e. c:\ftp. Initially the application works fine, however, after a period of being left, upon a new request I'm seeing the error below;
Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [C:\\Users\\FRONTIER\\AppData\\Local\\Temp\\tomcat.10182171515108748004.8080\\work\\Tomcat\\localhost\\ROOT] is not valid
I suspect that Windows is deleting old temporary files/folders, resulting in the temporary upload path no longer being present.
Has anyone come across this issue before, and is there a way to fix it?

Hello SheppardDigital,
try adding the property
spring.servlet.multipart.location=C:\\Users\\admin\\Desktop\\Perfect_APP\\
to your application.properties file, this property sets the multipart temp location for uploaded files which the POST requests use.
Be sure to set an absolute URL.

Related

Swift_IoException: Unable to open file for reading from a public url

I am trying to attach a pdf to an email generated using SwiftMailer on Laravel. The pdf is at a publicly accessible location, but I get this error:
Swift_IoException(code: 0): Unable to open file for reading [https://www.mynewdomain.com/myfile.pdf]
Previously this file was accessed with https://www.myolddomain.com/myfile.pdf which still works - the file can be attached correctly. The new domain was set up and the file can be accessed using it through a browser, but for some reason swiftmailer throws this error when trying to read it.
The storage location of the file hasn't been changed. The only new thing is the domain the nginx config which is the same as the old, with the new domain name.
Is there a reason why this wouldn't be working?
Thanks,

odd behaviour with max-swallow-size in Tomcat in spring boot

We have a backend service written in spring boot and UI in Angular.
We are using an Api which does a file upload.
problem :
when we try to upload a large file ~5mb we get an exception : ERR_FAILED_503 but if we upload a small file ~2mb it goes through. When I tried to reproduce this on my local, I could reproduce it. I was getting some connection related issue on my browser console. On further exploration I found that its is a Tomcat related issue.
To test it I tried updating the below configs to my yml :
server:
tomcat:
max-swallow-size: -1
max-http-form-post-size: -1
This actually solved the issue.
My only doubt is this strange behaviour :
Even when we dont put this config, the upload for large files fail, but after uploading a small file, large files also start going through.
I have attached the snapshot of console for reference.
Has anyone experienced this kind of behaviour ? or any hunch, why this could happen ?
Note : the CORS error visible in the console seems to be a false error because when we try uploading the same file after uploading a small file, it uploads successfully
Thanks.
console error on uploading large file

download zip file using Rest API responding null file immediately

I have spring boot API for downloading zip file, when i hit rest API in IE or chrome, API responding with file name as null, with no content, if try to hit the same api again after few seconds, the file getting downloaded.
how to fix this issue.
Please help.
Thanks
Daya
this is due to the filename was set after the content(stream) was written to response, once content was written the control return back to client - before filename was set to the header.

Spring Boot: Static content serving CSS correctly but not JS

We're trying to serve a React app via Spring Boot.
Spring is able to serve the CSS folder's css files (src/main/resources/static/css/), but is not able to serve the JS folder's files (src/main/resources/static/js/). There is a main.8f965741.chunk.js inside the JS folder, and when we run the application, it is returning an error 404.
It is not a browser/caching issue.
It is not a folder/file permissions issue.
Any thoughts on how to debug this? Spring gives us essentially no output for the 404.
You can turn on DEBUG (or TRACE) level logs by adding the following to your application.properties:
logging.level.org.springframework.web: TRACE
Then try requesting the JS file directly, perhaps with curl (e.g., curl http://localhost:8080/js/main.8f965741.chunk.js)
The logs should tell you how the request was mapped and how it was subsequently handled. You can compare the logs generated here with a "known good" request (perhaps from requesting a css file).
If you've built a .jar or .war artifact, you can also unpack it (using jar xf ...) and double check if the js files are properly packaged there.

Web API 404 File or Directory not Found for "root" routes

I am developing a RESTful web api service. It's web api v.1, not v.2. Also I am developing on Visual Studio 2010 SP1. I have installed the MVC 4 for VS2010 SP1.
Please understand and keep in mind that Upgrading to newer versions of VS or Web Api 2 is not an option.
I have the following problem after a Windows Update ocurred.
When I try to use my RESTful api this way....
http://url.com/documents/ (get all the documents) I get the following error...
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Here is the stack trace.
[HttpException]: File does not exist. at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response) at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath) at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state) at system.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
If I specify the action name directly, it works. For example...
http://url.com/documents/get (gets all the documents) or
http://url.com/documents/7 (gets document id=7.
It only fails when you call it by its default name. I have already read similar situations here and I have tried to follow their solutions but they are not working for me properly.
Now, I know this is not a "web api routing" issue because I actually get the .net default exception page html markup (I am using Postman to test my webservice). When I force a "routing issue", then I get a JSON error description, which means that the Controller actually got created in the pipeline and returned a response.
Also, I have a custom file (SecurityHandler) that inherits from DelegatingHandler. This file gets executed almost first in the pipeline with each call to the api. Even before the actual Controller. Well, this file is never called when I get the error, which confirms to me that the "webserver" (either VS Development Server or IIS 7) is the one throwing the exception.
I have exhausted every single solution that I have found here. Change my web.config to multiple handlers configurations, re-installed MVC 4 for VS2010, created an entire new project... all these efforts have shown no results whatsoever.
Like I said, this was working perfectly fine until my pc restarted from a Windows Update BUT... why does it fail in the server as well? I did deploy my api to the server after the error started to occur.
Thanks.
The issue is not in Web API (and has nothing to do with it's version or Visual Studio 2010), it's the static file handler trying to serve and failing.
Alternatives:
0. Do you have a documents folder in your site? Get rid of it.
1. Remove the static file handler for directory browsing and re-add it.
2. Use RAMMFAR (less recommended)

Resources