<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0-3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>2.0</version>
<type>pom</type>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.json</groupId>
<artifactId>javax.json.bind-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
</exclusion>
<exclusion>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.myfaces.core</groupId>
<artifactId>myfaces-api</artifactId>
<version>2.3.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>test</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomee.maven</groupId>
<artifactId>tomee-embedded-maven-plugin</artifactId>
<version>8.0.2</version>
<configuration>
<context>ROOT</context>
<containerProperties>
<tomee.mp.scan>true</tomee.mp.scan>
</containerProperties>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>mp-common</artifactId>
<version>8.0.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>
Wednesday, June 24, 2020
How to use Microprofile with tomee-embedded-maven-plugin
Here is a sample POM how to use Microprofile with tomee-embedded-maven-plugin 8.x:
Tuesday, March 12, 2019
Tuesday, March 5, 2019
Way to MyFaces 2.3-next
I (and other commiters) spend many hours to prepare the MyFaces codebase for the upcoming version 2.3-next during the last months, which will be MyFaces 4.0 in the future.
JSF (or Jakarta Faces) 3.0 will be 1:1 the same as JSF 2.3, just with the jakarta.* package names.
In 2.3-next, we did BIG BIG cleanup of our codebase and build.
Wee also removed the old JSF EL (javax.faces.el.*) and @ManagedBean (javax.faces.bean.*) implementations.
What does this mean? The API (javax.faces.el.*) and (javax.faces.bean.*) is still there but the implementation of it has been removed partially. @ManagedBean's are now registered as CDI beans, which means that a CDI runtime is a required dependency now.
The biggest clenaup was that we merged back the "shared" and "shared-public" modules to myfaces-impl, as the shared modules are no longer used by other active projects under the MyFaces umbrella.
We also introduced some real integration tests with Arquillian, to test parts of the container integration and AJAX client side. This makes around 1600 unittests!
OK.... Lets compare some numbers!
JAR size:
Performance:
NOTE: this is not a full benchmark, it's only a single case to demonstrate the difference between MyFaces 2.3 and MyFaces 2.3-next, which was inspired from: https://www.oio.de/public/java/studie-jsf-mojarra-myfaces-performance-vergleich.htm
We have to rerun https://github.com/lu4242/performance-comparison-java-web-frameworks later for a real comparison between MyFaces and Mojarra.
This means that MyFaces 3.0 is up to ~15% faster as the already very fast MyFaces 2.3 in this case.
We also did some memory finetuning - i just don't have any numbers right now.
JSF (or Jakarta Faces) 3.0 will be 1:1 the same as JSF 2.3, just with the jakarta.* package names.
In 2.3-next, we did BIG BIG cleanup of our codebase and build.
Wee also removed the old JSF EL (javax.faces.el.*) and @ManagedBean (javax.faces.bean.*) implementations.
What does this mean? The API (javax.faces.el.*) and (javax.faces.bean.*) is still there but the implementation of it has been removed partially. @ManagedBean's are now registered as CDI beans, which means that a CDI runtime is a required dependency now.
The biggest clenaup was that we merged back the "shared" and "shared-public" modules to myfaces-impl, as the shared modules are no longer used by other active projects under the MyFaces umbrella.
We also introduced some real integration tests with Arquillian, to test parts of the container integration and AJAX client side. This makes around 1600 unittests!
OK.... Lets compare some numbers!
JAR size:
| Mojarra 2.3 | MyFaces 2.3 | MyFaces 2.3-next | |
|---|---|---|---|
API |
1318 kb | 1043 kb | |
| IMPL | 3495 kb (combined) | 2712 kb | 2384 kb |
Dependencies |
241 kb (beanutils) 141 kb (digester) |
||
| TOTAL | 3495 kb | 4412 kb | 3427 kb |
Performance:
NOTE: this is not a full benchmark, it's only a single case to demonstrate the difference between MyFaces 2.3 and MyFaces 2.3-next, which was inspired from: https://www.oio.de/public/java/studie-jsf-mojarra-myfaces-performance-vergleich.htm
We have to rerun https://github.com/lu4242/performance-comparison-java-web-frameworks later for a real comparison between MyFaces and Mojarra.
| Mojarra 2.3 | MyFaces 2.3 | MyFaces 2.3-next | |
|---|---|---|---|
| GET input.xhtml | Average: 67 ms | Average: 62 ms | Average: 43 ms |
| POST input.xhtml | Average: 115 ms | Average: 122 ms | Average: 108 ms |
| GET detail.xhtml | Average: 119 ms | Average: 124 ms | Average: 103 ms |
| POST detail.xhtml | Average: 70 ms | Average: 54 ms | Average: 43 ms |
| TOTAL | Average: 92 ms Throughput: 198.7/s |
Average: 91 ms Throughput: 209.8/sec |
Average: 74 ms Throughput: 264.2/sec |
This means that MyFaces 3.0 is up to ~15% faster as the already very fast MyFaces 2.3 in this case.
We also did some memory finetuning - i just don't have any numbers right now.
Tuesday, February 5, 2019
Maven: use lombok combined with OpenJPA metadata generation
Here is a example how to use lombok combined with OpenJPA metadata generation inside the maven-compiler-plugin:
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
</dependency>
<!-- needs to be defined here for the annotation processor -->
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>3.0.0</version>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<annotationProcessors>
<annotationProcessor>lombok.launch.AnnotationProcessorHider$AnnotationProcessor</annotationProcessor>
<annotationProcessor>org.apache.openjpa.persistence.meta.AnnotationProcessor6</annotationProcessor>
</annotationProcessors>
<compilerArgs>
<arg>-Aopenjpa.metamodel=true</arg>
<arg>-Aopenjpa.source=7</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Tuesday, November 7, 2017
Increase your JSF application performance - Version 2017
As my last posts are already 5 years old, i think it's time for a new one :D
If you would like to use a JavaEE application server, i would go with TomEE.
It's the fastest and smallest application server available and already comes with Apache MyFaces as JSF implementation and Apache OpenWebBeans as CDI implementation.
There are already really good benchmarks available why we should choose MyFaces over Mojarra and OpenWebBeans over Weld:
Understanding JSF 2.0 Performance – Part 1
Understanding JSF 2.0 Performance – Part 2
Understanding JSF 2.0 Performance – Part 3
CDI Performance
So if you just use a plain servlet container like Tomcat or Jetty, i would also use MyFaces and OpenWebBeans.
In the past it was also a good performance boost if you use JUEL over Tomcat's EL implementation - sadly JUEL doesn't implement EL 3.0.
Enable ViewPooling: http://lu4242.blogspot.de/2013/12/view-pooling-in-jsf-22-using-apache.html
NOTE: You must also set:Enable WhiteSpace compression: http://lu4242.blogspot.de/2012/12/html-white-space-compression-for-jsf.html
Disable JSP support in MyFaces - this increases the startup performance and EL resolution:
Disable ManagedBeans support (since 2.3):
Reduce saved view states:
Disable ViewState compression (better performance but more memory usage):
Enable partial submit in PrimeFaces - this reduces the network traffic:
Move above the fold scripts to the bottom (end of body). This is a huge improvement of the visible rendering and removes flickering between navigations (since 6.2):
Other params to increase performance:
Use a custom ServletFilter to set the correct expires/cache headers of your resources (images, stylesheets, javascripts). This is only required if you don't use the JSF resource handling for every resource. The JSF impl should already do it correctly for all JSF managed resources.
Compress and optimize your Javascripts in your build process. If you
use maven, try primefaces-extensions' closure compiler maven plugin.
Enable GZIP in your webserver! If it's not supported by your webserver/container, you can still add the GzipResponseFilter from OmniFaces: http://showcase.omnifaces.org/filters/GzipResponseFilter
Environment:
If you would like to use a JavaEE application server, i would go with TomEE.
It's the fastest and smallest application server available and already comes with Apache MyFaces as JSF implementation and Apache OpenWebBeans as CDI implementation.
There are already really good benchmarks available why we should choose MyFaces over Mojarra and OpenWebBeans over Weld:
Understanding JSF 2.0 Performance – Part 1
Understanding JSF 2.0 Performance – Part 2
Understanding JSF 2.0 Performance – Part 3
CDI Performance
So if you just use a plain servlet container like Tomcat or Jetty, i would also use MyFaces and OpenWebBeans.
In the past it was also a good performance boost if you use JUEL over Tomcat's EL implementation - sadly JUEL doesn't implement EL 3.0.
Configuration:
- Common settings:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>-1</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.CACHE_EL_EXPRESSIONS</param-name>
<param-value>alwaysRecompile</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.SUPPORT_JSP_AND_FACES_EL</param-name>
<param-value>false</param-value>
</context-param>
<!--
NOTE: the ExpressionFactory might differ e.g. on Glassfish or Wildfly.
This parameter is optional since MyFaces 2.3.3.
-->
<context-param>
<param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
<param-value>org.apache.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.SUPPORT_MANAGED_BEANS</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
<param-value>15</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION</param-name>
<param-value>3</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>primefaces.SUBMIT</param-name>
<param-value>partial</param-value>
</context-param>
<context-param>
<param-name>primefaces.MOVE_SCRIPTS_TO_BOTTOM</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.CHECK_ID_PRODUCTION_MODE</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.EARLY_FLUSH_ENABLED</param-name>
<param-value>true</param-value>
</context-param>
Patterns:
- Correctly define update/render and process/execute! Often this is a huge improvement as many times the whole form is updated instead only a small part. But i also prefer maintainability over performance here.
- If you don't use ViewScoped beans, it's a good but small improvement to mark the view as stateless via transient=true.
- Try using HTML over JSF tags.
- Especially avoid using h:outputText if you don't need the escaping. Just use EL expressions inside your xhtml template.
- The same applies for some other components like p:outputPanel. Just use a plain div. If you need to make it updateable, you can still use "passtrough elements" (<div jsf:id="...">...</div>)
- Never put logic in getters because they can be called multiple times - especially for the rendered attribute!
- Avoid logic (like inline if-statements) in EL expression! It's better to move those logic into the bean. It's faster and often easier to read and maintain.
- Prefer AJAX over a full postback!
- If you have many p:outputLabel's on the page and you know that the input field is required or not, it's a good performance improvemet to set the input to required=true or the outputLabel to indicateRequired=true|false. The default value for indicateRequired since 6.2 is auto, which tries to lookup BeanValidation constrains to check if @NotNull|@NotEmpty|@NotBlank are defined.
- Cache data, which is required multiple times in the same view, in @RequestScoped beans.
- Avoid missusing @SessionScoped, @ViewScoped and other long living scopes if not really required.
- Try to put only small amount of data in such long living beans. Sometimes a small flag or id of an entity is enough information. Often people put many entities in such long living beans. One of my patterns is to split beans into *Controllers (@RequestScoped) and *StateHolders (@ViewScoped, @ViewAccessScoped). *StateHolders are just data containers.
Labels:
CDI,
Java,
Java EE,
JSF,
JUEL,
MyFaces,
OpenWebBeans,
Performance,
PrimeFaces,
Tomcat
Monday, January 25, 2016
Enable failover with OpenWebBeans (>= 1.5.1)
Since OWB 1.5.1 you don't need any configuration or FailOverFilter anymore as the beans are directly stored in the HttpSession :)
Saturday, September 21, 2013
Session replication / clustering / failover with Tomcat (Part 1 - Overview)
This is my first post of a series about Tomcat and clustering.
In this post i will explain some different replication mechanism.
NOTE: A common drawback of replication, like it's defined in the specs, is that only HttpSession#setAttribute(...) triggers replication.
This means that if you store a container object in the session and if you change a variable inside the object, you must HttpSession#setAttribute(...) again to replicate the modified object again.
Many frameworks implements a simple workaround for it - i will write about it another post.
With this mode, Tomcat just replicates the session to all registered nodes.
Pro:
The sessions will be replicated to the next neighbor. If one Tomcat is not available anymore, the neighbor still holds the sessions.
Pro:
Each Tomcat replicates all sessions to N (multiple) Memcached nodes.
If a session is not available on the local Tomcat, the memcached-session-manager tries to lookup the session from the Memcached nodes.
Pro:
In this post i will explain some different replication mechanism.
NOTE: A common drawback of replication, like it's defined in the specs, is that only HttpSession#setAttribute(...) triggers replication.
This means that if you store a container object in the session and if you change a variable inside the object, you must HttpSession#setAttribute(...) again to replicate the modified object again.
Many frameworks implements a simple workaround for it - i will write about it another post.
All to all replication / DeltaManager
With this mode, Tomcat just replicates the session to all registered nodes.
Pro:
- No single point of failure at software level
- Every node holds all sessions
- In theory, all other nodes can be turned off
- No extra software is needed
- Synchronous or Asynchronous replication
- Open Source
- Enterprise-Support available
- High memory usage and network traffic because all nodes holds all sessions
- Objects which are stored in the session must be triggered manually to replicate again if a property has been changed
- Slower session serialization
Primary/Secondary Replication (Buddy Replication) / BackupManager
The sessions will be replicated to the next neighbor. If one Tomcat is not available anymore, the neighbor still holds the sessions.
Pro:
- No single point of failure at software level
- Lower memory usage and network traffic because the session is not stored on all nodes
- No extra software is needed
- Synchronous or Asynchronous replication
- Open Source
- Enterprise-Support available
- Not quite as battle tested as the All-to-all replication (see Tomcat documentation)
- Objects which are stored in the session must be triggered manually to replicate again if a property has been change
- Slower session serialization
Memcached-session-manager
Each Tomcat replicates all sessions to N (multiple) Memcached nodes.
If a session is not available on the local Tomcat, the memcached-session-manager tries to lookup the session from the Memcached nodes.
Pro:
- No single point of failure at software level
- More scalability
- Session will be replicated to N “Memcached” nodes – The sessions are still available if all webservers are down
- Automatically handles “Memcached” nodes failover
- Sticky mode: Lower memory usage because every node holds only the current used sessions
- Non-Sticky mode: Lowest memory usage because Tomcat does not hold the sessions anymore. Session will be received from memcached for each request
- MSM will automatically trigger replication if a property in a session stored object has been changed
- Faster session serialization – Changeable mechanism
- Synchronous or Asynchronous replication
- Open Source
- Enterprise-Support available for Tomcat
- Extra software needed (“Memcached” plugin and nodes)
- Cannot switch to another Java Webserver which does not automatically check changed values in the session - but only if the used framework has no implemented workaround
- AFAIK no Enterprise-Support available for the Memcached plugin but Martin Grotzke is very active on the mailing list
Thursday, September 19, 2013
Enable failover with OpenWebBeans (> 1.2.0)
In my first post i already explained how it's possible to enable failover (aka clustering) with OpenWebBeans > 1.1.3: Enable failover with OpenWebBeans (> 1.1.3)
Because we moved the clustering logic to own module, we must include this module since OWB 1.2.0:
You still need the org.apache.webbeans.web.failover.FailOverFilter but if you include this module, you must NOT add a custom openwebbeans.properties anymore. It will be registered automatically.
Because we moved the clustering logic to own module, we must include this module since OWB 1.2.0:
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-clustering</artifactId>
</dependency>
You still need the org.apache.webbeans.web.failover.FailOverFilter but if you include this module, you must NOT add a custom openwebbeans.properties anymore. It will be registered automatically.
Labels:
CDI,
Cluster,
Clustering,
FailOver,
Java,
Java EE,
OpenWebBeans,
OWB,
Session,
Tomcat
Wednesday, September 18, 2013
PrimeFaces Extensions 1.0
This week, Oleg released a RC of PrimeFaces Extensions as you can read here: PrimeFaces Extensions 1.0.0.RC1 released
To be honest, i had not much time to improve anything in PrimeFaces Extensions.
I'm PrimeFaces committer since January 2013 and it was more fun to implement new features, working on complex stuff together with Çağatay or improve performance directly in PrimeFaces Core.
I also will blog about some of this features the next weeks.
The biggest of my changes in PrimeFaces Extensions 1.0 are the PrimeFaces 4.0 compatibility and a new CKEditor version (4.2.1 now).
It's not sooo easy to marry CKEditor and the resource handling of JSF. I had to adjust some of there code and created some issues on their side.
If they will improve it and fix those issues, updating CKEditor will much easier in the future.
CKEditor removed and introduced new skins. Supported skins are "kama" and "moono" now.
We also added support for "my" new Search Expression Framework of PrimeFaces 4.0 in all our components.
We were also able to clean up some code because i could move some features or API changes directly to PrimeFaces Core.
Stay tuned for the final release!
To be honest, i had not much time to improve anything in PrimeFaces Extensions.
I'm PrimeFaces committer since January 2013 and it was more fun to implement new features, working on complex stuff together with Çağatay or improve performance directly in PrimeFaces Core.
I also will blog about some of this features the next weeks.
The biggest of my changes in PrimeFaces Extensions 1.0 are the PrimeFaces 4.0 compatibility and a new CKEditor version (4.2.1 now).
It's not sooo easy to marry CKEditor and the resource handling of JSF. I had to adjust some of there code and created some issues on their side.
If they will improve it and fix those issues, updating CKEditor will much easier in the future.
CKEditor removed and introduced new skins. Supported skins are "kama" and "moono" now.
We also added support for "my" new Search Expression Framework of PrimeFaces 4.0 in all our components.
We were also able to clean up some code because i could move some features or API changes directly to PrimeFaces Core.
Stay tuned for the final release!
Friday, December 14, 2012
Dynamical switching of JSF state saving method
By default, it's only possible to configure the state saving method (client or server) globally for all views in your application.
This is sometimes really annoying as server side performs better but needs more memory.
Also with server side state saving, it's not possible to cache views (if they have actions) because you will get a ViewExpiredException soon.
So what about using client-side state for some views and using server-side state for all other views?
Currently this is only possible with MyFaces (since 2.1.9). Mojarra doesn't support this feature.
I created a specifiation improvement ticket (http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1147) and hopefully this will be supported in Mojarra soon.
So how can we use this feature?
To switch the state saving method, we just need to overwrite/wrap the following method: StateManager#isSavingStateInClient(FacesContext).
In my application i combined this feature with CODI ViewConfig.
Create a ViewMetaData:
Wrap the StateManager:
Configure that JSF should use our StateManager:
Usage:
Currently i'm not a member of a library/framework, where i could add this nice feature.
Maybe i will release my own lib for such stuff someday.
This is sometimes really annoying as server side performs better but needs more memory.
Also with server side state saving, it's not possible to cache views (if they have actions) because you will get a ViewExpiredException soon.
So what about using client-side state for some views and using server-side state for all other views?
Currently this is only possible with MyFaces (since 2.1.9). Mojarra doesn't support this feature.
I created a specifiation improvement ticket (http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1147) and hopefully this will be supported in Mojarra soon.
So how can we use this feature?
To switch the state saving method, we just need to overwrite/wrap the following method: StateManager#isSavingStateInClient(FacesContext).
In my application i combined this feature with CODI ViewConfig.
Create a ViewMetaData:
@Inherited
@ViewMetaData(override = true)
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface StateSaving {
Method value();
enum Method {
SERVER,
CLIENT
}
}
Wrap the StateManager:
public class ExtensionsStateManager extends StateManagerWrapper {
@Override
public boolean isSavingStateInClient(final FacesContext context) {
boolean isSavingStateInClient;
final StateSaving stateSaving = getStateSavingAnnotationViaCodiViewConfigResolver(context);
if (stateSaving == null) {
isSavingStateInClient = getWrapped().isSavingStateInClient(context);
} else {
isSavingStateInClient = stateSaving.value() == StateSaving.Method.CLIENT;
}
return isSavingStateInClient;
}
}
Configure that JSF should use our StateManager:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<state-manager>xxx.xxx.ExtensionsStateManager</state-manager>
</application>
</faces-config>
Usage:
@Page(navigation = NavigationMode.REDIRECT)
public interface Pages extends ViewConfig {
@Page
@StateSaving(Method.SERVER)
class ViewA implements Pages { }
@Page
@StateSaving(Method.CLIENT)
class View implements Pages { }
}
Currently i'm not a member of a library/framework, where i could add this nice feature.
Maybe i will release my own lib for such stuff someday.
Thursday, October 25, 2012
Speedup jetty-maven-plugin startup time
- Create a own profile - this allows more flexibility
<profile>
<id>jetty-run</id>
</profile>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<webAppSourceDirectory>${basedir}/src/main/webapp</webAppSourceDirectory>
<scanIntervalSeconds>2</scanIntervalSeconds>
<scanTargets>
<scanTarget>src/main/java</scanTarget>
</scanTargets>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<properties>
<maven.test.skip>true</maven.test.skip>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<executions>
<execution>
<id>default-war</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
- Skip optimzation (we use the primefaces-extensions plugin for this)
<plugin>
<groupId>org.primefaces.extensions</groupId>
<artifactId>resources-optimizer-maven-plugin</artifactId>
<executions>
<execution>
<id>optimize</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
throws ServletException, IOException
{
final OutputStream ouputStream = response.getOutputStream();
response.setContentType(getServletConfig().getInitParameter("contentType");
final List<File> filesToMerge = getFiles(getServletContext().getRealPath(getServletConfig().getInitParameter("includeDirectory")));
for (final File fileToMerge : filesToMerge) {
final FileInputStream inputStream = new FileInputStream(fileToMerge);
IOUtils.copy(inputStream, ouputStream);
inputStream.close();
}
ouputStream.close();
}
We just create a second web.xml (this is just for localhost and jetty) with the name "web-localhost.xml" in your "src/main/webapp/WEB-INF" directory with the following servlet mapping
<servlet>
<servlet-name>Merge Javascript Servlet</servlet-name>
<servlet-class>xxx.servlet.MergeResourceServlet</servlet-class>
<init-param>
<param-name>includeDirectory</param-name>
<param-value>/javascript/</param-value>
</init-param>
<init-param>
<param-name>contentType</param-name>
<param-value>application/x-javascript</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Merge Javascript Servlet</servlet-name>
<url-pattern>/javascript/bundle.js</url-pattern>
</servlet-mapping>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<webAppConfig>
<overrideDescriptor>src/main/webapp/WEB-INF/web-localhost.xml</overrideDescriptor>
</webAppConfig>
...
</configuration>
</plugin>
Finished! You will be able to start jetty now via "mvn package -P jetty-run".
Wednesday, October 3, 2012
Introducing PrimeFaces Extensions
In march 2011, I founded my first open source project called "PrimeFaces Extensions".
Our new application required a functionality to resize/rotate images and select a part of the image to do OCR (Optical Character Recognition), both with client-server communication.
I already had experience with JSF2 and PrimeFaces 2.2, so I decided to develop those components in my spare time based on PrimeFaces and commit it to a open source platform (Google Code).
After talking to Cagatay Civici (PrimeFaces founder and lead developer), I got green light to start the "PrimeFaces Extensions" project.
The first release contained this two components: ImageRotateAndResize and ImageAreaSelect.
Months later Oleg Varaksin joined my project as second lead and developer.
For the first big release (0.2), we developed many new components like CKEditor, MasterDetail, ResetInput and Layout.
Nevertheless, after 1,5 years of hard work, we can proudly say that we created some really unique and useful components which are used by many PrimeFaces users and also used in real-world applications!
Currently we are 6 developers around the world and we have about 25 components, functions, behaviors and converters.
Also some of our components and enhancements are now part of PrimeFaces and we also have a little influence on JSF 2.2 with our ResetInput component (JIRA Issue).
Thanks to Cagatay for PrimeFaces, Oleg for the great cooperation and the other PrimeFaces Extensions developers for their great work!
Our new application required a functionality to resize/rotate images and select a part of the image to do OCR (Optical Character Recognition), both with client-server communication.
I already had experience with JSF2 and PrimeFaces 2.2, so I decided to develop those components in my spare time based on PrimeFaces and commit it to a open source platform (Google Code).
After talking to Cagatay Civici (PrimeFaces founder and lead developer), I got green light to start the "PrimeFaces Extensions" project.
The first release contained this two components: ImageRotateAndResize and ImageAreaSelect.
Months later Oleg Varaksin joined my project as second lead and developer.
For the first big release (0.2), we developed many new components like CKEditor, MasterDetail, ResetInput and Layout.
Nevertheless, after 1,5 years of hard work, we can proudly say that we created some really unique and useful components which are used by many PrimeFaces users and also used in real-world applications!
Currently we are 6 developers around the world and we have about 25 components, functions, behaviors and converters.
Also some of our components and enhancements are now part of PrimeFaces and we also have a little influence on JSF 2.2 with our ResetInput component (JIRA Issue).
Thanks to Cagatay for PrimeFaces, Oleg for the great cooperation and the other PrimeFaces Extensions developers for their great work!
Thursday, September 6, 2012
Increase your JSF application performance (Part 2 - Design Patterns)
- Use Facelets instead of JSP
- If possible, always use HTML instead of JSF tags
- Never put logic in getters because they can be called multiple times - especially for the rendered attribute
- Avoid much logic in EL expression
- Avoid using h:outputText. Just use EL expressions. If you need to escape HTML, it's better to use a EL function
- Use AJAX as much as possible
- Only process and update components which are really required to process or update
- Cache data, which is required multiple times in the same view, in @RequestScoped beans
- Avoid using @SessionScoped, @ViewScoped and other long living scopes
- Split your beans. Its better to have a seperate bean for logic and a seperate bean for values which are required for multiple requests (@ViewScoped, @ViewAccessScoped...). I call them *Controller and *StateHolder
Friday, August 24, 2012
Get bean instance in CDI
In some cases it's required to get the bean instance instead of the reference.
You can simply do it with the following method:
You can simply do it with the following method:
public static <T> T getBeanInstance(final Class<T> type, final Class<? extends Annotation> scope, final BeanManager beanManager)
{
final Context context = beanManager.getContext(scope);
final Set<<Bean<?>> beans = beanManager.getBeans(type);
final Bean<T> bean = (Bean<T>) beanManager.resolve(beans);
final CreationalContext<T> creationalContext = beanManager.createCreationalContext(bean);
return context.get(bean, creationalContext);
}
Tuesday, August 21, 2012
Increase your JSF application performance (Part 1 - Environment & Configuration)
- Always use the newest MyFaces version (As you can read here: Blog Entry)
- If you just need a plain servlet container, use Tomcat instead of Jetty
- Use JUEL as EL implementation
- Add the newest JUEL API + implementation as depedency
- Configure MyFaces to use JUEL:
<context-param>
<param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
<param-value>de.odysseus.el.ExpressionFactoryImpl</param-value>
</context-param>
- Create src/main/resources/el.properties
- Add property javax.el.cacheSize with a custom size. The default size is 1000. In my application i use a size of 3000.
<context-param>
<param-name>org.apache.myfaces.EL_RESOLVER_COMPARATOR</param-name>
<param-value>org.apache.myfaces.el.unified.OpenWebBeansELResolverComparator</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.SUPPORT_JSP_AND_FACES_EL</param-name>
<param-value>false</param-value>
</context-param>
Attention: If you set this, you need to provide the "org.apache.myfaces.EXPRESSION_FACTORY" parameter.
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>-1</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.CHECK_ID_PRODUCTION_MODE</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.VIEW_UNIQUE_IDS_CACHE_ENABLED</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.SAVE_STATE_WITH_VISIT_TREE_ON_PSS</param-name>
<param-value>false</param-value>
</context-param>
Labels:
CDI,
JSF,
JUEL,
MyFaces,
OpenWebBeans,
OWB,
Performance,
Tomcat
Monday, August 20, 2012
Enable failover with OpenWebBeans (> 1.1.3)
With Tomcat 7.0.22, some changes has be done when
will be called. This caused that session replication was done before OpenWebBeans prepared the beans for the failover.
Therefore a new ServletFilter, which prepares the bean failover before session replication, was added in OpenWebBeans 1.1.4.
Just add it as FIRST filter in your web.xml:
and map it for example to the FacesServlet.
Also don't forget the src/main/resources/META-INF/openwebbeans/openwebbeans.properties with following entries:
Update for OWB 1.2.0 -> Click
ServletRequestListener
#requestDestroyed(javax.servlet.ServletRequestEvent)
will be called. This caused that session replication was done before OpenWebBeans prepared the beans for the failover.
Therefore a new ServletFilter, which prepares the bean failover before session replication, was added in OpenWebBeans 1.1.4.
Just add it as FIRST filter in your web.xml:
org.apache.webbeans.web.failover.FailOverFilter
and map it for example to the FacesServlet.
Also don't forget the src/main/resources/META-INF/openwebbeans/openwebbeans.properties with following entries:
configuration.ordinal=100
org.apache.webbeans.web.failover.issupportfailover=true
org.apache.webbeans.web.failover.issupportpassivation=true
Update for OWB 1.2.0 -> Click
Labels:
CDI,
Cluster,
Clustering,
FailOver,
OpenWebBeans,
OWB,
Session,
Tomcat
Subscribe to:
Posts (Atom)


