Posts

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 fro...

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); //...

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.

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");     } }  

CXF RESTFUL Service - Example jax-rs

CXF frame work  supports restful web services. It is provided in the following ways: JAX_RS JAX_WS ProviderDispatch 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-in...

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. Create a web application project in eclipse cxf.xml -add a cxf.xml in web-inf folder <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...

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

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