Skip to main content

Seam application on JBoss 4.2.x with Maven 2

Every time when i configuring Seam project on JBoss using Maven, i loos two or three hours. So my intention is that this post be instruction how to build Seam project on JBoss using Maven. 


For this test project i will use next project sturcture:

  • parent
    • model
    • services
    • web
    • ear

Parent Project

I will start from parent project pom. In this pom file, will be configured dependencies management, plugin management and we will use this project for building application.
First of all, there is few way to create Seam project using Maven, but my preferred is setting up seam as parent project of my parent project. On this why i will get configured dependencies management.

<parent>
     <groupId>org.jboss.seam</groupId>
     <artifactId>root</artifactId>
     <version>2.2.1.Final</version>
</parent>

But if we want to get seam we need to include JBoss public repository, it can be done with adding repository section in you pom:

<repositories>
    <repository>
          <id>jboss-public-repository-group</id>
          <name>JBoss Public Maven Repository Group</name>
          <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
          <layout>default</layout>
          <releases>
               <enabled>true</enabled>
               <updatePolicy>never</updatePolicy>
          </releases>
          <snapshots>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
          </snapshots>
     </repository>
 </repositories>


Next step is defining modules:

<modules>
       <module>../sender-ear</module>
       <module>../sender-model</module>
       <module>../sender-service</module>
       <module>../sender-web</module>
 </modules>


After that we should take care about java compiler, and we can do it with maven compiler plugin. It is important to use Java 1.5+, because in earlier version of Java there is no support for annotations.

<plugin>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>2.3.2</version>
     <configuration>
         <!-- Set up version of Java, at least it need to be 1.5 (older version
           do not support annotation ) service -->
         <source>1.6</source> 
         <target>1.6</target>
      </configuration> 
</plugin>

Next thing is setting up of plugins management. For sure we will needed maven ejb plugin and maven ear plugin, but if you like to deploy and undeploy application from the server you can use maven jboss plugin. Also we should define project dependency management and define common dependencies for all modules used in the project. Next code snipet contains complete parent pom used by this test project:

<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>ba.codecentric.mail</groupId>
<artifactId>sender</artifactId>
<packaging>pom</packaging>
<name>parent</name>
<version>0.0.1-SNAPSHOT</version>


<!-- Include all seam dependencies, dependency-management are already configured -->
<parent>
    <groupId>org.jboss.seam</groupId>
    <artifactId>root</artifactId>
    <version>2.2.1.Final</version>
</parent>

<modules>
    <module>../sender-ear</module>
    <module>../sender-model</module>
    <module>../sender-service</module>
    <module>../sender-web</module>
</modules>

<properties>
    <earVersion>0.0.1-SNAPSHOT</earVersion>
    <modelVersion>0.0.1-SNAPSHOT</modelVersion>
    <serviceVersion>0.0.1-SNAPSHOT</serviceVersion>
    <webVersion>0.0.1-SNAPSHOT</webVersion>
    <JBOSS_HOME>/home/igor/Projects/Tools/jboss-4.2.3.GA</JBOSS_HOME>
    <SERVER_NAME>default</SERVER_NAME>
</properties>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-ejb-plugin</artifactId>
                 <version>2.3</version>
                 <configuration>
                      <ejbVersion>3.0</ejbVersion>
                 </configuration>
            </plugin>
            <plugin>
                 <artifactId>maven-ear-plugin</artifactId>
                 <version>2.6</version>
            </plugin>
            <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>jboss-maven-plugin</artifactId>
                 <version>1.5.0</version>
            </plugin>
        </plugins>
    </pluginManagement>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                 <!-- Set up version of Java, at least it need to be 1.5 (older version
                   do not support annotation ) service -->
                 <source>1.6</source>
                 <target>1.6</target>
             </configuration>
         </plugin>
         <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-eclipse-plugin</artifactId>
              <version>2.7</version>
              <configuration>
                   <wtpversion>2.0</wtpversion>
                   <downloadSources>true</downloadSources>
                   <downloadJavadocs>true</downloadJavadocs>
              </configuration>
          </plugin>
     </plugins>
