Showing posts from 2015

JavaOne 2015 Session: EJB 3.2/JPA 2.1 Best Practices with Real-Life Examples by Gohar

I have recently watched my friend Ahmed Nabil Gohar's session at JavaOne 2015. It's really a clear and straight to the point session. I'm sharing with you the sessions details (inluding the YouTube + the presentation downloadable link) as mentioned in his post.
Session ID: CON7535
Session Title: EJB 3.2/JPA 2.1 Best Practice with life examples (Download Link)
Session Type: Conference Session
Session Abstract:
This session’s speaker, an architect, discusses lessons learned from using JPA and EJB to support a high-volume, high-performance applications. These best practices don't only involve JPA/EJB but also its integration with other Java EE 7 technologies. They also include coding best practices, testing and production practices. The presentation focuses primarily on some Key concepts such as persistence context, lazy loading, caching, flushing, dirty checking, transaction and connection demarcation. This is a fast-paced presentation with many code samples. Categories…

Creating JSF/CDI Maven project on Eclipse

While I was working on a JSF and CDI example, I thought it would be useful to mention the steps required to create JSF and CDI Maven project. You can find the bellow steps to do so.
Eclipse Luna that's shipped with the M2E plugin by default. So no need to install the plugin yourself.WildFlye 8.x. 1- Select from the main menu File->New->Other. Then select Maven->Maven Project.
2- Click the Next button and then check "Create a simple project (skip archetype selection)".
3- Write the Group Id and the Artifact Id then select Packaging as WAR.
4- Click the Finish button to create the project with the bellow structure displayed in the Navigator view.
5- As you can see there is no deployment descriptor file (web.xml) as there is no WEB-INF folder. Also by checking on the Project Facets (select the project then ALT+ENTER then choose from the left menu Project Facets), we can see that the version of the Dynamic Web Module is 2.5 and the JavaServer Faces is not sele…

DynamicReports and JasperReports with JSF, Servlet and CDI

In this example, I will show how to integrate DynamicReport and JasperReports with Servlet and CDI.
TIBCO Jaspersoft  Luna Service Release 2 (4.4.2).WildFly 8.x application server. This is a screenshot from the project hierarchy on Eclipse.

1- The pom.xml file contains the required dependencies for the Servlets + JSF + CDI + DynamicReports.
<project xmlns="" xmlns:xsi="" xsi:schemaLocation=""> <modelVersion>4.0.0</modelVersion> <groupId>com.ithinkisink</groupId> <artifactId>DynamicReportsWithJSFServletsAndCDI</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>DynamicReportsWithJSFServletsAndCDI Maven Webapp</name> <dependencies> <dependency> <gr…

Weekly Readings - Week Ending 2 October 2015

Enable autocomplete for JSF in Eclipse

The autocomplete is not presented with Eclipse to discover the classes annotated with the @ManagedBean in the XHTML pages. Fortunately, JBoss Tools plugin enables to by installing the JBoss Tools JSF as shown in the bellow screenshot.

This is the link for installing the JBoss Tools for Eclipse Luna.
I have tried the latest Eclipse Mars and I figured out that Eclipse made things easier for us as developers. Now Eclipse Mars is delivered with support for autocomplete of the JSF Managed Beans. That's cool!

Weekly Readings - Week Ending 25 September 2015

Weekly Readings

I will start to post weekly posts about readings (that could be articles, technical documentations, references, technical questions ... etc) that I have gone through during every week. This would be useful to share with you what other people wrote about some technical stuff. I hope this would be useful in a way or another :)

Unicode characters in Java comments are executed as a normal code!

This is actually an interesting case about the Unicode in Java. I'm sharing with you this question from Stack Overflow about this case with a good answer explaining it.

Bidirectional relationship with Jackson in REST web services in WildFly

This is an example for a Bidirectional relationship between Java entities in a REST web service with the Jackson API.

1- Assume we have a bidirectional relationship between two entities Parent and Child.
2- Using MySQL workbench to generate the SQL schema file for this two tables.
DROP SCHEMA IF EXISTS `bidirectional_schema` ; CREATE SCHEMA IF NOT EXISTS `bidirectional_schema` DEFAULT CHARACTER SET utf8 ; USE `bidirectional_schema` ; -- ----------------------------------------------------- -- Table `bidirectional_schema`.`PARENT` -- ----------------------------------------------------- DROP TABLE IF EXISTS `bidirectional_schema`.`PARENT` ; CREATE TABLE IF NOT EXISTS `bidirectional_schema`.`PARENT` ( `PARENT_ID` INT NOT NULL , `PARENT_CONTENT` VARCHAR(45) NULL , PRIMARY KEY (`PARENT_ID`) ) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `bidirectional_schema`.`CHILD` -- ----------------------------------------------------- DROP TABLE IF EXIS…

Installing WebSphere Liberty Profile server then adding features

IBM WebSphere Liberty Profile is a really fast and easy to to use application server. According to the About page, the latest stable release of Liberty is Java EE 6 Web Profile-certified and they’re gradually adding Java EE 7 technologies. Any Java EE 6 applications you write on Liberty can be deployed in production, without changes, on WebSphere Application Server which is certified for the full Java EE 6 platform. You can, of course, deploy to production on Liberty too. Bellow we will see how to start working on it and adding some features to it.

