Tag: CDI

RestEasy WebService & RestEasy Client with CDI injection in JBoss AS7


As we are already aware that JBossAS 7.1 is a Fully EE6 certified Application Server. It provides implementations of most needed features like “RestEasy WebService” And “CDI” injection. You might have already seen/read some of the demos of RestEast webservices in our previous articles. But here in this article we are going to focus on following points .

Point-1). How to developand use the JAX-RS resteasy implementations and various annotations associated with it on JBoss AS7.1.1.Final.

Point-2). How to use the CDI Injection of @javax.inject.Named Beans using @javax.enterprise.context.ApplicationScoped inside our RestEasy WebServices. And will see that why do we need “beans.xml” file.

Point-3). How and why to use the annotations like @javax.xml.bind.annotation.XmlRootElement.

Point-4). How to write a Pure RestEasy Standalone Client to access the RestEasy WebService.

The Source Code of this Demo can be Downloaded from the following link: “Github”
https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/RestfulService_With_CDI_AS7

Writing RestEasy WebService with CDI Injection.

Step-1). Create a directory somewhere in your file system like “home/userone/RestfulService_With_CDI_AS7” then in this directory create a “src” directory where we will place all our source codes and application components.

Step-2). Write a Simple Class “Customer.java” inside “home/userone/RestfulService_With_CDI_AS7/src” with the help of “@javax.xml.bind.annotation.XmlRootElement” annotation sothat its value can be represented as XML element in an XML document.

package test;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Customer {

	private int id;
	private String name;
	private String address;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
}

Step-3). As above write another Simple Class “Customers.java” inside “home/userone/RestfulService_With_CDI_AS7/src” with the help of “@javax.xml.bind.annotation.XmlRootElement” annotation sothat its value also can be represented as XML element in an XML document.

package test;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.*;
@XmlRootElement
public class Customers {

	private List customer;

	public List getCustomer() {
		return customer;
	}

	public void setCustomer(List customer) {
		this.customer = customer;
	}
}

Step-4). Now we will write “TestBean.java” inorder to populate it’s property “java.util.TreeMap” with the Customer Objects. Write the “TestBean.java” program inside “home/userone/RestfulService_With_CDI_AS7/src”

package beans;
import java.io.Serializable;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import java.util.TreeMap;
import test.Customer;

@Named
@ApplicationScoped
public class TestBean implements Serializable
   {
    private static final long serialVersionUID = 1L;
    private TreeMap customerMap;

    public TestBean()
         {
           System.out.println("nt TestBean which is CDI Bean instantiated.");
           customerMap=new TreeMap();
         }

    public TreeMap getCustomerMap()
         {
            System.out.println("nt[TestBean] getCustomerMap() called.");
            return customerMap;
         }

    public void setCustomerMap(TreeMap customerMap)
         {
           System.out.println("nt[TestBean] setCustomerMap(TreeMap) called.");
           this.customerMap = customerMap;
         }
   }

Step-5). As in the above TestBean we have used the @Named annotation and we have declared it’s scope as “ApplicationScoped” so now we will create a “beans.xml” file which is finally going to be placed inside “WEB-INF” directory of our webapplication for the CDI to wrok. So here we will need to create a file with name “beans.xml” inside “home/userone/RestfulService_With_CDI_AS7/src” as following:

*** NOTE: An application that uses CDI must have a file named beans.xml. The file can be completely empty (it has content only in certain limited situations), but it must be present.

<beans 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/beans_1_0.xsd">


</beans>

Step-6). In order to develop RestEasy WebService we should provide a class which extends “javax.ws.rs.core.Application” so write a Program “MyRestService.java” inside “home/userone/RestfulService_With_CDI_AS7/src” as following:

package ws.test;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("test")
public class MyRestService  extends Application {

}

Step-7). Now the Most important Step Here we will write a Class “CustomersResource.java” with the help of “javax.ws.rs.*” packages in order to process the Client Requests. so write a Program “CustomersResource.java” inside “home/userone/RestfulService_With_CDI_AS7/src” as following:

package test;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.FormParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import javax.servlet.ServletContext;
import javax.ws.rs.core.Context;
import javax.inject.Inject;