</build>

<dependencyManagement>
     <dependencies>
          <dependency>
               <groupId>ba.codecentric.mail</groupId>
               <artifactId>sender-application</artifactId>
               <version>${earVersion}</version>
          </dependency>
          <dependency>
               <groupId>ba.codecentric.mail</groupId>
               <artifactId>sender-model</artifactId>
               <version>${modelVersion}</version>
          </dependency>
          <dependency>
               <groupId>ba.codecentric.mail</groupId>
               <artifactId>sender-service</artifactId>
               <version>${serviceVersion}</version>
          </dependency>
          <dependency>
               <groupId>ba.codecentric.mail</groupId>
               <artifactId>sender-web</artifactId>
               <version>${webVersion}</version>
          </dependency>
     </dependencies>
</dependencyManagement>

<repositories>
     <repository>
           <id>jboss-public-repository-group</id>
           <name>JBoss Public Maven Repository Group</name>
           <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
           <layout>default</layout>
           <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
           </releases>
           <snapshots>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
           </snapshots>
      </repository>
</repositories> 

</project>

Model Module


This project is not very interesting, it should contains model classes, and usually I use JPA, so i add dependency to persistence api. Here is complete pom of model project:


<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>ba.codecentric.mail</groupId>
<artifactId>sender-model</artifactId>
<packaging>jar</packaging>
<name>model</name>

<version>0.0.1-SNAPSHOT</version>
<!-- Include all seam dependencies, dependency-management are already configured -->
<parent>
    <groupId>ba.codecentric.mail</groupId>
    <artifactId>sender</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<dependencies>
   <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>persistence-api</artifactId>
   </dependency>
   <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>
</project>



Service Module


This module should contains EJB bean used by application. So we need to configure this project as ejb project and later we will include this projoct as ejb module in ear module. Here is sample of complete pom for ejb modul:


<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>ba.codecentric.mail</groupId>
<artifactId>sender-service</artifactId>
<packaging>ejb</packaging>
<name>ejb3 services</name>
<version>0.0.1-SNAPSHOT</version>
<parent>
    <groupId>ba.codecentric.mail</groupId>
    <artifactId>sender</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ejb-plugin</artifactId>
        </plugin>
     </plugins>
</build>

<dependencies>
    <dependency>
         <groupId>org.jboss.seam</groupId>
         <artifactId>jboss-seam</artifactId>
         <type>ejb</type>
         <scope>provided</scope>
     </dependency>
     <dependency>
          <groupId>ba.codecentric.mail</groupId>
          <artifactId>sender-model</artifactId>
     </dependency>
     <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-validator</artifactId>
      </dependency>
      <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
      </dependency>
      <dependency>
          <groupId>javax.ejb</groupId>
          <artifactId>ejb-api</artifactId>
          <version>3.0</version>
          <scope>provided</scope>
      </dependency>
</dependencies>
</project>

As you can see from pom file, dependencies for Seam is set to provided because seam we will include as independent module in ear package. Also ejb api is set to provide because it already available on JBoss.


At this why we have ready ejb module, but if we want to integrate seam with ejb we need to do some additional work. First of all we need to create empty seam.properties file which we places in the resource folder, this will allow as to use seam. But if we want to use seam in interactions with ejb beans we need to setup seam ejb interceptors. To do that we need to create META-INF folder inside of resources folder and there we should place ejb-jar.xml file. Contet of this configuration file is list below.



<?xml version="1.0" encoding="UTF-8"?>

<ejb-jar 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/ejb-jar_3_0.xsd"
  version="3.0">

<interceptors>
     <interceptor>
           <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
     </interceptor>
</interceptors>

<assembly-descriptor>
       <interceptor-binding>
            <ejb-name>*</ejb-name>
            <interceptor-class>org.jboss.seam.ejb.SeamInterceptor</interceptor-class>
       </interceptor-binding>
</assembly-descriptor>

</ejb-jar>


