Friday, June 12, 2015

Simple restful service using jersey+json format


Resource class


package com.hps.resources;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hps.model.HelloRequest;
import com.hps.model.HelloResponse;

@Path("/admin")
public class MessageResource {
@GET
@Path("{parameter}")
public Response responseMsg( @PathParam("parameter") String parameter,
@DefaultValue("Nothing to say") @QueryParam("value") String value) throws JsonProcessingException, UnknownHostException {
String output = "Hello from: " + parameter + " : " + value;
return Response.status(200).entity(output).build();
}
@POST
@Path("/action")
@Produces(MediaType.APPLICATION_JSON)
public Response produceJson(HelloRequest helloRequest) throws JsonProcessingException, UnknownHostException{
String output = "Hello from: " + helloRequest.getParameter() + " : " +helloRequest.getMessage();

HelloResponse reponse = new HelloResponse(output);
reponse.setStatus(Response.Status.CREATED.getStatusCode());
return Response.status(200).entity(reponse).build();
}


}

HelloRequest.java



@XmlRootElement
public class HelloRequest {
private String message;
private String parameter;
//getters and setter methods
}

HelloResponse.java

public class HelloResponse {
private String message;
private int status;
//getters and setters
}


MyApplication.java(this will produce the json response)


import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import org.glassfish.jersey.filter.LoggingFilter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;

@ApplicationPath("/")
public class MyApplication extends Application {

@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(MessageResource.class);
return classes;
}
@Override
public Set<Object> getSingletons() {
final Set<Object> instances = new HashSet<Object>();
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
instances.add(new JacksonJsonProvider(mapper));
instances.add(new LoggingFilter());
return instances;
}
}

web.xml



<servlet>
        <servlet-name>rest</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
          <param-name>javax.ws.rs.Application</param-name>
          <param-value>com.hps.resources.MyApplication</param-value>
        </init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>







Inserting and Retrieving images in MongoDB without GridFs Library

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.UnknownHostException;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.Mongo;
import com.mongodb.MongoException;

