Include deployment timestamp into JSP page - java

I'm writing web applications with Java EE 7 using JSP and servlets, deploying to a local Wildfly 10 server.
To help me developing and testing my code, it would be useful to include a little timestamp into the displayed webpage, so that I can directly see when the version I'm looking at in my browser was deployed.
That would prevent me from both forgetting to deploy changes as well as from looking at old cached versions instead of the latest one.
How can I display the date and time when a Java EE web app got deployed to my Wildfly server directly on the webpage?
My IDE is Eclipse Neon for Java EE, if that matters.

This is not deploytime, but starttime of the application. Maybe it is useful for your purpose. You can inject the class and use it to display data on your page.
#Startup
#Singleton
public class Deploytime
{
private LocalDateTime starttime;
#PostConstruct
public void init() {
starttime = LocalDateTime.now();
}
}
Apart from that I can only think of Maven Git Plugin which can generate things like buildtime, commit id, ... into a propery file, which you can also use to display it on the page (if you use git/maven).

There is likely an API to do this too but you can get the server start time from the command line. Assuming that you have your admin user name and password set up (i.e. you've run something like add-user.sh) you could run:
curl --digest "http://user:password#localhost:9990/management/core-service/platform-mbean/type/runtime?operation=attribute&name=start-time"
Of course, this is not Java - you'd either have to do a System.exec on this or use something like HttpClient. Additionally, the big issue here is that you've got to have your admin username and password available to the code.
The Wildfly HTTP Management Docs go into some more detail with a small sample Java snippet.
EDIT:
Sorry - should not have assumed that the server restarts on deployment. You can get deployment time for a web app with:
curl --digest "http://user:password#localhost:9990/management/deployment/test-1.0-SNAPSHOT.war/?operation=attribute&name=enabled-time"
However, that seems more difficult than the other answer of running something at startup. I don't see a deployment time for a webapp as that time would have to be stored somewhere in case of server restarts.

Related

Jboss wildfly 10 strange issue loading libraries

I'm developing a custom application for IBM BPM that uses these libraries: Jace.jar, pe.jar, log4j.jar, stax-api.jar, xlxpScanner.jar and xlxpScannerUtils.jar that are used to call a web service.
When I create a java project and add those libraries, it works fine. It also works ok when I create a dynamic web project using tomcat 8 as server; but when using jboss I don't get the expected result when calling the web service. So, does anybody know how to disable the modules that use these libraries? Or where to find information about it?
I want my application to be server independent.
This is my code:
try {
VWSession vwSession = new VWSession("userName", "userPass", "connPt");
vwSession.isLoggedOn(); /* It's loaded with 'false' value in jboss.
In tomcat it's loaded with 'true' value */
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.FATAL, "Details: ", e);
}
To create an application that is server agnostic, you need to strictly adhere to Java EE specification. Meaning, use only those jars that are bundled as part of the Java EE version you are using. Then too, there are certain deployment descriptors specific to a given application server that would need to be used in some cases. For example - jboss-deployment-structure.xml, ibm-application-bnd.xml, etc.
In your case, xlxpScanner.jar is not a part of the Java EE spec, so making the application server independent is not possible with the current settings. You could look for a replacement of the part of this jar you are using with something Java EE has. In short, get rid of this jar alongwith xlxpScannerUtils.jar.
Alternatively, if you want jboss to run the application properly, add all the jars in a module and give it to the EAR/WAR using jboss-deployment-structure.xml. Details can be found here.

Tomcat Deploying 2 Projects

I have a requirement that I need to use a single server machine to run 2 totally different applications.
The server machine has Apache Tomcat 6.0 installed. 1 of the applications is deployed on it and is running successfully for a long time. Initially, the clients used to connect to it by invoking the url "http://machine-name/1stProjectName/initialPage". I have also mentioned the "initialPage" as the Welcome Page in web.xml of this project. But somehow, later some ports or relating things were changed by the server maintenance team, and to connect to the application, now one has to use the url "http://machine-name" or "http://machine-name/initialPage", i.e. the machine name has started behaving like the project name folder because now if I invoke the url "http://machine-name/1stProjectName/initialPage", it gives 404 error saying that "/1stProjectName/1stProjectName/initialPage" resource not available.
Now, when I deploy the WAR of the second application into the webapps folder of Tomcat (just like I did for the first application), it unpacks it properly. But, the issue is how do I connect to this second project. If I use "http://machine-name", it takes me to the 1st application and if I use "http://machine-name/2ndProjectName/initialPage", it gives me an error that "/1stProjectName/2ndProjectName/initialPage" not available.
Kindly help or guide me in some direction.
Thanks in advance.
Your URLs should look like this if you did things properly:
Project 1: http://host:port/war-name-1
Project 2: http://host:port/war-name-2
That means no changes to content.xml to modify the path.
I would talk to your "server maintenance team" and let them know what you are trying to do (since they are the ones who made these changes in the first place). But it sounds to me that they just mapped a path to a specific location, that is your machine-name root is mapped to 1stProjectName.

