Saturday, May 30, 2015

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" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>PrimePushNotify</display-name>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <servlet>
    <servlet-name>PrimePushServlet</servlet-name>
    <servlet-class>org.primefaces.push.PushServlet</servlet-class>
    <init-param>
      <param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
      <param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
    <async-supported>true</async-supported>
  </servlet>
  <servlet-mapping>
    <servlet-name>PrimePushServlet</servlet-name>
    <url-pattern>/primepush/*</url-pattern>
  </servlet-mapping>
</web-app>

Friday, May 29, 2015

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="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
 <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 to switch WildFly to use EclipseLink, you can follow the bellow steps:
1- Download the EclipseLink JAR file from the bellow Maven repository link:
http://mvnrepository.com/artifact/org.eclipse.persistence/eclipselink/2.6.0
2- Now navigate to the following directory under the WildFly server directory:
<PATH_TO_WILDFLY_DIRECTORY>\wildfly-8.2.0.Final\modules\system\layers\base\org\eclipse\persistence\main
3- Move the EclipseLink JAR file to the above directory and remove the version from the file name, so it would be eclipselink.jar.
4- Add the eclipselink.jar to the <resources> of the module.xml in the mentioned directory.
<module xmlns="urn:jboss:module:1.3" name="org.eclipse.persistence">
    <resources>
        <resource-root path="jipijapa-eclipselink-1.0.1.Final.jar"/>
  <resource-root path="eclipselink.jar"/>
    </resources>

    <dependencies>
        <module name="asm.asm"/>
        <module name="javax.api"/>
        <module name="javax.annotation.api"/>
        <module name="javax.enterprise.api"/>
        <module name="javax.persistence.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.validation.api"/>
        <module name="javax.xml.bind.api"/>
        <module name="org.antlr"/>
        <module name="org.apache.commons.collections"/>
        <module name="org.dom4j"/>
        <module name="org.javassist"/>
        <module name="org.jboss.as.jpa.spi"/>
        <module name="org.jboss.logging"/>
        <module name="org.jboss.vfs"/>
    </dependencies>
</module>
5- Now you can point the JPA provider to org.eclipse.persistence.jpa.PersistenceProvider.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
 <persistence-unit name="BidirectionalPU">
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
     <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>

Thursday, May 28, 2015

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 0.0.0.0" to the Program argument.

For more information about binding the WildFly server to different IP addresses, check the link by Arun Gupta.

References:
http://blog.arungupta.me/bind-wildfly-different-ip-address-multihomed/

Friday, May 1, 2015

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:
https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en
Update:
I figured out that there is a another packaged application version. So I'm sharing with you the other one also:
https://chrome.google.com/webstore/detail/postman-rest-client-packa/fhbjgbiflinjbdggehcddcbncdddomop?hl=en