One JVM per application WAR in Jetty? - servlets

I'm using Jetty 8 to run some servlets. I have two (or more) applications that share source code, and I want to run them on the same port (i.e., 8080). I have placed two different WAR files into Jetty, one.war and two.war, so that I access them at, for example,
http://localhost:8080/one
http://localhost:8080/two
Both WARS contain an identical common JAR file (common utils). Does each WAR application get its own JVM? Really, I just want to be sure that the common JAR classes are entirely separate, since some of the classes are static and I need the two applications to obviously not share access to the same static class.
This seems obvious, and I seemed to confirm that it is the case that the common classes are loaded separately for each WAR with a simple test scenario (two identical WARs hosted in the same Jetty instance, but at different paths...see above). But I lack written documentation or confirmation that this is the case.

Each WAR file will have its own class loader see http://docs.codehaus.org/display/JETTY/Classloading. So you can safely use static classes.

Related

Websphere 8.5 overlapping jars between project and default server jars

I have a project deployed on websphere 8.5. However, there are certain classes that are creating conflict due to jar version errors in project and the ones provided by websphere default.
Can anyone help to point mechanism to resolve conflict.
I have done something similar in weblogic which provides option in welogic.xml to exclude / include jars from project.
This is the use case for the "isolated shared libraries" feature in the WebSphere server. For any technologies for which you need to bring your own version rather than use the version provided with the server, place the necessary jars into some directory outside the application, create a shared library pointing to that location, select the "use an isolated class loader" option in the library configuration, and associate the library with the application(s) that require it. The application will search the isolated library class loader before delegating to its parent loaders, and classes there will be found instead of server-provided versions.
A few cautions: This should ONLY be used for technologies that you are 100% certain that you need your own version rather than the server's. The "parent last" style of class loading used by isolated shared libraries includes some risk of conflicts between class loaders, and avoiding it (by using APIs provided by the server) is generally the safer option.
Note, too, that not everything can be overridden. The Servlet, EJB, and JPA APIs, for example, will break application startup if included in an isolated shared library, because the server containers require consistent versions of the API classes when processing application objects. Also, you cannot bring an API of any technology without an associated implementation - doing that is usually a recipe for a VerifyError or LinkageError caused by duplicate visibility to multiple versions of the API.

Tomcat or JBoss hosting 1 webapp with multiple websites

I want to have 3 websites, all with distinct public domain names but they all share a common java back-end SpringMVC server and use common static web resources like js and css files.
Rather than maintaining the UI code in 3 places, I'd rather run 1 server and deploy 1 WAR on a Tomcat8, Jboss or Wildfly cloud instance like OpenShift or AWS, but still be able configure my dns CNAME's to point to different paths on that WAR.
For example, here is where each domain would map to their respective endpoints but not have visibility of the others:
www.mydomainA.com ---> mycloudprovider.ip/sharedcontext/A
www.mydomainB.com ---> mycloudprovider.ip/sharedcontext/B
www.mydomainC.com ---> mycloudprovider.ip/sharedcontext/C
Is this possible? If so, what would be the steps to configure?
It is actually beneficial to configure 3 separate projects. They will all need to have their own application contexts, but can share a single parent POM. This will result in better load balancing performance. Also, since Amazon's pricing structure is such that it is cheaper to set up 3 micro instances than one powerful instance to run all 3 wars. Note: You can still have all 3 instances pointing to the same dataSource.
To solve the problem of duplicate webapp code, you can create a pom overlay using the maven-war-plugin. When Maven applies the overlay it will essentially apply a union of the files from your app with the files from the overlay. Any files that intersect will be used from the app rather than the overlay.
To solve the problem of duplicate java code, you can separate the common code into a new project and build a jar to use as a dependency.

what is api-paste.ini file in openstack

I've seen api-paste.ini as a conf file after installing openstack.
It looks like substituting some prefixes for python implementation but have no clue about this.
Here, my questions are:
What script is it?
it looks like very bizarre grammar like the following:
[composite:metadata]
use = egg:Paste#urlmap
/: meta
How does it work within python script?
See documentation for Paste Deploy.
The api-paste.ini is the configuration for the above web-services framework. Paste.deploy allows you to separate concerns between writing your application and middleware/filters from the composition of them into a web service. You define you WSGI applications and any middleware filters in the configuration file then you can compose pipelines which include the middleware/filters you want into your web-service, e.g. authentication, rate-limiting, etc.
You want to temporarily remove authentication, take it out of your pipeline and restart your web service.
The declaration above is declaring a composite application, but with only one application binding (a bit unnecessary - normally you would expect to see more than one binding, e.g. for different versions of the application). The WSGI application app:meta will be bound to / and you should have a declaration of app:meta later in the file. The implementation of the composite app is declared via the use and the egg:Paste#urlmap is a simple reference implementation.
You load this in your program with paste.deploy.loadwsgi.loadapp().
There is a proposal/recommendation(?) to move away from Paste Deploy/WebOb to WSME/Pecan see OpenStack Common WSGI

