Sunday, May 4, 2014

SpringMailService Utility Class

// This class contains  overloaded methods and has demonstrated all the features of spring mail inclusing velocity integration.
package com.packt.mailservice;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailException;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.javamail.MimeMessagePreparator;
import javax.mail.Message;
import java.util.Map;
import java.util.HashMap;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class MailSenderService {
@Autowired
private VelocityEngine velocityEngine;
@Autowired
private MailSender mailSender;
@Autowired
private JavaMailSender javaMailSender;
@Autowired
private SimpleMailMessage configured_message;
public void sendmail(String from, String to, String subject, String body) throws MailException{
SimpleMailMessage message=new SimpleMailMessage();
message.setFrom(from);
message.setSubject(subject);
message.setText(body);
mailSender.send(message);
}
public void sendmail(String from, String []to, String subject, String body) throws MailException{
SimpleMailMessage message=new SimpleMailMessage();
message.setFrom(from);
message.setTo(to);
message.setSubject(subject);
message.setText(body);
mailSender.send(message);
}
public void sendmime_mail(final String from, final String to, final String subject, final String body) throws MailException{
MimeMessagePreparator message = new MimeMessagePreparator() {
               public void prepare(MimeMessage mimeMessage) throws Exception {
              message.setRecipient(Message.RecipientType.TO,new InternetAddress(to));
              message.setFrom(new InternetAddress(from));
              message.setSubject(subject);
              message.setText(msg);
            }

public void prepare(MimeMessage arg0) throws Exception {
// TODO Auto-generated method stub

}

    };
    mailSender.send(message);
}
public void sendmail(String from, String []to, String subject, String body,FileSystemResource file,String filename) throws MailException{
       MimeMessage mimemessage = mailSender.createMimeMessage();
       MimeMessageHelper mimemessagehelper = new MimeMessageHelper(message, true);
       mimemessagehelper.setFrom(from);
       mimemessagehelper.setTo(to);
       mimemessagehelper.setSubject(subject);
       mimemessagehelper.setText(msg);
       mimemessagehelper.addAttachment(filename, file);//image will be sent by this name
       mailSender.send(message);
     
}
public void sendmail(String message) throws MailException{
SimpleMailMessage message=new SimpleMailMessage(configured_message);
        mailSender.send(message);
     
}
public void sendmail(final Customer customer){
MimeMessagePreparator preparator = new MimeMessagePreparator() {
     public void prepare(MimeMessage mimeMessage)
          throws Exception {
       MimeMessageHelper message =
                             new MimeMessageHelper(mimeMessage);
       message.setTo(user.getEmailAddress());
           message.setFrom("webmaster@csonth.gov.uk"); // could be parameterized...
           Map model = new HashMap();
           model.put("customer", customer);
           String text = VelocityEngineUtils.mergeTemplateIntoString(
              velocityEngine, "com/packt/velocity/templates/orderconfirmation.vm", model);
           message.setText(text, true);
        }
     };
     this.mailSender.send(preparator);
  }
}

Tuesday, July 2, 2013

Multilevel Inheritance in java with public variables and parameterized Constructor

This is a demonstration of Multi-level inheritance in java using parameterised constructor
package com.inheritance;

public class Class1 {
public int a;
public int b;
public Class1(int a, int b) {
super();
this.a = a;
this.b = b;
System.out.println("I am super class called first--->"+(a+b));
System.out.println(a+b);
}
}
---------------------------------------------
package com.inheritance;
public class Class2 extends Class1 {
public int c;
public Class2(int a, int b, int c) {
super(a, b);
this.c=c;
System.out.println("I am the second level subclass--->" +a%c);
}

}
--------------------------------------------------------------
package com.inheritance;

public class Class3 extends Class2 {
public int d;
public Class3(int a, int b,int c, int d) {
super(a, b, c);
this.d=d;
System.out.println("I am thrid level subclass extends second level class-->"+a*b*c*d);
// TODO Auto-generated constructor stub
}
public static void main(String args[]){
Class3 class3=new Class3(1, 2, 3, 4);
}
}
--------------------------------------------
output:
I am super class called first--->3
3
I am the second level subclass--->1
I am thrid level subclass extends second level class-->24

Wednesday, June 26, 2013

Can a Class implement two interfaces with the same method signature

