Maintain your daily Logs with Notepad

Do you wish to keep notes where the notes keep the date automatically? Well here is an awesome trick for you. All you need is notepad.


1) Open a blank notepad file.
2) Type .LOG in all caps at the top and hit enter.
3) Now save the file.
4) After closing the file, reopen it and notice that the date & time is now listed on the second line.
5) Also notice that the cursor is ready for you to start typing on the very next line.
6) Now every time you open it, type something on the next line and then save it, when you reopen it, it will have automatically saved the date and time on the last line.

It keeps a running record of date and time for each save. Now you have a cheap diary! Congrats!

source:centralbeat
Wednesday, August 31, 2011
Posted by Unknown

Sphinx Search Code is available for download...

Hi Today I got an email from roger.xia from China regarding the Sphinx search article i posted few months back, he requested the source code so I uploaded the same on dzone, Any one who is interested in trying Sphinx free text search code can download it from dzone site.


URL - http://java.dzone.com/articles/using-sphinx-and-java






---------------------------------------
Hi , Munish Gogna

I come from china , and i read your article about Sphinx, it was very useful for me, but i can't find the sample source code, can you send me a copy of the sample complete source code to me?
thank u very much !

best wishes.
roger.xia
20110822
---------------------------------------

Monday, August 22, 2011
Posted by Unknown

Task Scheduling in JBoss Server ...

First thing I would like to admit is - Sorry for being away for so long !!!
Next let's quickly move to second thing which is the topic of today's very simple post - scheduling jobs in JBoss :)

In many projects there is a requirement for cron-like task scheduling, be it for batch processing, automatic system maintenance or some other regular job. Few days back I had to create a cron job to sync data from external source to the local database. I was having so many options to implement the functionality like:
  • java.util.Timer
  • EJB Timers
  • Unix Cron jobs
  • Quartz Scheduler
  • Custom Timer
But in the end I settled for a very simple solution (in terms of time it took to implement the whole stuff) that is as effective as anything mentioned above.

org.jboss.varia.scheduler.Scheduler
----------------------------------------
The good thing is, this Scheduler directly invokes a callback on an instance of a user defined class, or an operation of a user specified MBean. Let's say we want to print 'Hello World!' (our so called task) after every 30 seconds from the the time of deployment.
package com.gognamunish.test;
import org.jboss.varia.scheduler.Schedulable;
/**
* Implement Schedulable interface and override perform() function. 
* @author Munish Gogna
*/
public class HelloWorld implements Schedulable
{
    public void perform( Date now, long remainingRepetitions ) {
        System.out.println("Hello World");
    }
}
Next just copy the following mbean definition in /deploy/scheduler-service.xml file of the Jboss profile.

      true
      com.gognamunish.test.HelloWorld
      0
      30000
      -1
      true    

      
   
Once the deployment is done, this task will be called after every 30 seconds, so easy and simple right? We can also pass input parameters to our target class using 'SchedulableArguments' attribute, just make sure you define the right constructor in the class that implements Schedulable interface. e.g If we want to pass the location and environment of the server, we have to add following lines to the mbean definition:
Singapore,Test
 java.lang.String,java.lang.String

HelloWorld class now has to define a constructor as follow:
public HelloWorld (String location, String environment){
 this.location=location;
 this.environment=environment;
}