public class SaveImageApp {
public static void main(String[] args)
{
SaveImageApp o = new SaveImageApp();
o.withoutUsingGridFS();
}
public  void withoutUsingGridFS()
{
try {
Mongo mongo = new Mongo("localhost", 27017);
DB db = mongo.getDB("imagedb");
DBCollection collection = db.getCollection("dummyColl");

String filename = "C:/TEOProjectWorkspace/Mongodb/hoopertext.png";
String empname ="hooper";
insert(empname,filename,collection);
String destfilename = "C:/TEOProjectWorkspace/Mongodb/hoopertext.png";
retrieve(empname, destfilename, collection);

} catch (UnknownHostException e) {
e.printStackTrace();
} catch (MongoException e) {
e.printStackTrace();
}
}

public   void insert(String empname, String filename, DBCollection collection)
{
try
{
File imageFile = new File(filename);
FileInputStream f = new FileInputStream(imageFile);
byte b[] = new byte[f.available()];
f.read(b);

//    Binary data = new Binary(b);
BasicDBObject o = new BasicDBObject();
o.append("name",empname).append("photo",b);
collection.insert(o);
System.out.println("Inserted record.");
f.close();

} catch (IOException e) {
e.printStackTrace();
}
}
void retrieve(String name, String filename, DBCollection collection)
{
byte c[];
try
{
DBObject obj = collection.findOne(new BasicDBObject("name", name));
String n = (String)obj.get("name");
c = (byte[])obj.get("photo");
FileOutputStream fout = new FileOutputStream(filename);
fout.write(c);
fout.flush();
System.out.println("Photo of "+name+" retrieved and stored at "+filename);
fout.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}

Friday, June 5, 2015

JSTl Important Tags

JSTL out tag

JSTL out tag is used to display information on JSP. It can also be used with properties of the bean.

JSTL c out tag Example:

To display the name of the product on JSP, you can use the <c:out> tag like:

<c:out value="${product.name}" default="Not Available" escapeXml="true"></c:out>

The above statement assumes that product object is available on this JSP and that product bean has a property name with setters and getters.
Attributes of <c:out> tag are:
   Required Attributes:
       1. value:This attribute needs expression to be evaluated.
  Optional Attributes:
       1. default: This attribute provides default value if the resulting value is null.
       2. escapeXml: This attribute determines whether characters &,'," in the resulting string should be converted to their corresponding character entity codes. Default value is set to true.

JSTL forEach Tag

JSTL forEach tag is used to iterate over the collection. It can be List, Set, ArrayList, HashMap or any other collection.
JSTL forEach Example:
To display the name of the product on JSP, you can use the <c:forEach> tag like:

<c:forEach items="${productList}" var="product" varStatus="status">
    <c:out value="${product.name}" default="Not Available" escapeXml="false"></c:out>
  </c:forEach>

The above statement assumes that productList object is available on this JSP and that product bean has a property name with setters and getters.
As you can see above, in the JSTL forEach tag, items attirbute is used to define the collection. It will iterate over productList. In each iteration, it will get a product variable defined with attribute var. status attirbute keeps track of iteration.
Withing starting and ending tag of forEach, you can display or apply other logic to each object in the collection. As shown in the above example, product name is displayed with index using c:out tag
Attributes of JSTL forEach tag are:
    1. items:This attribute provides collection of items to iterate over.
     2. var: This attribute provides name of the exported scoped variable for the current item of the iteration. This scoped variable has nested visiblity. Its type depends on the object of the underlying collection.
     3. varStatus: This attribute provides name of the exported scoped variable for the status of the iteration. Object exported is of type javax.servlet.jsp.jstl.core.LoopTagStatus. This scoped variable has nested visibility.
     4. begin: If items specified: Iteration begins at the item located at the specified index. First item of the collection has index 0. If items not specified: Iteration begins with index set at the value specified.
     5. end: If items specified: Iteration ends at the item located at the specified index (inclusive). If items not specified: Iteration ends when index reaches the value specified.
    6. step: Iteration will only process every step items of the collection, starting with the first one.
Iterate over HashMap:
Let's take another example which many people face during coding of real web application. Many times you get HashMap and need to iterate over it. In the example below, I take Map of Country Code and Currency, where country code is unique and selected as a key and currency is a value.

<c:forEach items="${countryCurrencyMap}" var="entry" varStatus="status>
    <c:out value="${entry.key}"> : <c:out value="${entry.value}">
 </c:forEach>

JSTL Set Tag

JSTL Set tag is used to create new variable and assign a value to new or existing variable. 

JSTL Set Tag Example,
 <c:set var="weight" value="10.05"/>
 <c:out value="${weight}"/> 

As you can see above, in the set tag, new variable "weight" is created and value is set to 10.05. In the next line, it prints the valued of weight variable using out tag.

JSTL IF Tag

JSTL c:if tag is used as a conditional statement in JSP. It is similar like If statement in JAVA. Based on condition evaluation within test attribute, if tag decides to run the code within JSTL IF tag

  <c:if test="${weight > 0}"/>
         <c:out value="${weight}"/>
     </c:if>

As you can see above, in the JSTL c:if tag, test attribute check the condition and if condition returns true, it executes the other statements within <c:if> and </c:if> statement.

JSTL If Else Statement Example

Like JAVA, JSTL has if statement. However, JSTL do not have if else statement like JAVA. JSTL provides same functionality using choose-when-otherwise statement. These tags are used as a conditional statement in JSP.
In this tutorial, you will see examples for both JSTL If statement and JSTL if else statement ( using choose-when-otherwise  statement ). 
JSTL c:if tag example:
Assume that you have a variable weight in your application. It is available in pound. You want to convert it to Kilograms. However you want to convert it only, if it is available and not null. You can use c:if tag in this case.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
              "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL If Tag Example</title>
</head>

<body>

<c:set var="weight" value="10">
 <c:if test="${weight != null}">
 Weight of the product is ${weight * 0.453592} kgs. 
 <c:if> 
</body>
</html> 


Output: Weight of the product is 4.53592 kgs.
As you can see above, <c:if> tag in JSTL is similar to if statement in JAVA.
JSTL if else tag example:
Let's continue with same example shown above where you have a variable weight of the product available in pound and you want to convert it to Kilograms. However you want to show different messages for different condition.
If weight is null, you want to display "Weight is not provided for this product."
If weight is negative, you want to display "Incorrect weight. It can not be negative."
If weight is zero, you want to display "Incorrect weight. It can not be zero."
If weight is not null and above zero, you want to display "Weight of the product is XXXX kgs."
In this case you want to use if else statement in JAVA. But in JSTL, you can use c:choose - c:when - c:otherwiser tag.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
              "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSTL If Tag Example</title>
</head>
<body>

    Scenario 1:
    <!--Weight is not available-->
    <c:choose>
        <c:when test="${weight == null}">
             Weight is not provided for this product.
        </c:when>
        <c:when test="${weight <= 0}">
             Incorrect weight. It can not be zero or negative.
        </c:when>
        <c:otherwise>
             Weight of the product is <c:out value="${weight}"/> lbs.
        <c:otherwise/>
    </c:choose>

   Scenario 2:
    <!--Weight is available but negative value-->
    <c:set var="weight" value="-6">
    <c:choose>
        <c:when test="${weight == null}">
             Weight is not provided for this product.
        </c:when>
        <c:when test="${weight <= 0}">
             Incorrect weight. It can not be zero or negative.
        </c:when>
        <c:otherwise>
             Weight of the product is <c:out value="${weight}"/> lbs.
        <c:otherwise/>
    </c:choose>

   Scenario 3:
    <!--Weight is available but zero value-->
    <c:set var="weight" value="0">
    <c:choose>
        <c:when test="${weight == null}">
             Weight is not provided for this product.
        </c:when>
        <c:when test="${weight <= 0}">
             Incorrect weight. It can not be zero or negative.
        </c:when>
        <c:otherwise>
             Weight of the product is <c:out value="${weight}"/> lbs.
        <c:otherwise/>
    </c:choose>

  Scenario 4:
    <!--Weight is available and it is 10 lbs.-->
    <c:set var="weight" value="10">
    <c:choose>
        <c:when test="${weight == null}">
             Weight is not provided for this product.
</c:when>
        <c:when test="${weight <= 0}">
             Incorrect weight. It can not be zero or negative.
        </c:when>
        <c:otherwise>
             Weight of the product is <c:out value="${weight}"/> lbs.
        <c:otherwise/>
    </c:choose>
    
</body> 
</html>


Output: 
Scenario 1:Weight is not provided for this product.
Scenario 2:Incorrect weight. It can not be negative..
Scenario 3:Incorrect weight. It can not be zero.
Scenario 4:Weight of the product is 4.53592 kgs.
Make sure that there is no condition evaluation in <c:choose> block. This is enclosing tag for <c:when> and <c:otherwise> blocks.
<c:when> tag has condition evaluation capability and you can have multiple <c:when> blocks within single <c:choose> block. Each condition can be evaluated using test attribute of this statement.
<c:otherwise> block do not have any condition evaluation capabiity. It represents all conditions which are not covered by <c:when> statements. <c:otherwise> statement must be present in <c:choose> block.

JSTL Choose When Otherwise Tag

These tags are used as a conditional statement in JSP. 

For Example,
 <c:choose>
          <c:when test="${weight > 0}">
              <c:out value="${weight}"/>
          </c:when>
          <c:otherwise>
              <c:out value="0"/>
          <c:otherwise/>
      </c:choose>

As you can see above, <c:choose>-<c:when>-<c:otherwise> tags JSP are similar to if-elesif-else blocks in JAVA. When you have multiple conditions and each of them produces different output, you can use <c:choose>-<c:when>-<c:otherwise>.
Make sure that there is no codition eveluation in <c:choose> block. This is enclosing tag for <c:when> and <c:otherwise> blocks.
<c:when> tag has condition evaluation capability and you can have multiple <c:when> blocks within single <c:choose> block. Each condition can be evaluated using test attribute of this statement.
<c:otherwise> block do not have any condition evaluation capabiity. It represents all conditions which are not covered by <c:when> statements. <c:otherwise> statement must be present in <c:choose> block.
JSTL Catch TagJSTL catch tag is used to catch the exception thrown at run time in JSP.

<c:catch var="exception">

    <c:out value="${firstNumber/ secondNumber}"/> 

  </c:catch>

  <c:if test="${exception != null}">

    Exception thrown is <c:out value="${exception}"/> 

  </c:if>

As you can see above, we are trying to display result of dividing firstNumber with secondNumber. It may be possible that secondNumber is 0. In that event, exception will be thrown at run time. <c:catch> block will handle this exception and print the exception in the next <c:if> block.

JSTL Remove Tag

Remove tag is being used in JSP to remove the variable from the scope.

 <c:set var="price" value="10.0" scope="session">
    <c:out value="${price}"/>
    <c:remove var="price">
    <c:out value="${price}"/>
As you can see above, <c:set> tag creates a new variable price with value of 10.0 and having scope for the current session. When tag <c:out> is used to print the value, first time it will print 10.0
In line 3, <c:remove> tag is removing the variable price from the session scope. In line 4, when <c:out> tag is printing value of variable price, it will not print anything as it is removed in line 2.

C:Import
JSTL Import tag is being used in JSP to include the content of other resource in the current JSP.

<c:import url="http://www.apekshit.com" var="tutorial" />
 <c:out value="${tutorial}"/> 

As you can see above, <c:import> tag imports the content of another resource specified in url attribute to the current JSP. It store the content to variable tutorial and prints it using <c:out> tag in the next line.
The <c:import> tag is similar to import action in JSP. However, <c:import> can import resouces from other applications also by providing absolute path to it.

<c:forTokens

  <c:forTokens delims=" {,}" items="{25,50,75,100}" var="number">
    <c:out value="${number}" default="25"></c:out>
  </c:forTokens>

Required Attributes:
      1. items:This attribute provides string of tokens to iterate over..
       2. delims: This attribute provides the set of delimiters. The characters that separate the tokens in the string.
Optional Attributes:
       1. var: This attribute provides name of the exported scoped variable for the current item of the iteration. This scoped variable has nested visiblity. Its type depends on the object of the underlying collection.
       2. varStatus: This attribute provides name of the exported scoped variable for the status of the iteration. Object exported is of type javax.servlet.jsp.jstl.core.LoopTagStatus. This scoped variable has nested visibility.
       3. begin: If items specified: Iteration begins at the item located at the specified index. First item of the collection has index 0. If items not specified: Iteration begins with index set at the value specified.
      4. end: If items specified: Iteration ends at the item located at the specified index (inclusive). If items not specified: Iteration ends when index reaches the value specified.
     5. step: Iteration will only process every step items of the collection, starting with the first one.

Handling Mongodb exception



<pre name="code" class="java">


I  am geting the server status(running or stoped) of mongodb.While stoping the server  i am getting the  MongoTimeoutException  i was handled that exception in catch block.

catch(MongoTimeoutException)
{
model = new ModelAndView("databaseStatus","status","STOPED");
}
 or 

catch(Exception e)
{
model = new ModelAndView("databaseStatus","status","STOPED");
}


complete controller code

@RequestMapping(value ="/databaseStatus",  method = RequestMethod.GET)
public ModelAndView dbServerStatus(HttpServletRequest request) throws UnknownHostException {
ModelAndView model =null;
try
{
log.info("database running");
Mongo mongo = new Mongo("localhost", 27017);
DB db = mongo.getDB("test");
CommandResult status= db.command("ServerStatus") ;
model = new ModelAndView("databaseStatus","status","RUNNING");
}
catch(Exception e)
{
model = new ModelAndView("databaseStatus","status","STOPED");
}
return model;
}
</pre>

Wednesday, June 3, 2015

Restful web service with get and post using jersey2 api in Json fromat

Get Request:
http://locahost:8080/rest/admin/helloworld?value=hai

Post Request with json body:

{
"parameter":"anyparameter",
"message":"any message"
}

Url

http://locahost:8080/rest/admin/

web.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<web-app 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_3_0.xsd"
      version="3.0"> 
    <display-name>Hooper Platform RESTful Services</display-name>
    <servlet>
        <servlet-name>rest</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
          <param-name>javax.ws.rs.Application</param-name>
          <param-value>com.hps.resources.MyApplication</param-value>
        </init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>

    <servlet-mapping>
        <servlet-name>rest</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app> 

Resource class

package com.hps.resources;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.hps.model.HelloRequest;
import com.hps.model.HelloResponse;

@Path("/admin")
public class MessageResource {
@GET
@Path("{parameter}")
public Response responseMsg( @PathParam("parameter") String parameter,
@DefaultValue("Nothing to say") @QueryParam("value") String value) {
String output = "Hello from: " + parameter + " : " + value;
return Response.status(200).entity(output).build();

}
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response produceJson(HelloRequest helloRequest) {
String output = "Hello from: " + helloRequest.getParameter() + " : " +helloRequest.getMessage();
HelloResponse reponse = new HelloResponse(output);
reponse.setStatus(Response.Status.CREATED.getStatusCode());

return Response.status(200).entity(reponse).build();
}

}


Json convertion java file


package com.hps.resources;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import org.glassfish.jersey.filter.LoggingFilter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;

@ApplicationPath("/")
public class MyApplication extends Application {

@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(MessageResource.class);
return classes;
}

@Override
public Set<Object> getSingletons() {
final Set<Object> instances = new HashSet<Object>();
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
instances.add(new JacksonJsonProvider(mapper));
instances.add(new LoggingFilter());
return instances;
}
}

HelloRequest

package com.hps.model;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class HelloRequest {
private String message;
private String parameter;

public String getParameter() {
return parameter;
}

public void setParameter(String parameter) {
this.parameter = parameter;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {

return "HelloRequest[parameter=" + parameter + ", message=" + message + "]";

}

}

HelloResponse.java


package com.hps.model;
public class HelloResponse {
private String message;
private int status;

public HelloResponse(String message){
this.message = message;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public int getStatus() {
return status;
}

public void setStatus(int status) {
this.status = status;
}

}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>

<groupId>jersey2-sample</groupId>
<artifactId>jersey2-sample</artifactId>
<version>1.0</version>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<connection>scm:git:git@github.com:aruld/jersey2-sample.git</connection>
<developerConnection>scm:git:git@github.com:aruld/jersey2-sample.git</developerConnection>
<url>git@github.com:aruld/jersey2-sample.git</url>
</scm>

<developers>
<developer>
<id>aruld</id>
<name>Arul Dhesiaseelan</name>
<email>aruld@acm.org</email>
</developer>
</developers>

<properties>
<jersey2.version>2.0-m12</jersey2.version>
<jaxrs.version>2.0-m15</jaxrs.version>
</properties>

<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.5</version>
</dependency>
<!-- For file upload -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
<version>${jersey2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.2.2</version>
</dependency>

<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-bundle</artifactId>
<version>${jersey2.version}</version>
<type>pom</type>
<scope>test</scope>
</dependency>

</dependencies>


<build>
<finalName>cluster</finalName>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>8080</port>
<path>/</path>
<useTestClasspath>false</useTestClasspath>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>

</project>


Tuesday, June 2, 2015

code to get progress bar in UI Pages


Standard code
<progress id="determinateProgressBar" value="30" max="100"></progress>

JavaScript(optional)
var progressBar = document.getElementById("determinateProgressBar");
progressBar.value = value;

Example to get memory status bar:

<progress id="determinateProgressBar" value="<%= request.getAttribute("memoryUsed")%>" max="100">