I created two interfaces with same method signature.
You can actually implement the method only once.

package com.anjana;
public interface Interface2 {
public String printme();
}
package com.anjana;
public interface Interface1 {
public String printme();
}
package com.anjana;

public class Employee implements Interface1,Interface2,Interface3{
@Override
public String printme() {
return "Hello";
}

public static void main(String args[]){
Interface1 emp1=new Employee();
emp1.printme();
System.out.println(emp1.printme());
Interface2 emp2=new Employee();
System.out.println(emp2.printme());
}
This will be misleading if you have to do some operations based on the returned value.

Thursday, May 30, 2013

Example:Immutable Class

Immutable class is thread safe
Imuutable class objects cannot be modified
Examples :
  • Integer
  • String
package com.demo.immutable;
//make ur class final
public final class MyImmutable {
 //make ur instance variables final
    final String s="Anjana";
    private String s2=null;
//access the private via constructors--to modify
    public MyImmutable(String s2) {
        super();
        this.s2 = s2;
    }
    public static void main(String args[]){
        MyImmutable  myimmutable=new MyImmutable("dff");
    }
}
 

Friday, September 7, 2012

CXF RESTFUL Service - Example jax-rs

CXF frame work  supports restful web services.
It is provided in the following ways:
  1. JAX_RS
  2. JAX_WS ProviderDispatch
  3. HtppBinding
Below is the example of RESTFUL service which gives an xml response.The data is pulled form  the database.I have also integrated  spring-jdbc with cxf.

check the response after running the application at-http://localhost:8086/cxf-jaxrs-poc/myservice/users
Port number can change based on availability.

Lets start with the configurations-cxf.xml:

