Clear web pages cache in jboss - caching

I develop a web app:
frontend javascript
transport json
backend Java EE
JBoss AS 6.1
All static html and js files are in an exploded .war directory which itself is in an exploded .ear directory.
Normally everything works fine! Today I changed a html file and copied it to the .war directory.
When the browser loaded the file it was the old one. So I started wireshark and saw in wireshark the get request and the returned OLD file, even when I changed the filename in the .war directory.
So there is some caching in jboss. I started Googling and found some posts about the tmp and work folders.
I looked in my "...\server\default\work..." folders, but everything was empty.
In "...\server\default\tmp" I found some files but no one seems to be related to my cached page.

As this is a tomcat-in-jboss issue, you have to go to the tomcat area in jboss.
In my case ..\server\default\deploy\jbossweb.sar. In this directory you should find a file called context.xml.
Now stop jboss.
In the context tag there are 2 attributes - cookies and crossContext. Now just add the attribute cachingAllowed="false" and start jboss again:
<Context cookies="true" crossContext="true" cachingAllowed="false">

If you need only one time solution, just create fresh ear with fixed HTML file, undeploy the old one and deploy the new one.

Related

How to deploy Static Vue application with Spring Boot on a Weblogic Server?

I have a Spring boot application deployed on a Weblogic server, and I want to add a Vue/vite frontend to it. I created a Vue project and then built it into static assets. I then placed the contents of the resulting Dist folder (index.html and assets folder) into src/main/resources/static of the Spring Boot project.
Then I generate the war file using Maven, and host that on Weblogic. The Spring Boot section of the app functions as normal, but when I navigate to weblogicurl/myapp/index.html- it is just a blank page rather than the complete frontend I'm expecting. Upon inspection, the blank index.html does have the standard Vue div element with id of "app", so weblogic is detecting and showing the static frontend. However, it is not able to pull any assets to actually display html or use the js - as it is 404ing when index.html tries to pull those built files.
I'm thinking that maybe it's because index.html is trying to pull the js and css assets from /weblogicurl/assets rather than /weblogicurl/myapp/assets but I'm not entirely sure as I'm unfamiliar with the intended structure of a Spring Boot Web app hosted on Weblogic. If that is the case, how would I resolve it? Though maybe it's some other issue, so any input would be greatly appreciated.
I'm assuming that your index.html has src URLs starting with / and that would cause weblogic to look in its default js assets folder. Alternatively, the src might include assets in the URL.
In any cases, you should update these URLs to be relative and correct after build aka remove the starting / and check path from html to js.
Turns out the problem was indeed that it was pulling assets from /weblogicurl rather than /weblogicurl/myapp.
Adding base: '/myapp/' to my vite.config.ts (or vue.config.js for non vite) resolved it.

url after spring maven deployment

