Setting up proxy filter for all application on WebSphere Application Server [duplicate] - java-ee-6

I want to register filter class for all web application in websphere; Tipically in tomcat I specify filter in /conf/web.xml. How can I do this in Websphere 8.5.
Also what is the common library (lib folder) in websphere. The filter class is in jar file and I want to put that jar file in websphere server lib directory.
-Thanks

Unfortunately there is no easy way to do it in WebSphere. It was already discussed here - Global Filter for all Web Applications
WebSphere solution involves creating custom listener and programmaticaly attach filters. You can find sample solution and description here - Adding a servlet filter to all web applications
What is the common library (lib folder) in Websphere?
You can put your jar to WebSphere\AppServer\lib\ext directory to be shared by all profiles, servers and apps, or create a shared library via web console Environment > Shared libraries and attach it to the specific server or application.

Related

Where do I place my templates for Blog-related mail notifications in Liferay 7.0?

The documentation states that I can configure the liferay server to use my own templates for the email messages. Specifically, if I add these properties to a portal-ext-env.properties in $CATALINA_BASE/conf/liferay:
blogs.email.entry.added.enabled=true
blogs.email.entry.added.subject=${resource:com/liferay/portlet/blogs/dependencies/email_entry_added_subject.tmpl}
blogs.email.entry.added.body=${resource:com/liferay/portlet/blogs/dependencies/email_entry_added_body.tmpl}
Liferay will supposedly use the templates in the specified paths (com/liferay/portlet/blogs/dependencies/email_entry_added_subject.tmpl and com/liferay/portlet/blogs/dependencies/email_entry_added_body.tmpl). The thing is, it's not very clear what these paths are relative to. Are these files relative to $CATALINA_BASE? For example, would the above configuration result in Liferay looking up $CATALINA_BASE/com/liferay/portlet/blogs/dependencies/email_entry_added_body.tmpl for creating the body of an email message? If this is not the case, where does Liferay lookup templates for Blog-related email messages?
After some digging, I've found that you place the templates in the $CATALINA_BASE/webapps/ROOT/WEB-INF/classes folder. Paths that you reference in the properties (e.g. blogs.email.entry.added.body=${resource:com/liferay/portlet/blogs/dependencies/email_entry_added_body.tmpl}) are relative to the aforementioned classes folder.
So, if I wanted Liferay to use a template file in the ff. relative path: org/foo/my_email_entry_added_body.tmpl, I would do two things:
Place the file in $CATALINA_BASE/webapps/ROOT/WEB-INF/classes/org/foo/my_email_entry_added_body.tmpl.
Add the following line to $CATALINA_BASE/portal-ext-env.properties: blogs.email.entry.added.body=${resource:org/foo/my_email_entry_added_body.tmpl}.
I consulted my co-worker and got a better understanding of why this is. The architecture of a Liferay application is such that it comes bundled with a Tomcat server. According to the documentation, WEB-INF/classes is a directory that a web app deployed to a Tomcat server looks up for classes and resources:
A class loader is created for each web application that is deployed in a single Tomcat instance. All unpacked classes and resources in the /WEB-INF/classes directory of your web application, plus classes and resources in JAR files under the /WEB-INF/lib directory of your web application, are made visible to this web application, but not to other ones.
Specifically, this folder is high in priorty in the web app's classpath.
When you see Liferay code similar to ${resource:path/to/foo}, it's looking up resources in its classpath. One of the paths in that classpath is WEB-INF/classes. Hence, if path/to/foo is placed in WEB-INF/classes, Liferay will find path/to/foo there.

ZK Project , Need Structural Advice for multiple ZK war applications

I need a advice for design purpose my structure of the application is as follows.
I have three module designed in ZK framework as a separate war application (web application) e.g finance-module , general-ledger and cash-account , all are separate war files can be deploy on tomcat as a separate war files,
Now I want to have a seperate war ZK application that has index or home page and have menu and from that menu I can able to call these three module or war application.
-------------------------- Main module -------------
Menu : general-ledger link , cash-account-link ,finance-module
1) This 4th Main module also has feature to user login and change user preference , means can also have code e.g view module as well as spring service.
Now the question is that how to call other war files zul pages and even if v call how to manage from 4th module and also how to share session across the four war files or applications.
Thanks
Vikas
I have worked in a similar scenario and this worked well for us:
When you create separate war's it means that they are independently running in it's own web context inside tomcat. Usually when you want to share resources like datasources, transactionManagers, or any other kind of jee resource you need to configure them at the tomcat instance level and they will be available in the JNDI directory of the tomcat server and any web application can pull any of them to use it.
https://tomcat.apache.org/tomcat-8.0-doc/config/context.html
https://tomcat.apache.org/tomcat-8.0-doc/jndi-resources-howto.html
There are several jee resources than you can share in the tomcat server but if you need more flexibility and robustness you might need a full stack java enterprise application server like wildfly http://wildfly.org/news/2014/11/20/WildFly82-Final-Released/ or any other commercial like WebSphere, Oracle Weblogic, etc
Now, if you want to share java classes, zul's or any other file, you may want to package them in separate common jars and use them in any war as a dependency and then reference them through the classpath of the web application.To organize and maintenance this modular projects Maven and Gradle are very good tools you can use.
From ZK you can call any other url of the other war's as simple as
<a href="htt://myserver/account/home.zul" label="Account"/>
<a href="htt://myserver/finnance/home.zul" label="Finance"/>
To share the session what you need is to implement a Single Sign On (there are other implementations like oracle opensso), you can configure it directly in tomcat but be aware of this Sharing security context between few web applications .
Spring Securityhas an extraordinary support for this kind of escenario.