 <?xml version="1.0" encoding="UTF-8"?>  
 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
   xmlns:jaxrs="http://cxf.apache.org/jaxrs"  
   xsi:schemaLocation="  
 http://www.springframework.org/schema/beans  
 http://www.springframework.org/schema/beans/spring-beans.xsd  
 http://cxf.apache.org/jaxrs  
 http://cxf.apache.org/schemas/jaxrs.xsd"  
   default-lazy-init="false">  
   <jaxrs:server id="myService" address="/">  
     <jaxrs:serviceBeans>  
       <ref bean="serviceImpl" />  
     </jaxrs:serviceBeans>  
     <jaxrs:extensionMappings>  
       <entry key="xml" value="application/xml" />  
     </jaxrs:extensionMappings>  
   </jaxrs:server>  
   <bean id="serviceImpl" class="service.ServiceImpl" />  
   <bean id="MySqlDatasource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">  
     <property name="driverClassName" value="com.mysql.jdbc.Driver"/>  
     <property name="url" value="jdbc:mysql://localhost:3306/emp"/>  
     <property name="username" value="root"/>  
     <property name="password" value="prdc123"/>  
   </bean>  
   <bean id="userDAO" class="dao.UserDAOImpl">  
           <property name="dataSource" ref="MySqlDatasource"/>  
      </bean>  
 </beans>  

web.xml configuration- add cxf servlet-and spring context listners
 <?xml version="1.0" encoding="UTF-8"?>  
 <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">  
   <display-name>cxf-jaxrs-poc</display-name>  
   <description>cxf-jaxrs-poc</description>  
 <!--   <context-param> -->  
 <!--     <param-name>webAppRootKey</param-name> -->  
 <!--     <param-value>cxf.rest.example.root</param-value> -->  
 <!--   </context-param> -->  
   <context-param>  
     <param-name>contextConfigLocation</param-name>  
     <param-value>/WEB-INF/cxf.xml</param-value>  
   </context-param>  
   <listener>  
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
   </listener>  
   <servlet>  
     <servlet-name>CXFServlet</servlet-name>  
     <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>  
     <load-on-startup>1</load-on-startup>  
   </servlet>  
   <servlet-mapping>  
     <servlet-name>CXFServlet</servlet-name>  
     <url-pattern>/*</url-pattern>  
   </servlet-mapping>  
 </web-app> 

Service Defn Interface
 package service;  
 import javax.ws.rs.core.Response;  
 import pojo.User;  
 import pojo.UserCollection;  
 public interface ServiceDefn {  
   public abstract UserCollection getUsers();  
   public abstract User getUser(Integer id);  
   public abstract Response getBadRequest();  
 }  

service impl class-- define restful service path,prepares the data for response
 package service;  
 import java.util.ArrayList;  
 import java.util.HashMap;  
 import java.util.Iterator;  
 import java.util.List;  
 import java.util.Map;  
 import javax.ws.rs.DELETE;  
 import javax.ws.rs.GET;  
 import javax.ws.rs.POST;  
 import javax.ws.rs.PUT;  
 import javax.ws.rs.Path;  
 import javax.ws.rs.PathParam;  
 import javax.ws.rs.Produces;  
 import javax.ws.rs.core.Response;  
 import javax.ws.rs.core.Response.Status;  
 import dao.Manager;  
 import pojo.User;  
 import pojo.UserCollection;  
 @Path("/myservice/")  
 @Produces("application/xml")  
 public class ServiceImpl implements ServiceDefn {  
   private static Map<Integer, User> users = new HashMap<Integer, User>();  
   private static Manager m;  
   Integer currentId = 3;  
   static {  
 //    users.put(1, new User(1, "foo","Manager"));  
 //    users.put(2, new User(2, "bar","SE"));  
 //    users.put(3, new User(3, "baz","CTO"));  
        List l=new ArrayList();       
         m=new Manager();  
         l=m.view();  
        Iterator itr=l.iterator();  
        int i=0;  
        while(itr.hasNext()){  
             users.put(i++, (User) itr.next());  
        }  
   }  
   public ServiceImpl() {  
   }  
   @GET  
   @Path("/users")  
   public UserCollection getUsers() {  
        System.out.println(users.values());  
     return new UserCollection(users.values());  
   }  
   @GET  
   @Path("/user/{id}")  
   public User getUser(@PathParam("id") Integer id) {  
     return users.get(id);  
   }  
   @GET  
   @Path("/users/bad")  
   public Response getBadRequest() {  
     return Response.status(Status.BAD_REQUEST).build();  
   }  
   @PUT  
   @Path("/users/")  
   public Response updateUsers(User user) {  
     System.out.println("----invoking updateCustomer, Customer name is: " + user.getName());  
     User c = users.get(user.getId());  
     Response r;  
     if (c != null) {  
          users.put(user.getId(), user);  
       r = Response.ok().build();  
     } else {  
       r = Response.notModified().build();  
     }  
     return r;  
   }  
   @POST  
   @Path("/users/")  
   public Response addUsers(User user) {  
     System.out.println("----invoking addCustomer, Customer name is: " + user.getName());  
     user.setId(++currentId);  
     users.put(user.getId(), user);  
     return Response.ok(user).build();  
   }  
   @DELETE  
   @Path("/user/{id}/")  
   public Response deleteUser(@PathParam("id") String id) {  
     System.out.println("----invoking deleteCustomer, Customer id is: " + id);  
     Integer idNumber = Integer.parseInt(id);  
     User c = users.get(idNumber);  
     Response r;  
     if (c != null) {  
       r = Response.ok().build();  
       users.remove(idNumber);  
     } else {  
       r = Response.notModified().build();  
     }  
     return r;  
   }  
 }  

Users COllection
 package pojo;  
 import java.util.Collection;  
 import javax.xml.bind.annotation.XmlElement;  
 import javax.xml.bind.annotation.XmlElementWrapper;  
 import javax.xml.bind.annotation.XmlRootElement;  
 @XmlRootElement  
 public class UserCollection {  
   private Collection<User> users;  
   public UserCollection() {  
   }  
   public UserCollection(Collection<User> users) {  
     this.users = users;  
   }  
   @XmlElement(name="user")  
   @XmlElementWrapper(name="users")  
   public Collection<User> getUsers() {  
     return users;  
   }  
 }  

User
 package pojo;  
 import javax.xml.bind.annotation.XmlRootElement;  
 @XmlRootElement(name = "user")  
 public class User {  
   private Integer id;  
   private String name;  
   private String designation;  
      public String getDesignation() {  
           return designation;  
      }  
      public void setDesignation(String designation) {  
           this.designation = designation;  
      }  
      public User() {  
   }  
   public User(Integer id, String name,String designation) {  
     this.id = id;  
     this.name = name;  
     this.designation=designation;  
   }  
   public User(String name,String designation) {  
     this.id = id;  
     this.name = name;  
     this.designation=designation;  
   }  
   public Integer getId() {  
     return id;  
   }  
   public void setId(Integer id) {  
     this.id = id;  
   }  
   public void setName(String name) {  
     this.name = name;  
   }  
   public String getName() {  
     return name;  
   }  
   @Override  
      public String toString() {  
           return "User [id=" + id + ", name=" + name + ", designation="  
                     + designation + "]";  
      }  
 }  

Monday, August 20, 2012

cxf-jaxws-SOAP Example-Live Resturant Example

This is a simple cxf-jaxws application.The appliction offers 2 services
  • cancel order
  • place order
The wsdl can be accessed at: http://localhost:8086/cxf-jaxws-LiveResturant/OrderService?wsdl
CXF webservice depends on the service endpoint interface.
Uses spring based configuration.
The application has been tested on tomcat and uses the latest cxf jar files.
  1. Create a web application project in eclipse
  2. cxf.xml -add a cxf.xml in web-inf folder
  3.  <beans xmlns="http://www.springframework.org/schema/beans"  
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
       xmlns:jaxws="http://cxf.apache.org/jaxws"  
      xmlns:wsa="http://cxf.apache.org/ws/addressing"   
      xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager"  
      xmlns:wsp="http://www.w3.org/2006/07/ws-policy"  
        xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm/policy"  
         xmlns:wsam="http://www.w3.org/2007/02/addressing/metadata"  
      xmlns:mtom="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization"  
      xsi:schemaLocation="http://www.springframework.org/schema/beans   
     http://www.springframework.org/schema/beans/spring-beans.xsd  
     http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd  
     http://cxf.apache.org/schemas/configuration/wsrm-manager.xsd  
     http://www.w3.org/2006/07/ws-policy http://www.w3.org/2006/07/ws-policy.xsd  
     http://cxf.apache.org/ws/rm/manager  
     http://cxf.apache.org/jaxws   
     http://cxf.apache.org/schemas/jaxws.xsd">  
     <jaxws:endpoint id="orderService" implementor="com.live.order.service.OrderServiceImpl" address="/OrderService">  
     </jaxws:endpoint >  
     </beans>  
    
  4. update the web.xml file --added cxf servlet and spring contextloader listener
     <?xml version="1.0" encoding="UTF-8"?>  
     <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">  
      <display-name>cxf-jaxws-poc</display-name>  
      <context-param>  
       <param-name>contextConfigLocation</param-name>  
       <param-value>WEB-INF/postgreSQL-beans.xml,WEB-INF/cxf.xml</param-value>  
      </context-param>  
      <listener>  
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
      </listener>  
      <servlet>  
       <servlet-name>CXFServlet</servlet-name>  
       <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>  
       <load-on-startup>1</load-on-startup>  
      </servlet>  
      <servlet-mapping>  
       <servlet-name>CXFServlet</servlet-name>  
       <url-pattern>/*</url-pattern>  
      </servlet-mapping>  
     </web-app>  
    
  5. Service EndPoint Interface-SEI

  6.  package com.live.order.service;  
     import javax.jws.WebService;  
     import com.live.order.domain.Order;  
     import javax.jws.WebMethod;  
     /**  
     * <pre>  
     * Service interface for Order Service operations, handles two operations. <ul>  
     *   <li>placeOrderRequest</li>  
     *   <li>cancelOrderRequest</li>  
     * </ul>  
     * </pre>  
     *  
     *  
     * @see OrderServiceImpl  
     *  
     */  
     @WebService  
     public interface OrderService {  
     @WebMethod  
       String placeOrder(Order order);  
     @WebMethod  
       boolean cancelOrder(String orderRef);  
     }  
    