Now seam will be able to work together with ejb beans.


Web Module


In this module we configure front end, which will be shown to the web clients. Usually with seam I use RichFaces so I will also describe how to configure RichFaces.


First of all i will show you sample of pom file, and after that i will eplain how to integrate seam with you web application and hot to configure RichFaces. 


<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>ba.codecentric.mail</groupId>
<artifactId>sender-web</artifactId>
<packaging>war</packaging>
<name>web clieant</name>
<version>0.0.1-SNAPSHOT</version>
<parent>
    <groupId>ba.codecentric.mail</groupId>
    <artifactId>sender</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<dependencies>
     <dependency>
           <groupId>javax.faces</groupId>
           <artifactId>jsf-impl</artifactId>
           <scope>provided</scope>
     </dependency>
     <dependency>
           <groupId>javax.faces</groupId>
           <artifactId>jsf-api</artifactId>
           <scope>provided</scope>
     </dependency>
     <dependency>
           <groupId>org.richfaces.framework</groupId>
           <artifactId>richfaces-api</artifactId>
      </dependency>
      <dependency>
           <groupId>org.richfaces.framework</groupId>
           <artifactId>richfaces-impl</artifactId>
      </dependency>
      <dependency>
           <groupId>org.richfaces.ui</groupId>
           <artifactId>richfaces-ui</artifactId>
      </dependency>
      <dependency>
           <groupId>com.sun.facelets</groupId>
           <artifactId>jsf-facelets</artifactId>
       </dependency>
       <dependency>
           <groupId>org.jboss.seam</groupId>
           <artifactId>jboss-seam-ui</artifactId>
           <exclusions>
                <exclusion>
                     <groupId>org.jboss.seam</groupId>
                     <artifactId>jboss-seam</artifactId>
                </exclusion>
          </exclusions>
       </dependency>
       <dependency>
            <groupId>org.jboss.seam</groupId>
            <artifactId>jboss-seam-mail</artifactId>
            <exclusions>
                 <exclusion>
                       <groupId>org.jboss.seam</groupId>
                       <artifactId>jboss-seam</artifactId>
                 </exclusion>
            </exclusions>
        </dependency>
</dependencies>
</project>

Be aware that you need to exclude seam when you adding dependency for mail, ui, pdf ...


Seam UI is needed to make integration of seam with your web tier, and you also can see dependency for mail because in this example i used seam mail feature for sending mails from application. 
After we added needed dependencies we should configure web.xml so we can use Seam and RichFaces. Below is example of configured application descriptor.


<web-app version="2.5" 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-app_2_5.xsd">

<!-- Seam -->
<listener>
     <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
</listener>

<filter>
    <filter-name>Seam Filter</filter-name>
    <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>