Note: This example has dependency on scheduler-plugin.jar which can be obtained from /common/lib folder of $JBOSS_HOME (it is sad that it's not available in maven or jboss repository)

Give it a Try !!!!
Sunday, August 7, 2011
Posted by Unknown

Google+ wishlist..



This is what I would like to have in next release of Google+:
1. Robust developer API (Many users get hooked on games like Farmville, and that would not have been possible without the application platform Facebook provides).
2. 'Import Facebook contacts' functionality (otherwise killing Facebook will take years of user attrition)
3. Integration with other Google offerings like Docs so that I can share selected documents with my circles, Latitude integration etc.
4. Less white space in UI (some how Facebook screens look more elegant and eye catching to me)
5. Seamless integration with popular apps like Twitter at least.

I hope that these features except the second one should be ready by end of this Year and then I would definitely think of giving Google+ a Thumbs up !!!

cheers,
Munish Gogna
Sunday, July 3, 2011
Posted by Unknown

Handling alien Java types in XML messages

Most of times we find ourself in situations where the XML instance doesn't fully comply with the available Java types.

Let's define a near real world problem to understand this.

Problem: Need to process XML message coming from some XYZ source we don't have control on( the message format is shown below). As can be seen dob element has value as date of birth for Nikhil but is surrounded by brackets [ and ]. Now if we want to unmarshal this message to Person object than with this limitation we will have to declare dob as String and then provide some more methods to parse date every time we process this XML message.

So what should we do - declare dob as String?


Nikhil
[1986-08-27]


Answer is NO, we can use adapters, how? be patient ..

Let's first define our domain object
// members are public just to keep it short..
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Person {

 @XmlElement
 public String name;

 @XmlElement
 @XmlJavaTypeAdapter(DateAdapter.class)
 public Date dob;

}
As can be seen above we have declared dob as of type Date only, but how it can be populated with the kind of values we are getting, you got it - yes it is our DateAdapter class who is going to manage this, let's see how:
/**
  * Our custom dob adapter.
  */
 class DateAdapter extends XmlAdapter<String, Date> {
  
  static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

  public DateAdapter() {
  }

  @Override
  public String marshal(Date date) throws Exception {
   // while sending message back to the source we will obey its format
   return "[" + format.format(date) + "]";
  }

  @Override
  public Date unmarshal(String dob) throws Exception {
   // remove unwanted characters and build date
   dob = dob.replace("[", "").replace("]", "");
   return format.parse(dob);
  }

 }

Let's unmarshal the message now:

JAXBContext context = JAXBContext.newInstance(Person.class);
  Unmarshaller unmarshal = context.createUnmarshaller();
// employee file is the source of message in this example
  Person person = (Person) unmarshal.unmarshal(new File("employee"));

  Assert.assertEquals("Nikhil", person.name);
  Assert.assertEquals("Wed Aug 27 00:00:00 SGT 1986", person.dob
    .toString());


and marshalling our new Person object works fine too :)

Person person = new Person();
  person.name="Toshi";
  person.dob= format.parse("2010-10-10");
  
  Marshaller marshaller = context.createMarshaller();
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
  marshaller.marshal(person, System.out);
// The console output is shown below:

  
      Toshi
      [2010-10-10]
  
This is exactly what we expect, value of dob within brackets. This was just a simple example to demonstrate the power of adapters for handling alien types in Java XML world. Hope you can also use this approach in some of your Projects.

See you later !!!
Saturday, May 14, 2011
Posted by Unknown

Converting JSF <h:dataTable/> to <annaRascla:RajniKant/> table ...



By RajniKant table I mean a readonly table that has all the features (sorting, pagination, searching etc). Most developers who are struck with JSF RI implementation know already how difficult it is to provide all these mentioned features. Suddenly you think of moving to PrimeFaces, RichFaces, BlaBlaFaces etc. but hey stop a while I have something special for you in today's post.

In the next section I will try to convert one simple <h:datatable> to <annaRascla:RajniKant> table as per the description of Rajnikant table.

Let's assume we have an existing JSF data table as shown below and suddenly there is a requirement to provide pagination and sorting capabilities.


   

The table looks exactly same as shown below:

Nothing fancy :(, lets move to make it live.

We will use DataTables plug-in for the jQuery Javascript library to make it happen.

  
  
  
  
 
 
  
   
Points to note
  • The tags htmlhead and htmlbody shown above correspond to usual HEAD and BODY tags of html language (Blogger doesn't allow these tags)
  • The reason for not using table id (form:mytable) in ready(function) is that Datatables plugin doesn't accept id of the table having colon in the name itself :( and we all know that JSF generates Ids like this, so how I provide the id of my table? Simple provide the unique class name of that element :)
  • Use this approach if the table is not very large, for large tables you can use ajax capabilities of the plugin, check Project's home page for more details.
  • All the resources above (css and js) come from the artifacts we downloaded earlier
Having made these changes, let's see how our simple table looks now:


The only word that come to my mind is WOW, as can be seen it has:

> Sorting feature
> Pagination feature
> Search feature
> Simple and clean design

Thanks everyone.
Posted by Unknown

Building RESTful WS with JAX-RS (Jersey) and Tomcat

This post is dedicated to my friend jagdish salgotra who wanted me to write something on RESTful web services and to all starters in this area.

In the REST(REpresentational State Transfer) world, information on the server side is considered a resource, which anyone can access in a uniform way using web URIs (Uniform Resource Identifiers) and HTTP. Because REST uses HTTP as the communication protocol, the REST style is constrained to a stateless client/server architecture. We can map the HTTP methods POST, GET, PUT, and DELETE to create, read, update and delete (CRUD) operations.

There are many ways to write RESTful web services:
> Sun offers a reference implementation for JAX-RS code-named Jersey.
> Spring provides RestTemplate for the same purpose

In this sample example (very basic and naive just to give u all a gentle kick) I will try to explain how we can use DEPARTMENT as representational state in REST using GET method. We will try to map following urls to the particular state we are interested in using Jersey implementation.

/api/departments/Get all departments
/api/departments/{id}Get details of a particular department
/api/departments/employeesGet all departments with employee details
/api/departments/{id}/employeesGet employees of particular department

NOTE: All employees related data will be available under department node (by design)

The output of the Restful web services can be a plain text, html, xml, json or any media type, For our example We will use XML as content type of our service output and will rely on JAXB annotations to provide the required marshaling/unmarshaling services.

Let's start with the root XML element. I chose to call mine GetDepartmentResponse, and use it as a container for a collection of Department objects. This is just to do with the convention I usually follow (no hard fast rules behind this).
package com.mg.rest.hr.resources;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class GetDepartmentResponse {

 private List<Department> departments;

 @XmlElement(name = "department")
@XmlElementWrapper(name = "departments")
 public List<Department> getAllDepartments() {
  if (departments == null) {
   departments = new ArrayList<Department>();
  }
  return departments;
 }

}

Notice the @XmlElementWrapper annotation on the Department collection. This makes JAXB wrap all of the department XML elements inside of an departments XML element. Also notice that I placed the @XmlElement annotations on the getter methods instead of on the private fields. When placed on the private fields, JAXB will give you an error unless you add @XmlAccessorType(XmlAccessType.FIELD) at the class level.

Next we define our Resources - Department and Employee

package com.mg.rest.hr.resources;

import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlType;

/**
 * 
 * @author Munish Gogna
 *
 */
@XmlType(name = "department")
public class Department {

 private String deptId;
 private String deptName;
 private List<Employee> employees;

 public Department() {
 }

 @XmlElement
 public String getDeptId() {
  return deptId;
 }

 @XmlElement(name = "employee")
 @XmlElementWrapper(name = "employees")
 public List<Employee> getEmployees() {
  return employees;
 }

 @XmlElement
 public String getDeptName() {
  return deptName;
 }

 public void setDeptId(String deptId) {
  this.deptId = deptId;
 }

 public void setEmployees(List<Employee> employees) {
  this.employees = employees;
 }

 public void setDeptName(String deptName) {
  this.deptName = deptName;
 }

}

In the example above, we use @XmlType at the class level instead of @XmlRootElement because it is not the root element

package com.mg.rest.hr.resources;

import java.math.BigDecimal;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;

/**
 * 
 * @author Munish Gogna
 * 
 */
@XmlType(propOrder = { "empId", "empName", "salary" })
public class Employee {

 private String empId;
 private String empName;
 private BigDecimal salary;

 public Employee() {
 }

 public Employee(String empId, String empName, BigDecimal salary) {
  super();
  this.empId = empId;
  this.empName = empName;
  this.salary = salary;
 }

 @XmlElement
 public BigDecimal getSalary() {
  return salary;
 }

 @XmlElement
 public String getEmpId() {
  return empId;
 }

 @XmlElement
 public String getEmpName() {
  return empName;
 }

 public void setEmpId(String empId) {
  this.empId = empId;
 }

 public void setEmpName(String empName) {
  this.empName = empName;
 }

 public void setSalary(BigDecimal salary) {
  this.salary = salary;
 }

}


Now lets create a JAX-RS RESTful web service that can return above defined object graph in the responses we have defined in the beginning of this article.

JAX-RS defines a resource as any Java class (POJO) that uses JAX-RS annotations to implement a web resource. The annotation @Path identifies a Java class as a resource class as shown below.

package com.mg.rest.hr;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.mg.rest.hr.resources.Department;
import com.mg.rest.hr.resources.GetDepartmentResponse;

/**
 * Service to handle Department and related resources.
 * Just a mock implementation, nothing fancy.
 * @author Munish Gogna
 *
 */
@Path("/api")
public class DepartmentResource {

 @GET
 @Produces("text/xml")
 @Path("/departments/employees")
 public GetDepartmentResponse getAllDepartmentsWithEmployees() {
  GetDepartmentResponse response = new GetDepartmentResponse();
  response.getAllDepartments().addAll(
    FromHeaven.getDeptsWithEmps().values());
  return response;
 }

 @GET
 @Produces("text/xml")
 @Path("/departments/{id}")
 public GetDepartmentResponse getDepartment(@PathParam("id") String id) {
  GetDepartmentResponse response = new GetDepartmentResponse();
  Department dept = FromHeaven.getDepts().get(id);
  response.getAllDepartments().add(dept);
  return response;
 }

 @GET
 @Produces("text/xml")
 @Path("/departments/{id}/employees")
 public GetDepartmentResponse getEmployeesForDepartment(
   @PathParam("id") String id) {
  GetDepartmentResponse response = new GetDepartmentResponse();
  Department dept = FromHeaven.getDeptsWithEmps().get(id);
  response.getAllDepartments().add(dept);
  return response;

 }

 @GET
 @Produces("text/xml")
 @Path("/departments")
 public GetDepartmentResponse getAllDepartments() {
  GetDepartmentResponse response = new GetDepartmentResponse();
  response.getAllDepartments().addAll(FromHeaven.getDepts().values());
  return response;

 }
}


Notice the @Produces("text/xml") annotation, and that the method returns a GetDepartmentResponse object. Since the GetDepartmentResponse is annotated with JAXB annotations, JAX-RS will automatically marshal the response to XML.
Also note that FromHeaven is a utility class that provides dummy departmental data(This class has 2 hard coded departments D1 and D2 with 2 employees in D1 and only single employee in D2)

Let's try some URIs now:

1. http://localhost:8080/rest/api/departments

 
  
   D2
   Human Resource
  
  
   D1
   Finance
  
 


2. http://localhost:8080/rest/api/departments/D1

 
  
   D1
   Finance
  
 


3. http://localhost:8080/rest/api/departments/employees

 
  
   D1
   Finance
   
    
     e1
     Munish Gogna
     1000
    
    
     e2
     Jagdish Salgotra
     2000
    
   
  
  
   D2
   Human Resource
   
    
     e3
     Sahil Gogna
     5000
    
   
  
 


4.http://localhost:8080/rest/api/departments/D1/employees

 
  
   D1
   Finance
   
    
     e1
     Munish Gogna
     1000
    
    
     e2
     Jagdish Salgotra
     2000
    
   
  
 


In order for Jersey to work, we need to configure the JAX-RS Servlet in the web.xml as shown below:


 
  com.mg.rest.hr
  JAX-RS REST Servlet
  com.sun.jersey.spi.container.servlet.ServletContainer
  
   com.sun.jersey.config.property.packagescom.mg.rest.hr
  1
 
 
  JAX-RS REST Servlet
  /*
 


Notice that we have to provide the package name (com.mg.rest.hr) of the resource handler classes to the servlet class.

That's all for now, later some day we will try make these RESTful services secure so that only authorized callers can use these resources.

Please don't forget to provide your valuable feedback, especially you Jagi :)
Sunday, May 8, 2011
Posted by Unknown

Saving ENUM values as String in database using JPA

First of all nothing very fancy or technical about this post :)

Let's say you have an enum declaration as shown below and you want to store these values as String (not the evil ordinals) in the database:

public enum UserSex {
 MALE, FEMALE, UNKNOWN
}

To save this enum as String in database, the table where this enum is referenced should declare a column of type varchar as shown below:
`user_sex` varchar(255) DEFAULT NULL

The entity (say User) should use this enumeration as shown below:

@Entity
@Table(name = "user")
public class User {

private Integer id;
private UserSex userSex;

@Id
public Integer getId() {
 return id;
}

@Enumerated(EnumType.STRING)
 @Column(name ="user_sex")
 public UserSex getUserSex() {
  return userSex;
 }

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

 public void setUserSex(UserSex userSex) {
  this.userSex = userSex;
 }

That's all. Now if you want to load all MALE users, you can use this column in JPA queries as

public List<User> getAllMaleUsers() {
  return entityManager.createQuery(
    "select user from User as user where user.userSex=:userSex")
    .setParameter("userSex", UserSex.MALE).getResultList();
 }

Please note that this will work only in case you have complete control on the database side, in case the column is declared as integer or varchar having length say 1 then you will have to write your own converter or fall back to evil ordinal().

NOTE: I'm guessing but I'm pretty sure that for using ENUM as String hibernate 3.2+ is required. So if anyone out there is interested in knowing my POM dependencies then here are they (specific to JBOSS AS 5.1.0 deployment)


   
javaee
   javaee-api
   5
   compile
  
  

   javax.persistence
   ejb3-persistence
   1.0
   provided
  
  
   org.hibernate
   hibernate-entitymanager
   3.3.1.ga
   
    
     javax.persistence
     persistence-api
    
    
     jboss
     jboss-common-core
    
    
     jboss
     javassist
    
   
  
Sunday, May 1, 2011
Posted by Unknown
Tag : ,

Ready made Template for J2EE project (EJB+JPA+Hibernte+Richfaces) deployed on Jboss AS 5.1.0.GA


This project will serve as a ready made template for all who want to use EJB3, JPA, Hibernate and JSF (Richfaces) in their project deployed over JBoss AS 5+ version.
Who Can use this template?
  • All who want to use above technology stack for the very first time in their new Project.
  • All who want to migrate to JBoss AS from glassfish or tomcat or any other server.
  • All new comers to Java for learning purpose so that they can make maximum out of it.
For more details checkout http://code.google.com/p/template4all/
Sunday, April 17, 2011
Posted by Unknown

Thanking Anna Hazare through JBOSS e-mail Service...

Hi everyone, First of all thanks to Anna Hazare and all who have really fought for lokpal bill.

Today's article is about sending Thanks email to Anna Hazare for his tremendous dedication towards our great nation, it's about setting up SMTP server to send emails from your application hosted on JBOSS Application server.


The focus will be on the Anna Hazare and Jboss setup rather than providing a full fledged Email Service.


Our application will be sending emails over gmail SMTP server.
Please pay attention to comments from now onwards through out this article. :)

Maven dependency : Here is a skelton of our maven project.

 4.0.0
 com.mg.poc.email
 JbossMail
 0.0.1-SNAPSHOT
 ejb
 A Simple project to send Emails using Gmail (service running in JBOSS) 

 
  
   Munish Gogna
   gognamunish@gmail.com
   www.twitter.com\munishgogna
  
 

 
 
  
   javaee
   javaee-api
   5
   provided
  

 
 

  ${basedir}/src
  
   
    ${basedir}/src
    
     **/*.java
    
   
  
  
   
    org.apache.maven.plugins
    maven-ejb-plugin
    
     3.0
    
   
   
    maven-compiler-plugin
    
     1.5
     1.5
    
   
  
 




STEP 1 Define our Gmail based SMTP mail service that we will use in our sample application.

SERVER\deploy\mail-service.xml : Create the service definition as shown below:



  
  
  

  
    java:/GMail
    gognamunish@gmail.com
    
    XXXXXX
    
      
       
            
            
      
      
      
            
            
         
    
    jboss:service=Naming
  

After placing this file in deploy folder, you should see following logs in server.log
15:40:49,985 INFO [MailService] Mail Service bound to java:/GMail

STEP 2 Let's build our sample EJB based application that will consume this service to send emails, time to define our remote interface.

package com.mg.poc.email;

import javax.ejb.Remote;

/**
 * Simple interface for our Mail Service.
 * 
 * @author Munish Gogna
 * 
 */
@Remote
public interface MailSender {

 /**
  * Sends mail using GMAIL Service.
  * 
  * @param envelope
  *            envelope to send
  */
 void sendMail(MailEnvelope envelope) throws GmailException;

}

The Envelope class is a simple class that holds regular stuff we need to send email. It is defined as :

package com.mg.poc.email;

import java.io.Serializable;

/**
 * Contains regular email stuff (with some defaults).
 * 
 * @author Munish Gogna
 *
 */
public class MailEnvelope implements Serializable {

 private static final long serialVersionUID = 1L;
    
 private String subject ="thanks Anna Hazare";
 private String to;
 private String from ="gognamunish@gmail.com";
 private String body ="Anna you are great. We the people of india have won the 1st step against the Govt. & feeling real freedom only Bcoz of you. - love you !!!!";

 /** setters/getters omitted */

}
Now as we have defined the interface for our Email Service, let's provide the implementation of the same.
package com.mg.poc.email;

import javax.annotation.Resource;
import javax.ejb.Stateless;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message.RecipientType;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 * Bean to manage simple email functionality.
 * 
 * @author Munish Gogna
 * 
 */
@Stateless
public class MailService implements MailSender {

 /**
  * This resource is defined in mail-service.xml file.
  */
 @Resource(mappedName = "java:/GMail", description = "jndi mapping for our simple mail service")
 Session mailSession;

 public void sendMail(MailEnvelope envelope) throws GmailException {
  
  if(envelope == null){
   throw new GmailException("envelope is null");
  }
  
  Message simpleMessage = new MimeMessage(mailSession);

  try {
   simpleMessage.setFrom(createInternetAddress(envelope.getFrom()));
   simpleMessage.setRecipient(RecipientType.TO, createInternetAddress(envelope.getTo()));
   simpleMessage.setSubject(envelope.getSubject());
   simpleMessage.setText(envelope.getBody());

   Transport.send(simpleMessage);
  } catch (MessagingException e) {
   throw new GmailException(e.getMessage());
  }

 }

 private Address createInternetAddress(String address) throws GmailException {
  try {
   return new InternetAddress(address);
  }catch (AddressException e) {
   throw new GmailException(e.getMessage());
  }
 }

}

That's all we are done.
> Generate jar - mvn clean install
> copy JbossMail-0.0.1-SNAPSHOT.jar to deploy folder.
> server logs should show binding of our EJB Stateless session beans as shown below:

15:41:33,403 INFO [EJBContainer] STARTED EJB: com.mg.poc.email.MailService ejbName: MailService
15:41:33,412 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

MailService/remote - EJB3.x Default Remote Business Interface


Finally we will test the service to make sure it actually sends email.

package com.mg.poc.email.test;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

import com.mg.poc.email.MailEnvelope;
import com.mg.poc.email.MailSender;

/**
 * Simple Test.
 * 
 * @author Munish Gogna
 * 
 */
public class TestMail {

 public static void main(String[] args) throws Exception {
  Properties properties = new Properties();

  properties.put("java.naming.factory.initial",
    "org.jnp.interfaces.NamingContextFactory");
  properties.put("java.naming.factory.url.pkgs",
    "org.jboss.naming:org.jnp.interfaces");
  properties.put("java.naming.provider.url", "localhost");
  Context context;
  try {
   context = new InitialContext(properties);
   MailSender beanRemote = (MailSender) context
     .lookup("java:MailService/remote");

   MailEnvelope envelope = new MailEnvelope();
   envelope.setTo("anna.hazare@gmail.com");

   beanRemote.sendMail(envelope);
   System.out.println("mail sent successfully !!!");
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}
Note : In case you want to run this client, make sure you add all the required client libraries in the classpath, do one thing add all jars in JBOSS_HOME/client folder to classpath OR try adding following dependency in the pom file.


jboss
jbossall-client
${jboss.version}
${jboss.home}/client/jbossall-client.jar
system

Creating client jars and managing dependencies\jndi lookups can be nightmare sometimes, not some times but most of the times, please do share your thoughts on the same.

To end discussion on this topic I would once again like to thank everyone who stood with Hazare to fight against corruption.

Thanks.
Saturday, April 9, 2011
Posted by Unknown

Popular Post

Labels

JAX-RS (1) JPA (1) RESTful (1) enums (1) java (2) mysql (1) request 2 (1) sphinx (1) tomcat (1) web service (2) ws (2)