  7. OrderServiceImpl
     package com.live.order.service;  
     import java.io.File;  
     import java.io.IOException;  
     import java.util.Calendar;  
     import javax.jws.WebService;  
     import org.apache.commons.io.FileUtils;  
     import org.apache.commons.lang.ObjectUtils;  
     import org.apache.log4j.Logger;  
     import org.springframework.context.ApplicationContext;  
     import org.springframework.context.support.ClassPathXmlApplicationContext;  
     import com.live.order.dao.OrderDAO;  
     import com.live.order.dao.OrderDAOImpl;  
     import com.live.order.domain.Order;  
     /**  
     * <pre>  
     * Service implementation for {@link OrderService}  
     * </pre>  
     *  
     * @see OrderService  
     *  
     */  
     @WebService  
     public class OrderServiceImpl implements OrderService {  
       private static final Logger logger = Logger.getLogger(OrderServiceImpl.class);  
       static ApplicationContext context;  
       OrderDAO dao;  
       public OrderServiceImpl() {  
            context = new ClassPathXmlApplicationContext("postgreSQL-beans.xml");  
            dao= (OrderDAO) context.getBean("OrderDAO");  
       }  
       public String placeOrder(Order order) {  
             order.setRefNumber(getRandomOrderRefNo());  
            // dao.insert_Order(order);  
         logger.info("Order has been placed. Order Info is : " + ObjectUtils.toString(order));  
        File file = new File("sample.txt");  
         System.out.println("file path : " + file.getAbsolutePath());  
         // We'll write the string below into the file  
         // To write a file called the writeStringToFile  
         // method which require you to pass the file and  
         // the data to be written.  
         try {  
                    FileUtils.writeStringToFile(file, ObjectUtils.toString(order));  
               } catch (IOException e) {  
                    // TODO Auto-generated catch block  
                    e.printStackTrace();  
               }  
         logger.info("Order has been placed. Order Info is : " + getRandomOrderRefNo());  
         return order.getRefNumber();  
       }  
       public boolean cancelOrder(String orderRef) {  
         logger.info("Order has been cancelled Order Reference : " + orderRef);  
         return true;  
       }  
       private String getRandomOrderRefNo() {  
         Calendar calendar = Calendar.getInstance();  
         int year = calendar.get(Calendar.YEAR);  
         int month = calendar.get(Calendar.MONTH);  
         int day = calendar.get(Calendar.DAY_OF_MONTH);  
         logger.info("Ref-" + year + "-" + month + "-" + day + "-" + Math.random());  
         return "Ref-" + year + "-" + month + "-" + day + "-" + Math.random();  
       }  
     }  
    