Technical details of serve modules without publishing in Eclipse WTP and Tomcat?

Eclipse's Web Tools Platform (WTP) allows you to configure Tomcat to "Server modules without publishing":
Web content will be served directly from the "WebContent" folder of the Dynamic Web Project. A customized context is used to make the project's dependencies available in the Web application's classloader.
In a 5 step process (just joking, you pick the # of steps), what happens technically and where are the files that Eclipse generates? I did notice that Eclipse generated a org.eclipse.jst.server.tomcat.runtime.70.loader.jar file in the Tomcat lib directory.
The idea is to serve a web application directly from the scattered directory structure of the development workspace, without packaging modules into JARs which then end up in WEB-INF/lib in a WAR.
The main benefits are:
You don't need to build archives.
When you change a resource in your workspace, the change is reflected in the running webapp without redeploying the webapp or restarting the server.
With Servlet 3.0, web resources may also be bundled in library JARs in META-INF/resources, so classes and resources may come from multiple workspace directories.
Tomcat 7.0 supports a VirtualWebappLoader and a VirtualDirContext to configure a web application based on a collection of scattered resource and class directories.
To serve your web app directly from your Eclipse workspace, WTP generates a suitable Tomcat configuration matching your project structure
in $WORKSPACE/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/conf/server.xml
For some reason, WTP does not directly use the Tomcat loader and context implementations but has its own WtpDirContext and WtpWebappLoader which are slightly different but similar. (I believe this approach is older than the current solution in Tomcat. There is some special logic for TLD scanning - I'm not sure if this is still required with the latest Tomcat versions.) These helper classes are contained in the org.eclipse.jst.server.tomcat.runtime.70.loader.jar you noticed.
Without Serve modules without publishing, when you change a web resource in META-INF/resources in a library module, this change will not be directly visible in the running application after reloading the current page in the browser.

Deploying .sar files used in jBoss to weblogic

We have ".sar"(Service Archive file) used in jboss. Currently we are planning to migrate the code to Weblogic.
Is there a way to deploy .sar files into weblogic.
If not directly possible, is there a work around where we can deploy the services on web logic.
In order to get the custom mbeans that are in the .sar you will need to repackage the contents as an .ear as a .sar is not standard Java EE deployment mechanism - that is a JBoss proprietary archive.
Here are some instructions on how to create, package and deploy your own service MBeans (JMX Beans) along with an example of how to use it.
https://blogs.oracle.com/WebLogicServer/entry/developing_custom_mbeans_to_ma
One thing you could do is to "substitute" or "emulate" the SAR Deployer, by creating, configuring and registering MBeans. That, AFAIK, could be done in two ways:
1) Using Standard Java EE components: that means on web tier you can use the init() method of a servlet (make sure that it is preloaded on startup) or, better, a ServletContextListener
2) Using WebLogic specific components. I'm talking about Startup classes. Simply register a startup class that creates, configures and registers your MBeans.
If you are using a web module, the first approach has the obvious advantage that you are using pure Java EE components. Although you are not using that, you can add a "dummy" web module only for doing that
Concerning what you have to do in those classes, you can choose a "from scratch" approach, by parsing the xml files that describe services and therefore manually create, configure and register MBeans or, if I remember well, the XMBeans from JBoss is something that can be reused outside JBoss but you need to check because I'm not sure

Shared libraries between web services on Glassfish

I need to deploy multiple web services on a jax-ws application server, glassfish 3. These web services need to have shared libraries, meaning shared instances of the same class.
I know I could do this by dropping a jar in the "~/glassfish3/glassfish/domains/domain1/lib" directory. But I wonder whether this is possible in a more elegant way: I want to place the shared library jar inside a web service war which I deploy and then access that library from another war I deploy on the same application server.
How can I do this?
I found a solution for Glassfish myself: Basically I just deploy a class (SharedClassLoader) which inherits from URLClassLoader as a shared library jar in the above mentioned directory. Then I use this classloader as a bootstrap: On calling the web service, the classloader hierarchy is extended as follows: A SharedClassLoader for an URL is instantiated if it does not exist yet and it is added as a delegate to the DelegatingClassLoader in the classloader tree. By doing this for every web service with the same SharedClassLoader instance, it acts as a bootstrap to pull in more class loading. The jar that SharedClassLoader refers to can also be deployed with one of the web services, because Glassfish unpacks the containers to $AS_HOME/domains/domain1/applications/APPLICATION_NAME/LIBRARY_NAME.jar.
I hope this helps anyone having the same problem. I solved this problem for my Bachelor Thesis. If anyone needs more information, just ask, I can send you my thesis.