I have a basic question about deployment but I can't seem to find an answer on google...
I am working on a jakarta project and it's the first time I do the deployment.
Since I am using Spring-boot maven, I know there is an embedded tomcat that will launch with the jar.
My issue is, I don't know what url to use to check my project is working...
Before, I used the address http://localhost:9091/contextPath/endpoint, but now, I only get a whiteScreen...
So my question is, what url should I use ? Also, is there something else to do after packaging ?
Thank you for your answers.
EDIT:
Alright, so I tried actuator but that didn't help me...
With /actuator/mappings, I could see that my endpoints are correctly configured but when I use the executable jar, http://localhost:9091/contextPath/endpoint odes not work while it does if I compile with my IDE...
I don't know what url to connect to just to see the index... I'm using a very basic spring framework (boot and mvc) and my IDE is intellij community if this helps anyone
EDIT 2:
I tried to deploy the app on a local Tomcat9 to see if something would change but the connexion is reinitialized everytime I try to deploy a war using the manager, and there was no trace of error in the logs.
I tried using ./mvnw and it did work, endpoint and all, but it implies working with IDE environment
I tried using java (openjdk 13) and it compiled, but i couldn"t acces my own endpoint. I could still access the actuator endpoints so i don't know what to make of it.
Should the url be different depending on whether we are using IDE environment or just the jar?
EDIT 3:
Ok, I think have a lead but I have no idea how to resolve this:
when I began the web part of the application, I created a WEB-INF folder where I put all my jsp. My js and css files were in the resources/static folder. I tried once to put the jsp in the resources folder but it didn't work so I didn't push too hard.
Now, when I unzip the jar, i find my css and js files, but not my jsp.
When I unzip my war file, I have everything, but when I try to deploy it on a separate tomcat server, the connexion resets and I don't know why because nothing is written in the logs.
The issue then becomes:
Right now, I have
└──src
└──main
├──java
├──resources
| ├──static
| | ├──css
| | └──js
| └──template
└──webapp
└──WEB-INF
└──classes
└──jsp
What is the standard tree in intellij with jsp ?
By default Spring Boot apps are on port 8080.
Can you try http://localhost:8080?
Port can be changed in application.properties (or application.yml, application-profile.properties etc.) via server.port property (e.g. server.port=8888).
Ok, I managed to make it work.
I'm going to describe here everything of note that I encountered.
First, when I called my app to the usual url, there was no response (whiteLabel).
I added test logs and i found that I indeed called m controller.
I unzipped the jar and war i produced and came to the conclusion that the issue was architectural. I couldn't use jar, I had to use the war file.
I tried to deploy on a local tomcat server using the manager, but it always resetted the connection, so I took the manual approach - copy pasting the war file in the webapp directory.
Finally, the web pages were accessible in the browser.
Thank you for all the tips given during my research!
`http://endpoint:{PORT}/actuator/health` or `http://endpoint:{PORT}/actuator/status`
it should help but it must require spring-boot-actuator as a dependency in your pom/gradle file.

Spring boot 404 error if the static content is deployed as jar