  8. Creating domain objects
    
     package com.live.order.domain;  
     public class Address {  
       protected String doorNo;  
       protected String building;  
       protected String street;  
       protected String city;  
       protected String country;  
       protected String phoneMobile;  
       protected String phoneLandLine;  
       protected String email;  
       /**  
        * Gets the value of the doorNo property.  
        *   
        * @return  
        *   possible object is  
        *   {@link String }  
        *     
        */  
       public String getDoorNo() {  
         return doorNo;  
       }  
       /**  
        * Sets the value of the doorNo property.  
        *   
        * @param value  
        *   allowed object is  
        *   {@link String }  
        *     
        */  
       public void setDoorNo(String value) {  
         this.doorNo = value;  
       }  
       /**  
        * Gets the value of the building property.  
        *   
        * @return  
        *   possible object is  
        *   {@link String }  
        *     
        */  
       public String getBuilding() {  
         return building;  
       }  
       /**  
        * Sets the value of the building property.  
        *   
        * @param value  
        *   allowed object is  
        *   {@link String }  
        *     
        */  
       public void setBuilding(String value) {  
         this.building = value;  
       }  
       /**  
        * Gets the value of the street property.  
        *   
        * @return  
        *   possible object is  
        *   {@link String }  
        *     
        */  
       public String getStreet() {  
         return street;  
       }  
       /**  
        * Sets the value of the street property.  
        *   
        * @param value  
        *   allowed object is  
        *   {@link String }  
        *     
        */  
       public void setStreet(String value) {  
         this.street = value;  
       }  
       /**  
        * Gets the value of the city property.  
        *   
        * @return  
        *   possible object is  
        *   {@link String }  
        *     
        */  
       public String getCity() {  
         return city;  
       }  
       /**  
        * Sets the value of the city property.  
        *   
        * @param value  
        *   allowed object is  
        *   {@link String }  
        *     
        */  
       public void setCity(String value) {  
         this.city = value;  
       }  
       /**  
        * Gets the value of the country property.  
        *   
        * @return  
        *   possible object is  
        *   {@link String }  
        *     
        */  
       public String getCountry() {  
         return country;  
       }  
       /**  
        * Sets the value of the country property.  
        *   
        * @param value  
        *   allowed object is  
        *   {@link String }  
        *     
        */  
       public void setCountry(String value) {  
         this.country = value;  
       }  
       /**  
        * Gets the value of the phoneMobile property.  
        *   
        * @return  
        *   possible object is  
        *   {@link String }  
        *     
        */  
       public String getPhoneMobile() {  
         return phoneMobile;  
       }  
       /**  
        * Sets the value of the phoneMobile property.  
        *   
        * @param value  
        *   allowed object is  
        *   {@link String }  
        *     
        */  
       public void setPhoneMobile(String value) {  
         this.phoneMobile = value;  
       }  
       /**  
        * Gets the value of the phoneLandLine property.  
        *   
        * @return  
        *   possible object is  
        *   {@link String }  
        *     
        */  
       public String getPhoneLandLine() {  
         return phoneLandLine;  
       }  
       /**  
        * Sets the value of the phoneLandLine property.  
        *   
        * @param value  
        *   allowed object is  
        *   {@link String }  
        *     
        */  
       public void setPhoneLandLine(String value) {  
         this.phoneLandLine = value;  
       }  
       /**  
        * Gets the value of the email property.  
        *   
        * @return  
        *   possible object is  
        *   {@link String }  
        *     
        */  
       public String getEmail() {  
         return email;  
       }  
       /**  
        * Sets the value of the email property.  
        *   
        * @param value  
        *   allowed object is  
        *   {@link String }  
        *     
        */  
       public void setEmail(String value) {  
         this.email = value;  
       }  
          @Override  
          public String toString() {  
               return "Address [doorNo=" + doorNo + ", building=" + building  
                         + ", street=" + street + ", city=" + city + ", country="  
                         + country + ", phoneMobile=" + phoneMobile + ", phoneLandLine="  
                         + phoneLandLine + ", email=" + email + "]";  
          }  
     }  
    