@Produces("application/xml")
@Path("customers")
public class CustomersResource {

        @Inject
        private beans.TestBean testBean;

	private TreeMap customerMap = new TreeMap();

	public CustomersResource() {
                System.out.println("[CustomerResource] Instantiated  "+this);
		Customer customer1 = new Customer();
		customer1.setId(1111);
		customer1.setName("CustomerOne");
		customer1.setAddress("Bombay, India");

		Customer customer2 = new Customer();
		customer2.setId(2222);
		customer2.setName("CustomerTwo");
		customer2.setAddress("Pune, India");

		Customer customer3 = new Customer();
		customer3.setId(3333);
		customer3.setName("CustomerThree");
		customer3.setAddress("Bangalore, India");

                customerMap.put(customer1.getId(),customer1);
                customerMap.put(customer2.getId(),customer2);
                customerMap.put(customer3.getId(),customer3);

                if(testBean!=null)
                    {
                       System.out.println("[CustomersResource] testBean NOT NULL "+testBean);
                       testBean.setCustomerMap(customerMap);
                    }
                else
                    {
                       System.out.println("[CustomersResource] testBean IS NULL");
                    }
	}

	@GET
	@Produces(MediaType.APPLICATION_XML)
	@Path("all")
	public Customers getCustomers() {
		List customers = new ArrayList();
		customers.addAll(testBean.getCustomerMap().values());
                Customers allCustomers=new Customers();
                allCustomers.setCustomer(customers);
                return allCustomers;
	}

	@GET
	@Path("{id}")
	public Customer getCustomer(@PathParam("id") int customerId) {
		return customerMap.get(customerId);
	}

	public String addDefaultCustomer(Customer customer) {
		customerMap.put(customer.getId(), customer);
		return "Customer ID: " +  customer.getId() +" Name: "+ customer.getName()+" Address: "+customer.getAddress();
	}

	@POST
	@Path("add")
	@Produces(MediaType.APPLICATION_XML)
	@Consumes("application/x-www-form-urlencoded")
	public Customer addCustomer(@FormParam("custId")int id,@FormParam("custName")String name,@FormParam("custAddress")String address) {
		Customer customer = new Customer();
                customer.setId(id);
                customer.setName(name);
                customer.setAddress(address);
                customerMap.put(customer.getId(),customer);
                testBean.setCustomerMap(customerMap);
		return customer;
	}

}

Step-8). Now we will write following kind of JSP file “index.jsp” inside “home/userone/RestfulService_With_CDI_AS7/src” in order to allow users to provide/enter the customer details.


    CDI Demo
<table border="10%">
<form action="test/customers/add" method="POST"></form>
<tbody>
<tr>
<td>Customer ID:</td>
<td> <input name="custId" type="text" /></td>
</tr>
<tr>
<td>Customer Name:</td>
<td> <input name="custName" type="text" /></td>
</tr>
<tr>
<td>Customer Address:</td>
<td> <input name="custAddress" type="text" /></td>
</tr>
<tr>
<td><input type="submit" value="Add Customer" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
</tbody>
</table>