gxt + Java EE hosted mode

I'm trying to develop a Java EE + gxt application. I have an rpc call which calls a session bean's method.
If I compile the project and run it in the browser, it works fine, but when I use
hosted mode I get an exception like this: (edited for readability)
Exception while dispatching incoming RPC call
...
Caused by: java.lang.NullPointerException: null at org.Pecc.server.services.AppServiceImpl.
getUserEmailByName(AppServiceImpl.java:53)
Line 53 is:
return appSessionBeanBean.getUserEmailByName(name);
It's like the session bean can't be reached. Note that I have GWT4NB plugin and use it's "GWT hosted mode (w/o a Java EE server)" command, but I have glassfish running and the ejb module deployed in it. Shouldn't it be enough to work? If I remember right, I was able to use my ejb module in hosted mode at some point.
Any thoughts?
I hate to ask this, but are you able to debug and confirm the appSessionBeanBean is indeed not null? And if not, with log statements...
I found a workaround by redirecting the hosted mode browser to the module deployed in glassfish. I simply write localhost:8080/EasyTicket-web into the address bar instead of localhost:8888 (jetty's port.). Of course, glassfish has to be started for that to work.

What causes duplicate requests to occur using spring,tomcat and hibernate

I'm working on a project in Java using the spring framework, hibernate and tomcat.
Background:
I have a form page which takes data, validates, processes it and ultimately persists the data using hibernate. In processing the data I do some special command (model)
manipulation prior to persisting using hibernate.
Problem:
For some reason my onSubmit method is being called twice, the first time through things
are processed properly. However the second time through they are not; and the incorrect
information is being persisted.
I've also noticed that on other pages which are simply pulling information from the data
base and displaying on screen; Double requests are happening there too.
Is there something misconfigured, am I not using spring properly..any help on this would
be great!
Additional Information:
The app is still being developed. In testing the app I'm running into this problem. I'm using the app as I would expect it to be used (single clicks,valid data,etc...)
If you are testing in IE, make note that in some versions of IE it sometimes submits two requests. What browsers are you testing the app in?
There is the javascript issue, if an on click handler is associated with submit button and calls submit() and does not return false to cancel the event bubble.
Could be as simple as users clicking on a link twice, re-submitting a form while the server is still processing the first request, or hitting refresh on a POST-ed page.
Are you doing anything on the server side to account for duplicate requests such as these from your users?
This is a very common problem faced by someone who is starting off. And not very sure about the application eco-system.
To deploy a spring app, we build the war file.
Then we put it inside 'webapps' folder of tomcat.
Then we run the tomcat instance using terminal (I am presuming a linux system).
Now, we set up env in that terminal.
The problem arises when we set up our environment for the spring application where there can be more than one war files to be deployed.
Then we must cater to the fact that the env must be exclusive to a specific war file.
To achieve this, what we can do is create exclusive env files for every war. (e.g. war_1.sh,war_2.sh,.....,war_n.sh) and so on.
Now we can source that particular env file for which we have to deploy its corresponding war. This way we can segregate the multiple wars (applications) and their environment.

Does JBoss cache class files?

I'm wrestling with a strange problem: When I make a change to a POJO or Seam Component in my localhost JBoss instance, restart it, and load the page, the change is visible. However, on our server, running the same version of JBoss, when I stop the instance, delete the WAR file, upload the latest version, and restart JBoss, it won't show some of the new server-side functionality.
Specifically, the change is to a POJO class which implements javax.faces.validator.Validator class. It's then used in the XHTML Facelet like this:
<h:inputText value="#{outsideaccount.accountOrganizationEmail}" maxlength="50"
id="txtOrganizationSupportEmail"
validatorMessage="Organization Support Email is not valid. It must be in the pattern 'some_id#some_domain.com'.">
<f:validator validatorId="AnyEmailValidator"/>
</h:inputText>
I'm able to use the email validator on my localhost JBoss correctly; on the development server, it throws a validation error using the same email on the same page. Very strange. Is JBoss caching the class files somewhere? How do I clear everything out of the JBoss development server cache?
I'm using Win XP Pro locally; the development server is using JBoss 4.2.3.GA on JVM Version 1.5.0_16-b02, with Unix SunOS 5.10. Thanks.
JBoss has work and tmp directories that you can delete to make sure everything is clean. Things can get cached there, so you can clear them out on deploy if you are having problems. There is also a setting to force that to happen automatically on JBoss's end. If your problem is a cache clearing problem, this will help solve it.
Another possibility is that you have two copies of that war deployed on JBoss, although that should give you some errors when you deploy in production.

Categories