jboss 6 - if the context root is specified in application.xml as well as in jboss-web.xml, which wins?

An application I am working on is encapsulated inside an ear file, which contains a jar (containing EJB files) and a war (having, apart from its normal contents, package hierarchy of action classes, directly inside it). The context-root is specified in both WEB-INF/jboss-web.xml as well as in META-INF/application, and, well... is different in both.
The interesting part is that if I deploy that ear file in JBoss 4.2, I am able to access the application by the context-root given in application.xml, whereas when I deploy it in JBoss-6.1, I can access my application only with the context-root provided in jboss-web.xml. Why is this happening ?
Could there be a rationale for specifying two different context-roots in the 2 xml files ?

Specifying connection string in config file for a class library and re-use/modify in ASP.NET Web Application

How can one specify the connection string in a config file of a class library and later modify this when used in a ASP.NET Web Application?
The Class library is a data access layer that has a Dataset connecting to a database based on a connection string specified in a config file (Settings.settings/app.config).
This class library is used in a web application where user inputs data and is written to the database using the DAL classes & methods exposed in the class library.
Now, I want to migrate this application from development environment to testing environment and later to production. The problem I'm facing is that after migrating to testing, the app in testing still connects to development database. I've changed the connection string mentioned in <class library>.dll.config file but this seems to have no impact.
Can someone explain the right way to achieve this? Thanks in advance for any help. Cheers.
With the .config files the name has to match the main executing assembly. For example I had a situation like yours, I needed a class library to have its settings in a .dll.config file. While it was able to reference it the actual application would not be able to read the config file because it was expecting .exe.config. Renaming the .dll.config to .exe.config fixed the problem.
In your case migrating your connection strings from .dll.config to web.config should fix your problem!
Good luck!
Joshua is partly right ... For posterity I would like to add a bit more to this answer as I have delt with the same problems on several occasions. First, one must consider their architecture. There are several issues you can run into with .config files in ASP.NET based on deployments.
Considering the architectural ramifications:
Single tier (one server):
A simple web application may be able to leverage a reference to the sites Web.config file and resolve your issues. This would be a fine solution for a single tier application. In the case of a windows application leveraged as a .exe file, the App.config will work too.
Multi-tier (more than one server):
Here is where things became a bit hairy for me the first time I was working with .config files across boundries. Remember the hierarchy of the config structure and keep this in mind (MSDN Article on .Config structure) - there is a machine.config at the root in the appropriate ASP.NET folder. These reside at each physical server. These are overridden by the site Web.config (or App.config) which are in turn overridden by subfolder .config files. If you have more than one .config file you may want to use one of the methods to pass the file path for the specific .config you want to use. More importantly, these files each may have connection information. ASP.NET's machine.config holds some for the framework ... so you should at least be senstive to the fact this is an "inheritance" chain. Second, any changes to the Web.config file once deployed will tell the application to restart. This will result in loss of state (bad if you have active users on the site). The way around this is to keep a separate .config file (e.g. connections.config) and put a reference to that file in the Web.config. This will allow you to change the connection information (e.g. password) without having to restart the application. Here is a link to more info: MSDN: Working with Configuration Files. This article lays out all the details you need to be aware of in a normal server / IIS deployed application. Keep in mind that the .config files are mainly intended for applications, not libraries. If you have several tiers, chances are you are using some communicaiton / messaging layer (e.g. WCF). This will have / allow its own Web.config. You can keep connection strings there (and encrypt them if needed), but better yet, put them in a second file referenced by the Web.config for manageability. One final point, if you are ever going to consider the cloud, .config files are wrapped for application deployments which in effect removes all of the benefits they offer in terms of "not having restart or redeploy". Azure deployments will want to consider this article to save themselves from nightmares of maintenance: Bill Lodin blog - Configuration files in Azul / Cloud. One other point on this article – great example on how to programmatically select configuration depending on deployment! Be sure to check that out if you want to add flexibility to deploy in or out of the cloud .
I hope these points saves all of you time and headaches. I know I lost a couple days of programming time dealing with these issues ... and it was hard to find all the reasons in one place why may app was not "implementing" its connection object. Hopefully this will save you all from the same fate I had.

Resources