1. Download the Liberty server from this link as a stand alone server.
Also you can embed it in Eclipse after installing the WebSphere Developer Tools through this link:
The Eclipse Marketplace would start like this for installing an adapter for the Eclipse.

Killing Websphere Liberty Profile processes in Windows

I face such issue as the Websphere Liberty Profile ports are used by a previous installation for the WMB so I have to manually kill the process in order to be able to start the application.
1- This is the error message that I got when I try to start the WLP server instance.
2- The bellow command lists the current ports and their processes ID's.
netstat -a -n -o 4- Open the CMD.exe as Administrator.

3- Now that we knew the processes ID's we kill them by one of the two bellow commands. The argument /F forces the killing of the process.
taskkill /PID <process_Id>taskkill /F /PID <process_Id>

PrimeFaces Push with Atmosphere

PrimeFaces Push is based on Atmosphere to establish WebSocket communication in an easy way. Bellow I will share the configuration to be able to do such kind of communication.
1- Adding the PrimeFaces and Atmosphere to the pom.xml for Maven dependency. Also, I added the dependency of the Apache Commons Lang3 to use the StringEscapeUtils while sending the notification message.
<dependency> <groupId>org.atmosphere</groupId> <artifactId>atmosphere-runtime</artifactId> <version>2.1.7</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.4</version> </dependency> <dependency> <groupId>org.primefaces</groupId> <artifactId>primefaces</artifactId> <version>5.0</version> </dependency> 2- The web.xml configuration for the push servlet.
<?xml version="1.0" encod…

EclipseLink on WildFly 8.2.0

WildFly application server uses Hibernate as a default JPA provider. So you can ignore specifying the persistence provider configuration in the persistence.xml file as bellow:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="" xmlns:xsi="" xsi:schemaLocation=""> <persistence-unit name="BidirectionalPU"> <jta-data-source>java:jboss/datasources/Bidirectional_DataSource</jta-data-source> <class>com.ithinkisink.entity.Child</class> <class>com.ithinkisink.entity.Parent</class> <class>model.TempTable</class> </persistence-unit> </persistence> The deployed application will then use Hibernate as default JPA provider. In order…

Bind WildFly to all available IP addresses on Eclipse

In order to be able to access the deployed applications on the WildFly server through the machine IP address, you should add the bellow configuration to the Eclipse lunch configuration as shown in the bellow screenshots.

1- Open launch configuration dialog from Eclipse.

2- Append "-b" to the Program argument.
For more information about binding the WildFly server to different IP addresses, check the link by Arun Gupta.


Postman, a REST web service client for Chrome

In case you needed to test a REST web service through a web service client. You can install Postman which is a Chrome extension. It's a pretty good one. You can install it from the bellow link:
I figured out that there is a another packaged application version. So I'm sharing with you the other one also:

Agile Architecture by Molly Dishman and Martin Fowler

I'm copying here what Mahmoud Atef mentioned in his post on Linkedin that sums up this video. I think it's really important to follow such tips in order to provide some sort of architecture management during the software development. Here is what Mahmoud wrote:

I was lucky to listen to  "Agile Architecture" talk by Molly Dishman & Martin Fowler (attached @the end of this post). I come up with eight points that I want to share my thoughts about.

Focus on the things that are hard to change and make them changeable. Mainly, service contracts and database design are the most rigid parts in any architecture design. Sometimes it's OK to fix them if the requirements are very clear from the beginning of the project, which is rare to happen. Most of the time, you need to find a way to simplify the change in these parts whenever it is needed.
Architects are more working as team leads and have to get their hands into code. In agile project, architects are almost engaged …

Java EE 7 Maven Coordinates

This is a useful link that contains the Maven dependencies for the Java EE platform APIs.

Adding MyBatis mapper files dynamically

I'm currently working in a project that we needed to implement such case. Assuming you are using MyBatis CDI in a EJB/CDI context, the bellow code will produce the MyBatis SqlSessionFactory for the MyBatis mapper files that are defined in a static way.

First, your Configuration.xml will only contain the database connection as bellow:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-// Config 3.0//EN" ""> <configuration> <environments default="development"> <environment id="development"> <transactionManager type="JDBC"/> <dataSource type="UNPOOLED"> <property name="driver" value="oracle.jdbc.driver.OracleDriver"/> <property name="url" value="jdbc:oracle:thin:@<HOST&g…

Using JUnit with GlassFish EJB embedded EJB container

1- Add the Glassfish embedded EJB container dependency to your Maven POM file. Also the JUnit dependency.
<dependency> <groupId>org.glassfish.main.extras</groupId> <artifactId>glassfish-embedded-all</artifactId> <version>3.1.2</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> </dependency> The scope is test so it can be applied during the testing of the application.

2- The service class is annotated with @Stateless as bellow
package; @Stateless public class MyService { public String getMessage() { return "Hello!"; } } For the sake of simplicity, the service class doesn't implement an interface as EJB supports injecting classes with no need to have interfaces.

3- Now the unit test class could be as bellow:
import javax.ejb.embeddabl…