Step-9). Now write the following kind of “web.xml” file inside “home/userone/RestfulService_With_CDI_AS7/src” directord make sure that you are using the web.xml 3.0 version XSD (web-app_3_0.xsd) declaration in your web.xml file as following


        javax.ws.rs.core.Application
        javax.ws.rs.core.Application

        javax.ws.rs.core.Application
        /*

Step-10). Now we will write the ANT “build.xml” file inside “home/userone/RestfulService_With_CDI_AS7” directory in order to build and deploy and test our WebService .


           <!-- Need to place at lease one empty "beans.xml" file inside WEB-INF -->

Step-11). Now before running your ANT script to build and deploy the above webapplication you should have the ANT as well as JAVA set in the $PATH variable of the Shell / command prompt as following:

.
For Unix Based OS:
export PATH=/home/userone/jdk1.6.0_21/bin:/home/userone/org.apache.ant_1.6.5/bin:$PATH

For Windows Based OS:
set PATH=C:/jdk1.6.0_21/bin;C:/org.apache.ant_1.6.5/bin;%PATH%
.

Step-12). Now once the PATH is set In the command/Shell prompt you can move inside the directory “home/userone/RestfulService_With_CDI_AS7” and then run the ant to build/deploy the webservice. by running the command “ant”

[userone@localhost RestfulService_With_CDI_AS7]$ ant
Buildfile: build.xml

init:
   [delete] Deleting directory /userone/RestfulService_With_CDI_AS7/build
    [mkdir] Created dir: /userone/RestfulService_With_CDI_AS7/build
    [mkdir] Created dir: /userone/RestfulService_With_CDI_AS7/tmp

build:
    [mkdir] Created dir: /userone/RestfulService_With_CDI_AS7/tmp/WEB-INF/classes
    [javac] Compiling 5 source files to /userone/RestfulService_With_CDI_AS7/tmp/WEB-INF/classes
     [copy] Copying 1 file to /userone/RestfulService_With_CDI_AS7/tmp
     [copy] Copying 1 file to /userone/RestfulService_With_CDI_AS7/tmp
     [copy] Copying 1 file to /userone/RestfulService_With_CDI_AS7/tmp/WEB-INF/classes
     [copy] Copying 1 file to /userone/RestfulService_With_CDI_AS7/tmp/WEB-INF/classes
     [copy] Copying 1 file to /userone/RestfulService_With_CDI_AS7/tmp/WEB-INF
      [jar] Building jar: /userone/RestfulService_With_CDI_AS7/tmp/RestServiceWithCDI.war
     [copy] Copying 1 file to /userone/RestfulService_With_CDI_AS7/build

deploy:
     [echo] *******************  Deploying the WAR file RestServiceWithCDI.war *********************
     [echo] ********** build/RestServiceWithCDI.war to /home/userone/jboss-as-7.1.1.Final/standalone/deployments **********
     [copy] Copying 1 file to /home/userone/jboss-as-7.1.1.Final/standalone/deployments
     [echo] *******************  Deployed Successfully   *********************

BUILD SUCCESSFUL
Total time: 2 seconds

Testing The RestEasy WebService from WebBrowser

Step-13). Once the WebService is deployed successfully you can access it using the following URL: “http://localhost:8080/RestServiceWithCDI//index.jsp” As following:

RestEasyWebService_CDI_Inserting Customer Data

If you want to access all the Customers Details then access te following URL “http://localhost:8080/RestServiceWithCDI/test/customers/all” :

RestEasyWebService_With_CDI_Retrieving all Customers Record

Writing and Testing a Pure RestEasy WebService Client

Step-13). Now we are going to use our own Standalone RestEasy WebService Client in order to access the WebService. So write program with name “RestEasyClient.java” inside “home/userone/RestfulService_With_CDI_AS7/src” directory as following:

package client;
import java.io.*;
import javax.ws.rs.core.MediaType;
import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ClientResponse;

public class RestEasyClient
{
      public static void main(String ar[]) throws Exception
       {
        String url="http://localhost:8080/RestServiceWithCDI/test/customers/all";
        MediaType mediaType=MediaType.APPLICATION_XML_TYPE;
        String result = "";

        try
        {
            ClientRequest request = new ClientRequest(url);
            request.accept(mediaType);
            ClientResponse response = request.get(String.class);
            if (response.getStatus() != 200)
            {
                System.out.println("***** BAD RESPONSE *****");
                throw new RuntimeException("Request Processing Failed with HTTP status: "+ response.getStatus());
            }

            BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(response.getEntity().getBytes())));
            String output = null;
            while ((output = br.readLine()) != null)
            {
                result = result+output+"n";
            }

            result=result.replaceAll("><",">n<");
            System.out.println("nn********** RESULT **********n"+result);
        }
        catch (Exception e)
        {
            System.err.println("nt Exception Occured: "+e);
            e.printStackTrace();
        }
    }
}

Step-14). Now run the command “ant client” in order compile and run the Client program from the following directory “home/userone/RestfulService_With_CDI_AS7” as following:

[userone@localhost RestfulService_With_CDI_AS7]$ ant client
Buildfile: build.xml

client:
     [echo] *******************  Client Accessing RestEasy Service *********************
    [javac] Compiling 6 source files to /NotBackedUp/Downloads/RestfulService_With_CDI_AS7/build
      log4j:WARN No appenders could be found for logger (org.jboss.resteasy.plugins.providers.DocumentProvider).
      log4j:WARN Please initialize the log4j system properly.
      log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
      
      
      ********** RESULT **********
      <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
      <customers>
      <customer>
      <address>Bombay, India</address>
      <id>1111</id>
      <name>CustomerOne</name>
      </customer>
      <customer>
      <address>Pune, India</address>
      <id>2222</id>
      <name>CustomerTwo</name>
      </customer>
      <customer>
      <address>Bangalore, India</address>
      <id>3333</id>
      <name>CustomerThree</name>
      </customer>
      <customer>
      <address>Pune, India</address>
      <id>8888</id>
      <name>MiddlewareMagic</name>
      </customer>
      </customers>
      

BUILD SUCCESSFUL
Total time: 3 seconds

.
.
Thanks 🙂
Middleware Magic Team


CDI Injection inside a HttpServlet with JBoss AS7

Hi,

As JBoss AS7 is very new And most powerful application server with many changes in it. JBossAS7 web profile is fully EE6 Certified however the JBoss AS7 full profile will be released soon with the full EE6 capabilities. CDI (Conextual Dependency Injection) is one of the most attractive feature of EE6. Managed beans are a key concept introduced in Java EE6. More details on CDI specification can be found in the following link: http://jcp.org/en/jsr/detail?id=299

So here we are going to see a very simple demo in which we will create our own Bean using “@javax.inject.Named” annotation and we will define it’s scope as “@javax.enterprise.context.SessionScoped”. Then we will try to inject this Plain Bean inside our HttpServlets using annotation “@javax.inject.Inject”. We will also see how we can develop, build, deploy and test this simple WAR file.

Features To Discuss.

In this example we will mainly focus on following points

Point-1). Here we are using JBoss AS7 latest build “jboss-as-7.1.0.Beta1” which can be downloaded from the following link: http://www.jboss.org/jbossas/downloads

Point-2). How to use and develop Servlets3.0 annotations without writing “web.xml” file.

Point-3). How to create our own Managed Beans using annotations @Named.

Point-4). Also we will see how to define the scope of our Beans using annotation @SessionScope.

Point-5). How to inject a Named Bean inside a Servlet using @Inject Annotation.

Point-6). For creating and using Named beans we must create at least one empty “beans.xml” file inside our applications “WEB-INF” directory, If it is a Web Application. For EJB Based application it can be placed inside the “META-INF” directory. For Plain Jar files it can be placed inside the jars present inside the “lib” directory.

Developing TestCase

Step1). Create a directory somewhere in your filesystem like “/home/userone/CDI_Demo” where we will place our application build related stuff. Then create another directory “src” inside “/home/userone/CDI_Demo” where we will be placing our source codes and JSPs.
Just place an empty “beans.properties” file inside “/home/userone/CDI_Demo/src”

Step2). Create Bean class “TestBean.java” as following inside the “/home/userone/CDI_Demo/src” directory.

package beans;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@SessionScoped
public class TestBean implements Serializable 
   {
	private static final long serialVersionUID = 1L;
	private String beanParam="Hi MiddlewareMagic !!!";

        public TestBean()
         {
    	   System.out.println("nt TestBean which is CDI Bean instentiated.");
         }
    
	public String getBeanParam() 
         {
	    System.out.println("nt getBeanParam() called.");
	    return beanParam;
	 }

	public void setBeanParam(String beanParam) 
         {
	    System.out.println("nt setBeanParam("+beanParam+") called.");
	    this.beanParam = beanParam;
	 }	
   }

Step2-A) Make sure that at least one empty file “beans.xml” need to be placed inside the “WEB-INF” directory of your application in order to web beans work.
So create an empty file with name “beans.xml” and then place it inside “/home/userone/CDI_Demo/src” then later while Build phase of the application we will put this file inside “WEB-INF” directory of our web application.

Step3). Now we will create a Simple HttpServlet class “TestServlet.java” inside “/home/userone/CDI_Demo/src” directory as following:

package servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;

import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.annotation.WebServlet;

@WebServlet(description = "TestServlet Description", urlPatterns = { "/TestServlet" })
public class TestServlet extends HttpServlet {
	
	@Inject 
	private beans.TestBean testBean;
	
	private static final long serialVersionUID = 1L;
        public TestServlet() 
        {
          super();
          System.out.println("TestServlet Initialized & Instentiated.");
        }

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
        {
          PrintWriter out=response.getWriter(); 
	  out.println("testBean.getBeanParam() = "+testBean.getBeanParam());
          testBean.setBeanParam("Hello, MiddlewareMagic");
          out.println("testBean.getBeanParam() = "+testBean.getBeanParam());
	}
}

Step4). Now we will write another simple Servlet “TestServletTwo.java” to check whether the Named Bean is present inside the SesionScope or not? Place this file as well inside the “/home/userone/CDI_Demo/src” directory as following:

package servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;

import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.annotation.WebServlet;

@WebServlet(description = "TestServletTwo Description", urlPatterns = { "/TestServletTwo" })
public class TestServletTwo extends HttpServlet {
	
	@Inject 
	private beans.TestBean testBean;
	
	private static final long serialVersionUID = 1L;
        public TestServletTwo() 
        {
          super();
          System.out.println("TestServletTwo Initialized & Instentiated.");
        }

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
        {
          PrintWriter out=response.getWriter(); 
	  out.println("testBean.getBeanParam() = "+testBean.getBeanParam());
	}
}

Step5). Now we will write a simple “index.jsp” page to just provide a link to access the “TestServlet” , Place this file as well inside the “/home/userone/CDI_Demo/src” directory as following:

<html>
  <head> 
    <title>CDI Demo</title>
  </head>
  <body>
      <a href="TestServlet">Click Here !!!</a>
  </body>
</html>

Step6). Now the most important part, here we are going to develop “build.xml” ANT file, which will build, deployour webapplication on the JBoss AS7.1 Beta Server, so write the following “build.xml” file inside “/home/userone/CDI_Demo” directory.

<project name="CDI_Demo" default="deploy">
<property name="jboss.home" value="/home/userone/jboss-as-7.1.0.Beta1" />
<property name="jboss.module.dir" value="${jboss.home}/modules" />
<property name="basedir" value="." />
<property name="tmp.dir" value="tmp" />
<property name="output.dir" value="build" />
<property name="src.dir" value="src" />
<property name="war.name" value="EE6Feature_CDIDemo.war" />

   <path id="jboss.classpath">
     <fileset dir="${jboss.module.dir}">
        <include name="**/*.jar"/>
     </fileset>  
   </path>

        <target name="init">
           <delete dir="${output.dir}" />
           <mkdir dir="${output.dir}" />
           <delete dir="${tmp.dir}" />
           <mkdir dir="${tmp.dir}" />
        </target>
	 
        <target name="build" depends="init">
           <mkdir dir="${tmp.dir}/WEB-INF/classes"/>
           <javac srcdir="${src.dir}" destdir="${tmp.dir}/WEB-INF/classes"  includes="*.java" classpathref="jboss.classpath" />
           <copy file="${src.dir}/index.jsp" tofile="${tmp.dir}/index.jsp"/>
           <copy file="${src.dir}/TestServlet.java" todir="${tmp.dir}/WEB-INF/classes"/>
           <copy file="${src.dir}/TestServletTwo.java" todir="${tmp.dir}/WEB-INF/classes"/>
           <copy file="${src.dir}/TestBean.java" todir="${tmp.dir}/WEB-INF/classes"/>

           <!-- Need to place at lease one empty "beans.xml" file inside WEB-INF -->
           <copy file="${src.dir}/beans.xml" todir="${tmp.dir}/WEB-INF"/>
   
           <jar jarfile="${tmp.dir}/${war.name}" basedir="${tmp.dir}" compress="true" />
           <copy file="${tmp.dir}/${war.name}" tofile="${output.dir}/${war.name}"/>

           <delete includeEmptyDirs="true">
              <fileset dir="${tmp.dir}"/>
           </delete> 
        </target>

        <target name="deploy" depends="build">
            <echo message="*******************  Deploying the WAR file ${war.name} *********************" />  
            <echo message="********** ${output.dir}/${war.name} to ${jboss.home}/standalone/deployments **********" />  
            <copy todir="${jboss.home}/standalone/deployments/">
                <fileset dir="${output.dir}/">
                  <include name="${war.name}"/> 
                </fileset>
            </copy>
            <echo message="*******************  Deployed Successfully   *********************" />  
        </target>