  9. 
     package com.live.order.domain;  
     public class FoodItem {  
       protected FoodItemType type;  
       protected String name;  
       protected double quantity;  
       /**  
        * Gets the value of the type property.  
        *   
        * @return  
        *   possible object is  
        *   {@link FoodItemType }  
        *     
        */  
       public FoodItemType getType() {  
         return type;  
       }  
       /**  
        * Sets the value of the type property.  
        *   
        * @param value  
        *   allowed object is  
        *   {@link FoodItemType }  
        *     
        */  
       public void setType(FoodItemType value) {  
         this.type = value;  
       }  
       /**  
        * Gets the value of the name property.  
        *   
        * @return  
        *   possible object is  
        *   {@link String }  
        *     
        */  
       public String getName() {  
         return name;  
       }  
       /**  
        * Sets the value of the name property.  
        *   
        * @param value  
        *   allowed object is  
        *   {@link String }  
        *     
        */  
       public void setName(String value) {  
         this.name = value;  
       }  
       /**  
        * Gets the value of the quantity property.  
        *   
        */  
       public double getQuantity() {  
         return quantity;  
       }  
       /**  
        * Sets the value of the quantity property.  
        *   
        */  
       public void setQuantity(double value) {  
         this.quantity = value;  
       }  
     }  
    
  10. 
     package com.live.order.domain;  
     public enum FoodItemType {  
       BEVERAGES("Beverages"),  
       COFFEE("Coffee"),  
       DESSERTS("Desserts"),  
       JUICES("Juices"),  
       MEALS("Meals"),  
       SNACKS("Snacks"),  
       STARTERS("Starters");  
       private final String value;  
       FoodItemType(String v) {  
         value = v;  
       }  
       public String value() {  
         return value;  
       }  
       public static FoodItemType fromValue(String v) {  
         for (FoodItemType c: FoodItemType.values()) {  
           if (c.value.equals(v)) {  
             return c;  
           }  
         }  
         throw new IllegalArgumentException(v.toString());  
       }  
     }  
    

Sunday, August 12, 2012

Code First Webservice using jax-ws and CXF- webservice framework

  1. Create a Bean
  2. Create a SEI-Service End Point Interface
  3. Use Annotation on the SEI @ webservice
  4. Create a Implementation Class which implements the SEI
  5. Create a CXF.xml file add the  SEI and impl mapping in the xml file
  6. configure the cxf file in the web.xml
  7. map the  spring context listener and cxf servlet in the web.xml.