I have spring boot application and angular js project as two different modules.
The angular js contents ( files inside 'dist' folder) are converted as jar files and included as part of Spring boot application. The folder structure inside the jar is /static/**.
The jar appears inside the lib folder of the spring boot application.
Now when i try to access the application http://localhost:8080, i get 404 error.
It works fine, if i copy the "dist" folder content inside the /resources/static and create spring boot jar file.
Am i missing anything when the static contents are included as jar file. ?
Thanks in advance
I have a similar set up like you but using Angular 4. My Spring Boot version is 1.5.3.RELEASE.
My build is based on Maven with two modules. One for front-end (JAR) and one for backend (WAR), which references first module with Maven dependency mechanics.
Providing static content works out of the box. Since I'm using Spring Security I have to configure access rules for this resources. But this issue should be answered with a 401 and not 404.
Your angular JAR structure seems to be correct. Is your front-end build complete?
The lib folder with the front-end JAR is in my Spring Boot WAR on path /WEB-INF/.
Did you check if there is a bug connected with your used Spring Boot version?
#Moshe Arad #Raj In my understanding from https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot ,
the static contents can be in one of those mentioned locations. However, I myself is facing struggle in serving static content. I was working on spring-boot and angular-cli(6.1.5) based app. For deploy purpose, so that UI works on spring-boot port; I ran ng build. It generates files in src/main/resource/static (changed outputPath in angular.json to resources/static and create an empty dir static in resources) . But spring-boot didn't serve any angular content at 8080. Although index.html has <base href="/">, I thought to be more specific for it to pick/serve .js contents from static dir so I ran :
ng build --base-href / --deploy-url /static/ . This time the generated index.html has /static/runtime.js etc. in . But when accessing localhost:8080/ (right click -> inspect shows 200 response code) still doesn't show any UI content. But hitting localhost:8080/static/runtime.js shows 404 .
I believe there is more to do beyond just adding content to resources/static as probably tomcat is trying to serve it but somehow the content not being displayed. Because I do notice favicon icon (angular icon) on browser tab and the contents of jar file shows generated static files in the path (BOOT-INF/classes/static/index.html etc.)

Externalizing static content from a WAR and serve both on jetty

In my project I use Maven to package a web application to a WAR which is later deployed to Jetty using a custom Maven plugin on CentOS. The custom plugin is used by every project that deployes to a production environment. There is now a requirement that all static content (like web site text, properties) is packed outside of the WAR so that it can be changed in production without requiring a new release cycle. I am unsure how to achieve this externalization.
The Jetty server has the directory structure described in Jetty quick start guide. Currently, the web application already offers some .properties files which can be altered externally, and these reside in the resources/ directory. These files are moved here by the custom Maven plugin. The WAR resides in the webapp/ folder. One option for my problem is to use <packagingExcludes> of maven-war-plugin to not include e.g. *.xhtml and *.properties in the WAR. Later, I can use the custom Maven plugin to move excluded files to resources/ directory. But, I have a feeling this is not the correct way to externalize static content... Shouldn't xhtml files live in webapp/ folder while the only the properties file live in resources/ folder?
I have also researched the option of deploying the WAR as exploded, but I am unsure of the implications of such. Clearly, the changes in the exploded WAR files will be overwritten in the next deploy, but the idea is to do static changes both in development and production. Also, I am not sure how to achieve WAR "explosion", is it something that Jetty does for your WAR if configured in jetty.xml or do I have to extract the WAR before deploying?
Lastly, how do people serve static content in Jetty which can be altered in production? Do both the WAR and static files live side by side
The Jetty resources folder should not be used for application files. A J2EE web application (war) should be self-contained -- and in Jetty, reside only on the /webapps folder -- and its only binding to the container (Jetty servlet engine) is via the web.xml deployment descriptor.
Since property files may be read from the classpath and the Jetty resources folder is part of the system classpath, a property file there could be read by the web application class loader. Note that there are other ways to read property files as well and the Jetty resources folder should not be used for application properties. Also, the application may not be portable as other application servers have different forms of webapp classloader isolation.
If the below architecture approach does not work for you, then your only approach would be to expand (explode the war) in the /webapps folder and hope for the best when files are edited.
Tackling this from a different angle,
- if your web application depends on .properties and .xhtml files in order to function properly, then these files are probably not 'content'. The fact that there is a business process that requires them to to be updated ad hoc does not make them content.
- 'content' is something like text, images, and videos that is added, edited and removed by an administrative user. The application does not depend on it for correct execution, it merely reads and passes it on the browser.
Suggestions:
I would suggest that you deploy your application every time there is a change to the .xhtml or .properties files change. If the editors of these files are power business users, you might think of a git push-pull tool for them and a continuous build hook, so that when they make changes and push them to the git repository, the application gets tagged with a newer version and gets built and deployed. If there is a problem (tag not closed in xhtml), then it would be easy to roll back to the last tag.
Alternately, if the changes are minor (such as text descriptions), then modify the application to read them from an arbitrary external file (outside the webapp) -- a location that is provided to the webapp on startup. You can then package a 'default' version of the file in the webapp, but the code would attempt to look in the specified external location first.
I discovered that you can add HTML tags to properties and later use <h:outputFormat> to fetch these properties with parameters. Also, you can do pretty neat stuff with property files as described in MessageFormat API.
My solution was to keep the .xhtml files inside the WAR, but use simple HTML snippets properties from the default resource bundle which is based on a .properties file. These properties were included in the .xhtml using <h:outputFormat>and <h:outputText>. This allows the user to add simple styling like bold and underline to the snippets.
The properties file are copied to the Jetty resource folder using the custom Maven plugin, so I have kept the .properties files in the WAR. For some reason the Jetty resource folder has precedence over the packed .properties files, so this works out fine. Also, as Akber pointed out, I will have the default versions of the properties available if for some reason the WAR was moved to some other application server where the resource folder is not available.
Of course, with this approach the code can break if malformed HTML is placed inside the snippet properties, as pointed out by Akber, but it works for our application as it is very small. I may never have done this if this was a much larger application, but then I might have gone for a database based solution for adding static text (like Joomla/Drupal/Wordpress).

How to disable caching of jsp (and static resources) at META-INF/resources in Tomcat 7 (servlet 3.0)?

I've tried to set the cachingAllowed to false at both context.xml and server.xml.
And I use the default Context (org.apache.catalina.core.StandardContext).
But Tomcat still ignores modifications in dependencies jars within WEB-INF/lib (changes in jsp or js at META-INF/resources have no results).
I've tried to delete the Work folder with no success.
Dos anyone knows a way to turn off this caching?
This is for dev purpose of quickly change the resources (jsp reloading) and see the result without restart Tomcat.
I used to use war overlays and I am trying to migrate to servlet 3.0.

Resources