</project>

NOTE: The only change in the above file you need to do is to change the “jboss.home” directory path in the second line of the above script to point to your own JBoss AS7 directory.

Step7). Now before running your ANT script to build and deploy the above webapplication you should have the ANT as well as JAVA set in the $PATH variable of the Shell / command prompt as following:

For Unix Based OS:
export PATH=/home/userone/jdk1.6.0_21/bin:/home/userone/org.apache.ant_1.6.5/bin:$PATH

For Windows Based OS:
set PATH=C:/jdk1.6.0_21/bin;C:/org.apache.ant_1.6.5/bin;%PATH%

Step8). Now once the PATH is set In the command/Shell prompt you can move inside the directory “/home/userone/CDI_Demo” and then run the ant to build the webservice. by running the command “ant build”

[userone@localhost EE6_Async_Servlet_Demo]$ ant deploy
Buildfile: /home/userone/CDI_Demo/build.xml

init:
   [delete] Deleting directory /home/userone/CDI_Demo/build
    [mkdir] Created dir: /home/userone/CDI_Demo/build
    [mkdir] Created dir: /home/userone/CDI_Demo/tmp

build:
    [mkdir] Created dir: /home/userone/CDI_Demo/tmp/WEB-INF/classes
    [javac] /home/userone/CDI_Demo/build.xml:25: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 3 source files to /home/userone/CDI_Demo/tmp/WEB-INF/classes
     [copy] Copying 1 file to /home/userone/CDI_Demo/tmp
     [copy] Copying 1 file to /home/userone/CDI_Demo/tmp/WEB-INF/classes
     [copy] Copying 1 file to /home/userone/CDI_Demo/tmp/WEB-INF/classes
     [copy] Copying 1 file to /home/userone/CDI_Demo/tmp/WEB-INF/classes
     [copy] Copying 1 file to /home/userone/CDI_Demo/tmp/WEB-INF
      [jar] Building jar: /home/userone/CDI_Demo/tmp/EE6Feature_CDIDemo.war
     [copy] Copying 1 file to /home/userone/CDI_Demo/build