<filter-mapping>
     <filter-name>Seam Filter</filter-name>
     <url-pattern>/*</url-pattern>
</filter-mapping>

<servlet>
     <servlet-name>Seam Resource Servlet</servlet-name>
     <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
</servlet>

<servlet-mapping>
     <servlet-name>Seam Resource Servlet</servlet-name>
     <url-pattern>/seam/resource/*</url-pattern>
</servlet-mapping>

<!-- Faces Servlet -->
<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>*.seam</url-pattern>
</servlet-mapping>

<!-- JSF parameters -->
<context-param>
       <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
       <param-value>.xhtml</param-value>
</context-param>

<context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>true</param-value>
</context-param>

<!-- Configuring richfaces -->
<context-param>
       <param-name>org.richfaces.SKIN</param-name>
       <param-value>classic</param-value>
</context-param>

<context-param>
     <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
     <param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>

<filter>
       <display-name>RichFaces Filter</display-name>
       <filter-name>richfaces</filter-name>
       <filter-class>org.ajax4jsf.Filter</filter-class>
</filter>

<filter-mapping>
        <filter-name>richfaces</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
</filter-mapping>

</web-app>


Also we need to create facesconfig.xml in WEB-INF folder.


<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" 
           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_1_2.xsd">

<!-- Facelets support -->
<application>
          <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>

</faces-config>

This will allow us to use Facelet. And at end we need to create componets.xml so we can use seam components in web tier. Here is example of components.xml:


<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
                  xmlns:core="http://jboss.com/products/seam/core"
                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:transaction="http://jboss.com/products/seam/transaction"
                  xmlns:web="http://jboss.com/products/seam/web"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:mail="http://jboss.com/products/seam/mail"
                  xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.2.xsd
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.2.xsd
                       http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.2.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.2.xsd
                       http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.2.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.2.xsd">

<core:manager conversation-timeout="120000" concurrent-request-timeout="500" conversation-id-parameter="cid" />

<transaction:no-transaction />

<core:init debug="true" jndi-pattern="mailSender/#{ejbName}/local" transaction-management-enabled="false" />

<mail:mail-session session-jndi-name="java:/Mail" />

<web:multipart-filter max-request-size="100000000" create-temp-files="false" />

</components>

After this you web tier is integrated with your backend.
At this example I disabled transaction, because I did not used any db in example project and I want to avoid possible exception which I can get during calling EJB components.


Ear Module


And at end we need to pack application and deploy it on JBoss. So this module is responsible for building ear file which will be deployed on JBoss. For this module is the most interesting configuration of the ear plugin.


<plugin>
    <artifactId>maven-ear-plugin</artifactId>
    <configuration>
         <displayName>mailSender</displayName>
         <jboss>
             <version>4.2</version>
         </jboss>
         <defaultLibBundleDir>lib</defaultLibBundleDir>
         <modules>
             <webModule>
                   <groupId>ba.codecentric.mail</groupId>
                   <artifactId>sender-web</artifactId>
                   <contextRoot>/mail-client</contextRoot>
                   <bundleFileName>sender-web.war</bundleFileName>
              </webModule>
              <ejbModule>
                   <groupId>org.jboss.seam</groupId>
                   <artifactId>jboss-seam</artifactId>
                   <bundleFileName>jboss-seam.jar</bundleFileName>
              </ejbModule>
              <ejbModule>
                   <groupId>ba.codecentric.mail</groupId>
                   <artifactId>sender-service</artifactId>
                   <bundleFileName>sender-service.jar</bundleFileName>
              </ejbModule>
          </modules>
          <!-- needed for jboss-app.xml -->
          <jboss>
               <version>4.2</version>
               <loader-repository>
                      seam.jboss.org:loader=mailSender
               </loader-repository>
          </jboss>
      </configuration>
</plugin>

With this we define ear moduls, in this case we defined to ejb modul and one web module. And you can see that Seam is included as ejb modul.
The next step is defining used dependencies for building ear archive. During this step you need to define version of used modules no matter if it is previously defined in dependency management of parent project.

<dependencies>
     <dependency>
           <groupId>ba.codecentric.mail</groupId>
           <artifactId>sender-model</artifactId>
           <version>0.0.1-SNAPSHOT</version>
           <type>jar</type>
      </dependency>
      <dependency>
           <groupId>ba.codecentric.mail</groupId>
           <artifactId>sender-service</artifactId>
           <version>0.0.1-SNAPSHOT</version>
           <type>ejb</type>
       </dependency>
       <dependency>
           <groupId>ba.codecentric.mail</groupId>
           <artifactId>sender-web</artifactId>
           <version>0.0.1-SNAPSHOT</version>
           <type>war</type>
       </dependency>
       <dependency>
            <groupId>org.jboss.seam</groupId>
            <artifactId>jboss-seam</artifactId>
            <version>2.2.1.Final</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.el</groupId>
                    <artifactId>el-api</artifactId>
                </exclusion>
            </exclusions>
            <type>ejb</type>
       </dependency>
</dependencies>


As you can see, el-api is excluded because JBoss already have it.
Here is complete pom.xml:


<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>ba.codecentric.mail</groupId>
<artifactId>sender-application</artifactId>
<packaging>ear</packaging>
<name>application</name>
<version>0.0.1-SNAPSHOT</version>


<parent>
<groupId>ba.codecentric.mail</groupId>
  <artifactId>sender</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</parent>


<build>
  <finalName>mailSender</finalName>
  <plugins>
  <plugin>
  <artifactId>maven-ear-plugin</artifactId>
  <configuration>
  <displayName>mailSender</displayName>
  <jboss>
  <version>4.2</version>
  </jboss>
  <defaultLibBundleDir>lib</defaultLibBundleDir>
  <modules>
  <webModule>
  <groupId>ba.codecentric.mail</groupId>
  <artifactId>sender-web</artifactId>
  <contextRoot>/mail-client</contextRoot>
  <bundleFileName>sender-web.war</bundleFileName>
  </webModule>
  <ejbModule>
  <groupId>org.jboss.seam</groupId>
  <artifactId>jboss-seam</artifactId>
  <bundleFileName>jboss-seam.jar</bundleFileName>
  </ejbModule>
  <ejbModule>
  <groupId>ba.codecentric.mail</groupId>
  <artifactId>sender-service</artifactId>
  <bundleFileName>sender-service.jar</bundleFileName>
  </ejbModule>
  </modules>
                    <!-- needed for jboss-app.xml -->
                    <jboss>
                         <version>4.2</version>
                         <loader-repository>
                                 seam.jboss.org:loader=mailSender
                         </loader-repository>
                     </jboss>
  </configuration>
  </plugin>
  <plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>jboss-maven-plugin</artifactId>
  <configuration>
                      <jbossHome>${JBOSS_HOME}</jbossHome>
  <serverName>${SERVER_NAME}</serverName>
  <fileName>${project.build.directory}/${project.build.finalName}.${project.packaging}</fileName>
  </configuration>
  </plugin>
  </plugins>
</build>


<dependencies>
  <dependency>
  <groupId>ba.codecentric.mail</groupId>
  <artifactId>sender-model</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <type>jar</type>
  </dependency>
  <dependency>
  <groupId>ba.codecentric.mail</groupId>
  <artifactId>sender-service</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <type>ejb</type>
  </dependency>
  <dependency>
  <groupId>ba.codecentric.mail</groupId>
  <artifactId>sender-web</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <type>war</type>
  </dependency>
  <dependency>
  <groupId>org.jboss.seam</groupId>
  <artifactId>jboss-seam</artifactId>
  <version>2.2.1.Final</version>
  <exclusions>
  <exclusion>
  <groupId>javax.el</groupId>
  <artifactId>el-api</artifactId>
  </exclusion>
  </exclusions>
  <type>ejb</type>
  </dependency>
</dependencies>


</project>


In this pom you can see that I have additionally configured jboss maven plugin which I using for deploying application to the JBoss.

Comments

Popular posts from this blog

Checking file's "magic numbers"

Few days ago I had very interesting task. Our customer required that we perform checking of so called file's "magic numbers" to determinate does uploaded file correspond to it's extension.  We are already allowed only to upload files with some predefined extensions (PDF, DOC ...). But this can not prevent some evil user to update an exe file after renaming it to PDF or DOC. So first of all I will explain what are "magic numbers", and then I will show how we handle them.

Simple Workflow Engine With Spring

Few months ago, during working on one of the company project, we had need to developed  REST services which is used for sending an email depending on data sent by client application. During developing this service we decide to create simple workflow engine which will be charged for sending an email, but also this engine can be used for any kind of simple flows. In this article i will explain step by step how you can implement your simple workflow engine which can handle sequence flow.

Running Spring Boot Web App on the Random Port from Port Range

By default the spring boot web application is listening on the port 8080 for the incoming connection. This behavior can be changed by providing server.port property value during starting of the application or as part of the application.properties or through the code by implementing EmbeddedServletContainerCustomizer. But it would be even better if we could specified a range of the ports which can be used for the starting the application. It would be great if I could specify a property like server.portRange=8100..8200 to define a list of the port on which I want to start my service. In this blog post I will describe how this can be done.