deploy:
     [echo] *******************  Deploying the WAR file EE6Feature_CDIDemo.war *********************
     [echo] ********** build/EE6Feature_CDIDemo.war to /home/userone/jboss-as-7.1.0.Beta1/standalone/deployments **********
     [copy] Copying 1 file to /home/userone/jboss-as-7.1.0.Beta1/standalone/deployments
     [echo] *******************  Deployed Successfully   *********************

BUILD SUCCESSFUL
Total time: 2 seconds

Step9). Now you will see the following kind of output on your JBoss AS7.1 console which means the application is deployed successfully:

11:41:27,741 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-2) Starting deployment of "EE6Feature_CDIDemo.war"
11:41:27,760 INFO  [org.jboss.weld] (MSC service thread 1-5) Processing CDI deployment: EE6Feature_CDIDemo.war
11:41:27,770 INFO  [org.jboss.weld] (MSC service thread 1-3) Starting Services for CDI deployment: EE6Feature_CDIDemo.war
11:41:27,775 INFO  [org.jboss.weld] (MSC service thread 1-3) Starting weld service
11:41:27,859 INFO  [org.jboss.web] (MSC service thread 1-2) registering web context: /EE6Feature_CDIDemo
11:41:27,898 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 1) Replaced deployment "EE6Feature_CDIDemo.war" with deployment "EE6Feature_CDIDemo.war"

Step10). Now access the WebApplication like following :
http://localhost:8080/EE6Feature_CDIDemo/TestServlet
AND then
http://localhost:8080/EE6Feature_CDIDemo/TestServletTwo

You will notice that the TestBean is injected inside these servlets using Session Scope.

.
.
Thanks
Middleware Magic Team


Copyright © 2010-2012 Middleware Magic. All rights reserved. |