tag:blogger.com,1999:blog-7549084380077653352024-03-08T03:49:40.615-08:00Axis2 Web Services Creation.Gangadhara Rao Duvvarapuhttp://www.blogger.com/profile/13863602001434055410noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-754908438007765335.post-49297207372048893922010-03-29T18:37:00.000-07:002010-03-29T18:39:36.754-07:00Importent Programming Stuff<span style="font-weight: bold;">Identifying Special Characters in a Given String</span><br />-------------------------------------------------------------------------------------------------<br /><br />package special;<br /><br />public class IdentifySpecialChar {<br /><br /> /**<br /> * @param args<br /> */<br /> public static void main(String[] args) {<br /> <br /> try {<br /> System.out.println(IdentifySpecialChar.identifyingSpecialCharacters("Gangadhar"));<br /> } catch (Exception e) {<br /> // TODO Auto-generated catch block<br /> e.printStackTrace();<br /> }<br /> }<br /> <br /> /**<br /> * This method is used to identify the special characters in the given value,<br /> * if there are any special characters it return true else return false.<br /> * @param value<br /> * @return<br /> * @throws Exception<br /> */<br /> public static boolean identifyingSpecialCharacters(String value) throws Exception {<br /> boolean returnVal = false;<br /> char[] charArray = value.toCharArray();<br /> for(int i=0;i< charArray.length;i++) {<br /> System.out.println((int)charArray[i]);<br /> if( (((int)charArray[i]) >= 32 && ((int)charArray[i]) <= 47) ||<br /> (((int)charArray[i]) >= 58 && ((int)charArray[i]) <= 64) ||<br /> (((int)charArray[i]) >= 91 && ((int)charArray[i]) <= 96) ||<br /> (((int)charArray[i]) >= 123 && ((int)charArray[i]) <= 127)) {<br /> returnVal = true;<br /> break;<br /> }<br /> }<br /> return returnVal;<br /> }<br />}Gangadhara Rao Duvvarapuhttp://www.blogger.com/profile/13863602001434055410noreply@blogger.com0tag:blogger.com,1999:blog-754908438007765335.post-52103775592375112452010-02-18T06:37:00.000-08:002010-02-18T06:55:47.445-08:00Hibernate - OneToOne***************************************************************************************<br />Tables<br />***************************************************************************************<br /> create table "SCOTT"."PERSON"(<br /> "PERSON_ID" NUMBER(10) not null,<br /> "PERSON_NAME" VARCHAR2(20),<br /> constraint "PK_PERSON" primary key ("PERSON_ID")<br /> );<br /><br /> create unique index "PK_PERSON" on "SCOTT"."PERSON"("PERSON_ID");<br /><br />create table "SCOTT"."COMPUTER"(<br /> "COM_ID" NUMBER(10) not null,<br /> "COMPUTER_NAME" VARCHAR2(20),<br /> "PROCESSOR" VARCHAR2(20),<br /> "PERSON_ID" NUMBER(10) unique,<br /> constraint "PK_COMPUTER" primary key ("COM_ID")<br /> );<br /><br /> alter table "SCOTT"."COMPUTER"<br /> add constraint "FK_PERSON_ID"<br /> foreign key ("PERSON_ID")<br /> references "SCOTT"."PERSON"("PERSON_ID");<br /> create unique index "PK_COMPUTER" on "SCOTT"."COMPUTER"("COM_ID");<br /> create unique index "UNIQUE_PERID" on "SCOTT"."COMPUTER"("PERSON_ID");<br />***************************************************************************************<br />Hibernate Factory Class<br />------------------------<br />package factory;<br /><br />import org.hibernate.HibernateException;<br />import org.hibernate.Session;<br />import org.hibernate.cfg.Configuration;<br /><br />/**<br />* Configures and provides access to Hibernate sessions, tied to the<br />* current thread of execution. Follows the Thread Local Session<br />* pattern, see {@link http://hibernate.org/42.html }.<br />*/<br />public class HibernateSessionFactory {<br /><br /> /**<br /> * Location of hibernate.cfg.xml file.<br /> * Location should be on the classpath as Hibernate uses<br /> * #resourceAsStream style lookup for its configuration file.<br /> * The default classpath location of the hibernate config file is<br /> * in the default package. Use #setConfigFile() to update<br /> * the location of the configuration file for the current session.<br /> */<br /> private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";<br /> private static final ThreadLocal<session> threadLocal = new ThreadLocal<session>();<br /> private static Configuration configuration = new Configuration();<br /> private static org.hibernate.SessionFactory sessionFactory;<br /> private static String configFile = CONFIG_FILE_LOCATION;<br /><br /> private HibernateSessionFactory() {<br /> }<br /><br /> /**<br /> * Returns the ThreadLocal Session instance. Lazy initialize<br /> * the <code>SessionFactory</code> if needed.<br /> *<br /> * @return Session<br /> * @throws HibernateException<br /> */<br /> public static Session getSession() throws HibernateException {<br /> Session session = (Session) threadLocal.get();<br /><br /> if (session == null || !session.isOpen()) {<br /> if (sessionFactory == null) {<br /> rebuildSessionFactory();<br /> }<br /> session = (sessionFactory != null) ? sessionFactory.openSession()<br /> : null;<br /> threadLocal.set(session);<br /> }<br /><br /> return session;<br /> }<br /><br /> /**<br /> * Rebuild hibernate session factory<br /> *<br /> */<br /> public static void rebuildSessionFactory() {<br /> try {<br /> configuration.configure(configFile);<br /> sessionFactory = configuration.buildSessionFactory();<br /> } catch (Exception e) {<br /> System.err<br /> .println("%%%% Error Creating SessionFactory %%%%");<br /> e.printStackTrace();<br /> }<br /> }<br /><br /> /**<br /> * Close the single hibernate session instance.<br /> *<br /> * @throws HibernateException<br /> */<br /> public static void closeSession() throws HibernateException {<br /> Session session = (Session) threadLocal.get();<br /> threadLocal.set(null);<br /><br /> if (session != null) {<br /> session.close();<br /> }<br /> }<br /><br /> /**<br /> * return session factory<br /> *<br /> */<br /> public static org.hibernate.SessionFactory getSessionFactory() {<br /> return sessionFactory;<br /> }<br /><br /> /**<br /> * return session factory<br /> *<br /> * session factory will be rebuilded in the next call<br /> */<br /> public static void setConfigFile(String configFile) {<br /> HibernateSessionFactory.configFile = configFile;<br /> sessionFactory = null;<br /> }<br /><br /> /**<br /> * return hibernate configuration<br /> *<br /> */<br /> public static Configuration getConfiguration() {<br /> return configuration;<br /> }<br /><br />}<br /><br />***************************************************************************************<br />Pojo Classes<br />------------<br />package model;<br />// default package<br /><br /><br /><br />/**<br />* Computer generated by MyEclipse - Hibernate Tools<br />*/<br /><br />public class Computer implements java.io.Serializable {<br /><br /><br /> // Fields <br /><br /> private Long comId;<br /> private Person person;<br /> private String computerName;<br /> private String processor;<br /><br /><br /> // Constructors<br /><br /> /** default constructor */<br /> public Computer() {<br /> }<br /><br /><br /> /** full constructor */<br /> public Computer(Person person, String computerName, String processor) {<br /> this.person = person;<br /> this.computerName = computerName;<br /> this.processor = processor;<br /> }<br /><br /><br /> // Property accessors<br /><br /> public Long getComId() {<br /> return this.comId;<br /> }<br /><br /> public void setComId(Long comId) {<br /> this.comId = comId;<br /> }<br /><br /> public Person getPerson() {<br /> return this.person;<br /> }<br /><br /> public void setPerson(Person person) {<br /> this.person = person;<br /> }<br /><br /> public String getComputerName() {<br /> return this.computerName;<br /> }<br /><br /> public void setComputerName(String computerName) {<br /> this.computerName = computerName;<br /> }<br /><br /> public String getProcessor() {<br /> return this.processor;<br /> }<br /><br /> public void setProcessor(String processor) {<br /> this.processor = processor;<br /> }<br />}<br /><br /><br /><br />package model;<br />// default package<br /><br />import java.util.HashSet;<br />import java.util.Set;<br /><br /><br />/**<br />* Person generated by MyEclipse - Hibernate Tools<br />*/<br /><br />public class Person implements java.io.Serializable {<br /><br /><br /> // Fields <br /><br /> private Long personId;<br /> private String personName;<br /> private Set computers = new HashSet(0);<br /><br /><br /> // Constructors<br /><br /> /** default constructor */<br /> public Person() {<br /> }<br /><br /><br /> /** full constructor */<br /> public Person(String personName, Set computers) {<br /> this.personName = personName;<br /> this.computers = computers;<br /> }<br /><br /><br /> // Property accessors<br /><br /> public Long getPersonId() {<br /> return this.personId;<br /> }<br /><br /> public void setPersonId(Long personId) {<br /> this.personId = personId;<br /> }<br /><br /> public String getPersonName() {<br /> return this.personName;<br /> }<br /><br /> public void setPersonName(String personName) {<br /> this.personName = personName;<br /> }<br /><br /> public Set getComputers() {<br /> return this.computers;<br /> }<br /><br /> public void setComputers(Set computers) {<br /> this.computers = computers;<br /> }<br />}<br />***************************************************************************************<br />Mapping Files<br />--------------</session></session><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_8np7y7bofeo/S31UF69HwTI/AAAAAAAAADo/fNy6Ui5vwpI/s1600-h/ComputerMappingFile.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 176px;" src="http://2.bp.blogspot.com/_8np7y7bofeo/S31UF69HwTI/AAAAAAAAADo/fNy6Ui5vwpI/s320/ComputerMappingFile.bmp" alt="" id="BLOGGER_PHOTO_ID_5439596385635123506" border="0" /></a><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_8np7y7bofeo/S31UgnNMR0I/AAAAAAAAADw/31KtGSCRE9Q/s1600-h/PersonMappingFile.bmp"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 174px;" src="http://2.bp.blogspot.com/_8np7y7bofeo/S31UgnNMR0I/AAAAAAAAADw/31KtGSCRE9Q/s320/PersonMappingFile.bmp" alt="" id="BLOGGER_PHOTO_ID_5439596844190287682" border="0" /></a><session><session>***************************************************************************************<br />DAO Class<br />-----------<br />package dao;<br /><br />import java.io.Serializable;<br /><br />import org.hibernate.HibernateException;<br />import org.hibernate.LockMode;<br />import org.hibernate.Session;<br />import org.hibernate.Transaction;<br /><br />import factory.HibernateSessionFactory;<br /><br />public class OneToOneDAO {<br /> public Object saveComputer(Class clazz, Object object) throws HibernateException {<br /> Session session = HibernateSessionFactory.getSession();<br /> Transaction tx = session.beginTransaction();<br /> Serializable id = session.save(object);<br /> tx.commit();<br /> Object returnObj = session.get(clazz, id, LockMode.UPGRADE);<br /> return returnObj;<br /> }<br />}<br />***************************************************************************************<br />Test Class<br />----------<br />package test;<br /><br />import java.util.HashSet;<br />import java.util.Set;<br /><br />import dao.OneToOneDAO;<br /><br />import model.Computer;<br />import model.Person;<br /><br />public class TestOneToOne {<br /><br /> /**<br /> * @param args<br /> */<br /> public static void main(String[] args) {<br /> OneToOneDAO oneToOneDAO = new OneToOneDAO();<br /> <br /> Computer computer = new Computer();<br /> computer.setComputerName("Gr_Computer");<br /> computer.setProcessor("Intel Duo Core");<br /> <br /> Person person = new Person();<br /> person.setPersonName("Gangadhar");<br /> <br /> /*Person person1 = new Person();<br /> person1.setPersonName("Rao");*/<br /> <br /> computer.setPerson(person);<br /> // Here in Computer class you can able to set only one person object, you can not set more than one.<br /> /*computer.setPerson(person1);*/ <br /> <br /> Set<computer> setOfComputers = new HashSet<computer>();<br /> setOfComputers.add(computer);<br /> <br /> person.setComputers(setOfComputers);<br /> /*person1.setComputers(setOfComputers);*/<br /> <br /> oneToOneDAO.saveComputer(Computer.class, computer);<br /> }<br />}<br /></session></session>***************************************************************************************Gangadhara Rao Duvvarapuhttp://www.blogger.com/profile/13863602001434055410noreply@blogger.com0tag:blogger.com,1999:blog-754908438007765335.post-56998871123403274492010-02-17T18:57:00.000-08:002010-02-17T19:06:42.150-08:00Hibernate - Many To One Example****************************************************************************************<br />Tables<br />****************************************************************************************<br />create table "SCOTT"."ADD_RESS"(<br /> "ADDRESS_ID" NUMBER(10) not null,<br /> "ADDRESS_STREET" VARCHAR2(20),<br /> "ADDRESS_CITY" VARCHAR2(20),<br /> "ADDRESS_STATE" VARCHAR2(20),<br /> "ADDRESS_PIN" NUMBER(10),<br /> constraint "PK_ADD_RESS" primary key ("ADDRESS_ID")<br /> );<br /><br /> create unique index "PK_ADD_RESS" on "SCOTT"."ADD_RESS"("ADDRESS_ID");<br /><br /><br /><br /> create table "SCOTT"."STUDENT"(<br /> "STUDENT_ID" NUMBER(10) not null,<br /> "STUDENT_NAME" VARCHAR2(30),<br /> "STUDENT_ADDRESS" NUMBER(10),<br /> constraint "PK_STUDENT" primary key ("STUDENT_ID")<br /> );<br /><br /> alter table "SCOTT"."STUDENT" <br /> add constraint "ADD_FK" <br /> foreign key ("STUDENT_ADDRESS") <br /> references "SCOTT"."ADD_RESS"("ADDRESS_ID");<br /> create unique index "PK_STUDENT" on "SCOTT"."STUDENT"("STUDENT_ID");<br />****************************************************************************************<br />Hibernate Session Factory Class<br />****************************************************************************************<br />package factory;<br /><br />import org.hibernate.HibernateException;<br />import org.hibernate.Session;<br />import org.hibernate.cfg.Configuration;<br /><br />/**<br /> * Configures and provides access to Hibernate sessions, tied to the<br /> * current thread of execution. Follows the Thread Local Session<br /> * pattern, see {@link http://hibernate.org/42.html }.<br /> */<br />public class HibernateSessionFactory {<br /><br /> /** <br /> * Location of hibernate.cfg.xml file.<br /> * Location should be on the classpath as Hibernate uses <br /> * #resourceAsStream style lookup for its configuration file. <br /> * The default classpath location of the hibernate config file is <br /> * in the default package. Use #setConfigFile() to update <br /> * the location of the configuration file for the current session. <br /> */<br /> private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";<br /> private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();<br /> private static Configuration configuration = new Configuration();<br /> private static org.hibernate.SessionFactory sessionFactory;<br /> private static String configFile = CONFIG_FILE_LOCATION;<br /><br /> private HibernateSessionFactory() {<br /> }<br /> <br /> /**<br /> * Returns the ThreadLocal Session instance. Lazy initialize<br /> * the <code>SessionFactory</code> if needed.<br /> *<br /> * @return Session<br /> * @throws HibernateException<br /> */<br /> public static Session getSession() throws HibernateException {<br /> Session session = (Session) threadLocal.get();<br /><br /> if (session == null || !session.isOpen()) {<br /> if (sessionFactory == null) {<br /> rebuildSessionFactory();<br /> }<br /> session = (sessionFactory != null) ? sessionFactory.openSession()<br /> : null;<br /> threadLocal.set(session);<br /> }<br /><br /> return session;<br /> }<br /><br /> /**<br /> * Rebuild hibernate session factory<br /> *<br /> */<br /> public static void rebuildSessionFactory() {<br /> try {<br /> configuration.configure(configFile);<br /> sessionFactory = configuration.buildSessionFactory();<br /> } catch (Exception e) {<br /> System.err<br /> .println("%%%% Error Creating SessionFactory %%%%");<br /> e.printStackTrace();<br /> }<br /> }<br /><br /> /**<br /> * Close the single hibernate session instance.<br /> *<br /> * @throws HibernateException<br /> */<br /> public static void closeSession() throws HibernateException {<br /> Session session = (Session) threadLocal.get();<br /> threadLocal.set(null);<br /><br /> if (session != null) {<br /> session.close();<br /> }<br /> }<br /><br /> /**<br /> * return session factory<br /> *<br /> */<br /> public static org.hibernate.SessionFactory getSessionFactory() {<br /> return sessionFactory;<br /> }<br /><br /> /**<br /> * return session factory<br /> *<br /> * session factory will be rebuilded in the next call<br /> */<br /> public static void setConfigFile(String configFile) {<br /> HibernateSessionFactory.configFile = configFile;<br /> sessionFactory = null;<br /> }<br /><br /> /**<br /> * return hibernate configuration<br /> *<br /> */<br /> public static Configuration getConfiguration() {<br /> return configuration;<br /> }<br />}<br />****************************************************************************************<br />HibernateCFG.xml File<br />****************************************************************************************<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_8np7y7bofeo/S3yt4p8kPLI/AAAAAAAAADQ/_pIMfz4CF2Y/s1600-h/hibernatecfg.bmp"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 262px;" src="http://1.bp.blogspot.com/_8np7y7bofeo/S3yt4p8kPLI/AAAAAAAAADQ/_pIMfz4CF2Y/s320/hibernatecfg.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5439413638800882866" /></a><br />****************************************************************************************<br />Pojo Classes<br />****************************************************************************************<br />package model;<br />// default package<br /><br /><br /><br />/**<br /> * Student generated by MyEclipse - Hibernate Tools<br /> */<br /><br />public class Student implements java.io.Serializable {<br /><br /><br /> // Fields <br /><br /> private Long studentId;<br /> private Add_ress addRess;<br /> private String studentName;<br /><br /><br /> // Constructors<br /><br /> /** default constructor */<br /> public Student() {<br /> }<br /><br /> <br /> /** full constructor */<br /> public Student(Add_ress addRess, String studentName) {<br /> this.addRess = addRess;<br /> this.studentName = studentName;<br /> }<br /><br /> <br /> // Property accessors<br /><br /> public Long getStudentId() {<br /> return this.studentId;<br /> }<br /> <br /> public void setStudentId(Long studentId) {<br /> this.studentId = studentId;<br /> }<br /><br /> public Add_ress getAddRess() {<br /> return this.addRess;<br /> }<br /> <br /> public void setAddRess(Add_ress addRess) {<br /> this.addRess = addRess;<br /> }<br /><br /> public String getStudentName() {<br /> return this.studentName;<br /> }<br /> <br /> public void setStudentName(String studentName) {<br /> this.studentName = studentName;<br /> }<br />}<br /><br />package model;<br />// default package<br /><br />import java.util.HashSet;<br />import java.util.Set;<br /><br /><br />/**<br /> * Add_ress generated by MyEclipse - Hibernate Tools<br /> */<br /><br />public class Add_ress implements java.io.Serializable {<br /><br /><br /> // Fields <br /><br /> private Long addressId;<br /> private String addressStreet;<br /> private String addressCity;<br /> private String addressState;<br /> private Long addressPin;<br /> private Set students = new HashSet(0);<br /><br /><br /> // Constructors<br /><br /> /** default constructor */<br /> public Add_ress() {<br /> }<br /><br /> <br /> /** full constructor */<br /> public Add_ress(String addressStreet, String addressCity, String addressState, Long addressPin, Set students) {<br /> this.addressStreet = addressStreet;<br /> this.addressCity = addressCity;<br /> this.addressState = addressState;<br /> this.addressPin = addressPin;<br /> this.students = students;<br /> }<br /><br /> <br /> // Property accessors<br /><br /> public Long getAddressId() {<br /> return this.addressId;<br /> }<br /> <br /> public void setAddressId(Long addressId) {<br /> this.addressId = addressId;<br /> }<br /><br /> public String getAddressStreet() {<br /> return this.addressStreet;<br /> }<br /> <br /> public void setAddressStreet(String addressStreet) {<br /> this.addressStreet = addressStreet;<br /> }<br /><br /> public String getAddressCity() {<br /> return this.addressCity;<br /> }<br /> <br /> public void setAddressCity(String addressCity) {<br /> this.addressCity = addressCity;<br /> }<br /><br /> public String getAddressState() {<br /> return this.addressState;<br /> }<br /> <br /> public void setAddressState(String addressState) {<br /> this.addressState = addressState;<br /> }<br /><br /> public Long getAddressPin() {<br /> return this.addressPin;<br /> }<br /> <br /> public void setAddressPin(Long addressPin) {<br /> this.addressPin = addressPin;<br /> }<br /><br /> public Set getStudents() {<br /> return this.students;<br /> }<br /> <br /> public void setStudents(Set students) {<br /> this.students = students;<br /> }<br />}<br />****************************************************************************************<br />Mapping Files<br />****************************************************************************************<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_8np7y7bofeo/S3yuYTFCQ7I/AAAAAAAAADY/5Zvv0vaPlE4/s1600-h/AddressMappingFile.bmp"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 274px;" src="http://2.bp.blogspot.com/_8np7y7bofeo/S3yuYTFCQ7I/AAAAAAAAADY/5Zvv0vaPlE4/s320/AddressMappingFile.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5439414182418203570" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_8np7y7bofeo/S3yuhPk9wDI/AAAAAAAAADg/u7LEAgIspxw/s1600-h/StudentMappingFile.bmp"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 150px;" src="http://4.bp.blogspot.com/_8np7y7bofeo/S3yuhPk9wDI/AAAAAAAAADg/u7LEAgIspxw/s320/StudentMappingFile.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5439414336097206322" /></a><br />****************************************************************************************<br />Actual DAO Class<br />****************************************************************************************<br />package test;<br /><br />import java.io.Serializable;<br />import java.util.HashSet;<br />import java.util.Set;<br /><br />import model.Add_ress;<br />import model.Student;<br /><br />import org.hibernate.HibernateException;<br />import org.hibernate.LockMode;<br />import org.hibernate.Session;<br />import org.hibernate.Transaction;<br /><br />import factory.HibernateSessionFactory;<br /><br />public class TestManyToOne {<br /><br /> /**<br /> * @param args<br /> */<br /> public static void main(String[] args) {<br /> //Saving Address and Student Objects<br /> Add_ress add_ress = new Add_ress();<br /> add_ress.setAddressCity("Yanam");<br /> add_ress.setAddressState("Pondicherry");<br /> add_ress.setAddressStreet("1st Cross");<br /> add_ress.setAddressPin(533464l);<br /> <br /> Student student = new Student();<br /> student.setStudentName("Swetha");<br /> Student student1 = new Student();<br /> student1.setStudentName("Nagendra");<br /> student.setAddRess(add_ress);<br /> student1.setAddRess(add_ress);<br /> Set<Student> studentSet = new HashSet<Student>();<br /> studentSet.add(student);<br /> studentSet.add(student1);<br /> <br /> add_ress.setStudents(studentSet);<br /> <br />// new TestManyToOne().saveStudent(Add_ress.class, add_ress);<br /> //Saving Address and Student Objects<br /> <br /> /********************************************************************/<br /> //Getting Address and Student Objects.<br /> /*Add_ress add_ress1 = new Add_ress();<br /> add_ress1.setAddressId(4l);<br /> add_ress1 = (Add_ress)new TestManyToOne().getAddress(Add_ress.class, add_ress1.getAddressId());<br /> System.out.println("City : " + add_ress1.getAddressCity());<br /> System.out.println("State : " + add_ress1.getAddressState());<br /> System.out.println("Street: " + add_ress1.getAddressStreet());<br /> System.out.println("PIN : " + add_ress1.getAddressPin());<br /> studentSet = add_ress1.getStudents();<br /> for (Student student2 : studentSet) {<br /> System.out.println("--------------------------------------------");<br /> System.out.println("Student ID : " + student2.getStudentId());<br /> System.out.println("Student Name: " + student2.getStudentName());<br /> }*/<br /> //Getting Address and Student Objects.<br /> <br /> /********************************************************************/<br /> Add_ress add_ress2 = new Add_ress();<br /> <br /> Set<Student> stdSet = new HashSet<Student>();<br /> Student std1 = new Student();<br /> std1.setStudentId(5l);<br /> Student std2 = new Student();<br /> std2.setStudentId(6l);<br /> stdSet.add(std1);<br /> stdSet.add(std2);<br /> add_ress2.setAddressId(4l);<br /> add_ress2.setStudents(stdSet);<br /> new TestManyToOne().deleteAddress(add_ress2);<br /> }<br /><br /> <br /> public void saveStudent(Class clazz, Object object) throws HibernateException {<br /> Session session = HibernateSessionFactory.getSession();<br /> Transaction tx = session.beginTransaction();<br /> Serializable id = session.save(object);<br /> session.close();<br /> tx.commit();<br /> }<br /> <br /> public Object getAddress(Class clazz, long id) throws HibernateException {<br /> Session session = HibernateSessionFactory.getSession();<br /> Transaction tx = session.beginTransaction();<br /> Object returnObj = session.get(clazz, id, LockMode.UPGRADE);<br /> return returnObj;<br /> }<br /> <br /> public void deleteAddress(Add_ress add_ress) throws HibernateException {<br /> Session session = HibernateSessionFactory.getSession();<br /> Transaction tx = session.beginTransaction();<br /> session.delete(add_ress);<br /> //session.close();<br /> tx.commit();<br /> }<br /> <br />}<br /><br />****************************************************************************************Gangadhara Rao Duvvarapuhttp://www.blogger.com/profile/13863602001434055410noreply@blogger.com0tag:blogger.com,1999:blog-754908438007765335.post-76808314722488176782010-02-17T18:38:00.000-08:002010-02-17T18:55:41.966-08:00Hibernate - One to Many ExampleTables<br />****************************************************************************************<br />create table "SCOTT"."EMPLOYEE"(<br /> "ID" NUMBER(10) not null,<br /> "NAME" VARCHAR2(50),<br /> "DEPT" VARCHAR2(20),<br /> "SAL" NUMBER(10),<br /> constraint "PK_EMPLOYEE" primary key ("ID")<br /> );<br /><br /> create unique index "PK_EMPLOYEE" on "SCOTT"."EMPLOYEE"("ID");<br /><br />create table "SCOTT"."ADDRESS"(<br /> "ID" NUMBER(10) not null,<br /> "EMP_ID" NUMBER(10),<br /> "STREET" VARCHAR2(30),<br /> "CITY" VARCHAR2(30),<br /> "STATE" VARCHAR2(30),<br /> "PIN" NUMBER(8),<br /> constraint "PK_ADDRESS" primary key ("ID")<br /> );<br /><br /> alter table "SCOTT"."ADDRESS" <br /> add constraint "EMP_ID_FK" <br /> foreign key ("EMP_ID") <br /> references "SCOTT"."EMPLOYEE"("ID");<br /> create unique index "PK_ADDRESS" on "SCOTT"."ADDRESS"("ID");<br />****************************************************************************************<br />Hibernate Session Factory Class<br />****************************************************************************************<br />package factory;<br /><br />import org.hibernate.HibernateException;<br />import org.hibernate.Session;<br />import org.hibernate.cfg.Configuration;<br /><br />/**<br /> * Configures and provides access to Hibernate sessions, tied to the<br /> * current thread of execution. Follows the Thread Local Session<br /> * pattern, see {@link http://hibernate.org/42.html }.<br /> */<br />public class HibernateSessionFactory {<br /><br /> /** <br /> * Location of hibernate.cfg.xml file.<br /> * Location should be on the classpath as Hibernate uses <br /> * #resourceAsStream style lookup for its configuration file. <br /> * The default classpath location of the hibernate config file is <br /> * in the default package. Use #setConfigFile() to update <br /> * the location of the configuration file for the current session. <br /> */<br /> private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";<br /> private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();<br /> private static Configuration configuration = new Configuration();<br /> private static org.hibernate.SessionFactory sessionFactory;<br /> private static String configFile = CONFIG_FILE_LOCATION;<br /><br /> private HibernateSessionFactory() {<br /> }<br /> <br /> /**<br /> * Returns the ThreadLocal Session instance. Lazy initialize<br /> * the <code>SessionFactory</code> if needed.<br /> *<br /> * @return Session<br /> * @throws HibernateException<br /> */<br /> public static Session getSession() throws HibernateException {<br /> Session session = (Session) threadLocal.get();<br /><br /> if (session == null || !session.isOpen()) {<br /> if (sessionFactory == null) {<br /> rebuildSessionFactory();<br /> }<br /> session = (sessionFactory != null) ? sessionFactory.openSession()<br /> : null;<br /> threadLocal.set(session);<br /> }<br /><br /> return session;<br /> }<br /><br /> /**<br /> * Rebuild hibernate session factory<br /> *<br /> */<br /> public static void rebuildSessionFactory() {<br /> try {<br /> configuration.configure(configFile);<br /> sessionFactory = configuration.buildSessionFactory();<br /> } catch (Exception e) {<br /> System.err<br /> .println("%%%% Error Creating SessionFactory %%%%");<br /> e.printStackTrace();<br /> }<br /> }<br /><br /> /**<br /> * Close the single hibernate session instance.<br /> *<br /> * @throws HibernateException<br /> */<br /> public static void closeSession() throws HibernateException {<br /> Session session = (Session) threadLocal.get();<br /> threadLocal.set(null);<br /><br /> if (session != null) {<br /> session.close();<br /> }<br /> }<br /><br /> /**<br /> * return session factory<br /> *<br /> */<br /> public static org.hibernate.SessionFactory getSessionFactory() {<br /> return sessionFactory;<br /> }<br /><br /> /**<br /> * return session factory<br /> *<br /> * session factory will be rebuilded in the next call<br /> */<br /> public static void setConfigFile(String configFile) {<br /> HibernateSessionFactory.configFile = configFile;<br /> sessionFactory = null;<br /> }<br /><br /> /**<br /> * return hibernate configuration<br /> *<br /> */<br /> public static Configuration getConfiguration() {<br /> return configuration;<br /> }<br /><br />}<br />****************************************************************************************<br />HibernateCFG.xls file<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_8np7y7bofeo/S3yrLvq3ExI/AAAAAAAAAC4/RpcteWCJWBY/s1600-h/hibernatecfg.bmp"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 229px;" src="http://4.bp.blogspot.com/_8np7y7bofeo/S3yrLvq3ExI/AAAAAAAAAC4/RpcteWCJWBY/s320/hibernatecfg.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5439410668219863826" /></a><br />****************************************************************************************<br />Pojo Classes<br />****************************************************************************************<br />package model;<br />// default package<br />/**<br /> * AddressModel generated by MyEclipse - Hibernate Tools<br /> */<br /><br />public class AddressModel implements java.io.Serializable {<br /> // Fields <br /><br /> private Long id;<br /> private EmployeeModel employee;<br /> private String street;<br /> private String city;<br /> private String state;<br /> private Long pin;<br /><br /><br /> // Constructors<br /><br /> /** default constructor */<br /> public AddressModel() {<br /> }<br /><br /> <br /> /** full constructor */<br /> public AddressModel(EmployeeModel employee, String street, String city, String state, Long pin) {<br /> this.employee = employee;<br /> this.street = street;<br /> this.city = city;<br /> this.state = state;<br /> this.pin = pin;<br /> }<br /><br /> <br /> // Property accessors<br /><br /> public Long getId() {<br /> return this.id;<br /> }<br /> <br /> public void setId(Long id) {<br /> this.id = id;<br /> }<br /><br /> public EmployeeModel getEmployee() {<br /> return this.employee;<br /> }<br /> <br /> public void setEmployee(EmployeeModel employee) {<br /> this.employee = employee;<br /> }<br /><br /> public String getStreet() {<br /> return this.street;<br /> }<br /> <br /> public void setStreet(String street) {<br /> this.street = street;<br /> }<br /><br /> public String getCity() {<br /> return this.city;<br /> }<br /> <br /> public void setCity(String city) {<br /> this.city = city;<br /> }<br /><br /> public String getState() {<br /> return this.state;<br /> }<br /> <br /> public void setState(String state) {<br /> this.state = state;<br /> }<br /><br /> public Long getPin() {<br /> return this.pin;<br /> }<br /> <br /> public void setPin(Long pin) {<br /> this.pin = pin;<br /> }<br />}<br /><br /><br />package model;<br />// default package<br /><br />import java.util.HashSet;<br />import java.util.Set;<br /><br />/**<br /> * EmployeeModel generated by MyEclipse - Hibernate Tools<br /> */<br /><br />public class EmployeeModel implements java.io.Serializable {<br /> // Fields <br /> private Long id;<br /> private String name;<br /> private String dept;<br /> private Long sal;<br /> private Set addresses = new HashSet(0);<br /><br /><br /> // Constructors<br /><br /> /** default constructor */<br /> public EmployeeModel() {<br /> }<br /><br /> <br /> /** full constructor */<br /> public EmployeeModel(String name, String dept, Long sal, Set addresses) {<br /> this.name = name;<br /> this.dept = dept;<br /> this.sal = sal;<br /> this.addresses = addresses;<br /> }<br /><br /> <br /> // Property accessors<br /><br /> public Long getId() {<br /> return this.id;<br /> }<br /> <br /> public void setId(Long id) {<br /> this.id = id;<br /> }<br /><br /> public String getName() {<br /> return this.name;<br /> }<br /> <br /> public void setName(String name) {<br /> this.name = name;<br /> }<br /><br /> public String getDept() {<br /> return this.dept;<br /> }<br /> <br /> public void setDept(String dept) {<br /> this.dept = dept;<br /> }<br /><br /> public Long getSal() {<br /> return this.sal;<br /> }<br /> <br /> public void setSal(Long sal) {<br /> this.sal = sal;<br /> }<br /><br /> public Set getAddresses() {<br /> return this.addresses;<br /> }<br /> <br /> public void setAddresses(Set addresses) {<br /> this.addresses = addresses;<br /> }<br />}<br /><br /><br />****************************************************************************************<br />Mapping files<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_8np7y7bofeo/S3yrwJ_JifI/AAAAAAAAADA/Sv6WmpcZgSQ/s1600-h/AddressMappingFile.bmp"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 230px;" src="http://4.bp.blogspot.com/_8np7y7bofeo/S3yrwJ_JifI/AAAAAAAAADA/Sv6WmpcZgSQ/s320/AddressMappingFile.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5439411293759572466" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_8np7y7bofeo/S3ysAmC5XjI/AAAAAAAAADI/i9TXDiuMXl4/s1600-h/AddressMappingFile.bmp"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 230px;" src="http://2.bp.blogspot.com/_8np7y7bofeo/S3ysAmC5XjI/AAAAAAAAADI/i9TXDiuMXl4/s320/AddressMappingFile.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5439411576169389618" /></a><br />****************************************************************************************<br />Actual DAO Class<br /><br />package test;<br /><br />import java.io.Serializable;<br />import java.util.HashSet;<br />import java.util.Set;<br /><br />import model.AddressModel;<br />import model.EmployeeModel;<br /><br />import org.hibernate.HibernateException;<br />import org.hibernate.LockMode;<br />import org.hibernate.Session;<br />import org.hibernate.Transaction;<br /><br />import factory.HibernateSessionFactory;<br /><br />public class EMPDAO {<br /><br /> /**<br /> * @param args<br /> */<br /> public static void main(String[] args) {<br /> EmployeeModel employeeModel = new EmployeeModel();<br /> employeeModel.setName("Gangadhara Rao D");<br /> employeeModel.setSal(1000L);<br /> employeeModel.setDept("Java");<br /> <br /> Set<AddressModel> set = new HashSet<AddressModel>();<br /> AddressModel addressModel = new AddressModel();<br /> addressModel.setStreet("3rd Cross");<br /> addressModel.setCity("Bangalore");<br /> addressModel.setState("Karnataka");<br /> addressModel.setPin(560068L);<br /> addressModel.setEmployee(employeeModel);<br /> set.add(addressModel);<br /> employeeModel.setAddresses(set);<br /> <br /> employeeModel = (EmployeeModel)new EMPDAO().saveEmployee(EmployeeModel.class, employeeModel);<br /> System.out.println(employeeModel.getId());<br /> }<br /> <br /> <br /> public Object saveEmployee(Class clazz, Object object) throws HibernateException {<br /> Session session = HibernateSessionFactory.getSession();<br /> Transaction tx = session.beginTransaction();<br /> Serializable id = session.save(object);<br /> tx.commit();<br /> /*session.flush();<br /> session.refresh(object);*/<br /> Object returnObj = session.get(clazz, id, LockMode.UPGRADE);<br /> return returnObj;<br /> }<br /><br />}<br />****************************************************************************************Gangadhara Rao Duvvarapuhttp://www.blogger.com/profile/13863602001434055410noreply@blogger.com0tag:blogger.com,1999:blog-754908438007765335.post-13902842805522746732010-02-15T18:25:00.000-08:002010-02-15T18:31:50.540-08:00EJB3 Session Beans**************************************************************************************<br />Server Side Code<br />**************************************************************************************<br />package test;<br /><br />import javax.ejb.Remote;<br /><br />@Remote<br />public interface TestEJBBean {<br /> public void executeBusinessLogic();<br />}<br /><br />**************************************************************************************<br />package test;<br /><br />import javax.ejb.Remote;<br />import javax.ejb.Stateless;<br /><br />import org.jboss.annotation.ejb.LocalBinding;<br />import org.jboss.annotation.ejb.RemoteBinding;<br />@Stateless (name="TestEJBBeanBean")<br />@Remote(TestEJBBean.class)<br />@RemoteBinding(jndiBinding = "/ejb3/TestEJBBeanBean")<br /><br />public class TestEJBBeanBean implements TestEJBBean{<br /> public void executeBusinessLogic() {<br /> System.out.println("Executing business logic.");<br /> }<br />}<br />**************************************************************************************<br />Client Side Code (Create this as another project)<br />**************************************************************************************<br />package test;<br />public interface TestEJBBean {<br /> public void executeBusinessLogic();<br />}<br />**************************************************************************************<br />package client;<br /><br />import java.io.FileInputStream;<br />import java.io.FileNotFoundException;<br />import java.io.IOException;<br />import java.util.Properties;<br /><br />import javax.naming.InitialContext;<br />import javax.naming.NamingException;<br /><br />import test.TestEJBBean;<br /><br /><br /><br />public class EJBTestClient {<br /><br /> static Properties props = new Properties();<br /> /**<br /> * @param args<br /> */<br /> public static void main(String[] args) {<br /> try { <br /> props.load(new FileInputStream("jndi.properties"));<br /> InitialContext ic = new InitialContext(props); <br /> TestEJBBean testEJBBean = (TestEJBBean)ic.lookup("/ejb3/TestEJBBeanBean");<br /> testEJBBean.executeBusinessLogic();<br /> } catch(FileNotFoundException fnfe) {<br /> fnfe.printStackTrace();<br /> } catch(IOException ioe) {<br /> ioe.printStackTrace();<br /> } catch(NamingException ne) {<br /> ne.printStackTrace();<br /> }<br /> }<br />}<br />**************************************************************************************<br />EJBJNDI.properties file (for JBoss)<br />**************************************************************************************<br />java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory<br />java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces<br />java.naming.provider.url=localhost:1099<br />TestEJBBeanBean=/ejb3/TestEJBBeanBean<br />**************************************************************************************Gangadhara Rao Duvvarapuhttp://www.blogger.com/profile/13863602001434055410noreply@blogger.com0tag:blogger.com,1999:blog-754908438007765335.post-23823545066840755232010-02-15T18:21:00.000-08:002010-02-17T17:57:06.786-08:00Web Service Complete Program--------------------------------------------------------------------------------------<br />Server Side Code<br />--------------------------------------------------------------------------------------<br /><br />package home.object;<br /><br />public class Address {<br /> private String street;<br /> private String city;<br /> private Integer pin;<br /> public String getCity() {<br /> return city;<br /> }<br /> public void setCity(String city) {<br /> this.city = city;<br /> }<br /> public Integer getPin() {<br /> return pin;<br /> }<br /> public void setPin(Integer pin) {<br /> this.pin = pin;<br /> }<br /> public String getStreet() {<br /> return street;<br /> }<br /> public void setStreet(String street) {<br /> this.street = street;<br /> }<br />}<br />--------------------------------------------------------------------------------------<br />package home.object;<br /><br />public class Employee {<br /> private String name;<br /> private Integer empNo;<br /> private Address address;<br /> public Address getAddress() {<br /> return address;<br /> }<br /> public void setAddress(Address address) {<br /> this.address = address;<br /> }<br /> public Integer getEmpNo() {<br /> return empNo;<br /> }<br /> public void setEmpNo(Integer empNo) {<br /> this.empNo = empNo;<br /> }<br /> public String getName() {<br /> return name;<br /> }<br /> public void setName(String name) {<br /> this.name = name;<br /> }<br />}<br />--------------------------------------------------------------------------------------<br />package home.webservice;<br /><br />import home.object.Employee;<br /><br />/**<br /> * @author Soumya Sree<br /> *<br /> */<br />public interface EmployeeInterface {<br /> public void displayEmp(Employee emp);<br />}<br />-------------------------------------------------------------------------------------<br />package home.webservice;<br /><br />import home.object.Address;<br />import home.object.Employee;<br /><br />import javax.ejb.Stateless;<br />import javax.jws.WebMethod;<br />import javax.jws.WebParam;<br />import javax.jws.WebService;<br />import javax.jws.soap.SOAPBinding;<br />import org.jboss.wsf.spi.annotation.WebContext;<br />@WebService(name = "EmployeeWebService", targetNamespace = "http://object.home/")<br />@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)<br />@WebContext(contextRoot = "/empoperations", urlPattern = "/displayEmp")<br />@Stateless()<br />public class EmployeeWebService implements EmployeeInterface{<br /> @WebMethod(operationName = "displayEmp", action = "displayEmp")<br /> public void displayEmp(@WebParam(name = "Employee", targetNamespace = "http://object.home/", partName = "employee") Employee emp) {<br /> System.out.println("Employee Name : " + emp.getName());<br /> System.out.println("Employee Number : " + emp.getEmpNo());<br /> Address address = emp.getAddress();<br /> System.out.println("Street : " + address.getStreet());<br /> System.out.println("City : " + address.getCity());<br /> System.out.println("PIN : " + address.getPin());<br /> }<br />}<br />-------------------------------------------------------------------------------------<br /><br />Create the Jar with the help of above files and deploy it into application server, the server automatically creates the WSDL (Web Service Description Language) file, with the help of wsdl and wsdl2java.jar we can write the client side code.<br />Generated wsdl is looks like the below content.<br />--------------------------------------------------------------------------------------<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_8np7y7bofeo/S3ydtPdNJcI/AAAAAAAAACo/VkwoR7zb7do/s1600-h/wsdl1.bmp"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 278px; height: 320px;" src="http://4.bp.blogspot.com/_8np7y7bofeo/S3ydtPdNJcI/AAAAAAAAACo/VkwoR7zb7do/s320/wsdl1.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5439395850525418946" /></a><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_8np7y7bofeo/S3yeVh9wOtI/AAAAAAAAACw/6SVDmfcyJ5I/s1600-h/wsdl2.bmp"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 206px;" src="http://1.bp.blogspot.com/_8np7y7bofeo/S3yeVh9wOtI/AAAAAAAAACw/6SVDmfcyJ5I/s320/wsdl2.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5439396542688541394" /></a><br />--------------------------------------------------------------------------------------<br />Client Side Code (Generated with the help of wsdl2java.jar file)<br />--------------------------------------------------------------------------------------<br />/**<br /> * Address.java<br /> *<br /> * This file was auto-generated from WSDL<br /> * by the Apache Axis WSDL2Java emitter.<br /> */<br /><br />package home.object;<br /><br />public class Address implements java.io.Serializable {<br /> private java.lang.String city;<br /> private java.lang.Integer pin;<br /> private java.lang.String street;<br /><br /> public Address() {<br /> }<br /><br /> public java.lang.String getCity() {<br /> return city;<br /> }<br /><br /> public void setCity(java.lang.String city) {<br /> this.city = city;<br /> }<br /><br /> public java.lang.Integer getPin() {<br /> return pin;<br /> }<br /><br /> public void setPin(java.lang.Integer pin) {<br /> this.pin = pin;<br /> }<br /><br /> public java.lang.String getStreet() {<br /> return street;<br /> }<br /><br /> public void setStreet(java.lang.String street) {<br /> this.street = street;<br /> }<br /><br /> private java.lang.Object __equalsCalc = null;<br /> public synchronized boolean equals(java.lang.Object obj) {<br /> if (!(obj instanceof Address)) return false;<br /> Address other = (Address) obj;<br /> if (obj == null) return false;<br /> if (this == obj) return true;<br /> if (__equalsCalc != null) {<br /> return (__equalsCalc == obj);<br /> }<br /> __equalsCalc = obj;<br /> boolean _equals;<br /> _equals = true && <br /> ((this.city==null && other.getCity()==null) || <br /> (this.city!=null &&<br /> this.city.equals(other.getCity()))) &&<br /> ((this.pin==null && other.getPin()==null) || <br /> (this.pin!=null &&<br /> this.pin.equals(other.getPin()))) &&<br /> ((this.street==null && other.getStreet()==null) || <br /> (this.street!=null &&<br /> this.street.equals(other.getStreet())));<br /> __equalsCalc = null;<br /> return _equals;<br /> }<br /><br /> private boolean __hashCodeCalc = false;<br /> public synchronized int hashCode() {<br /> if (__hashCodeCalc) {<br /> return 0;<br /> }<br /> __hashCodeCalc = true;<br /> int _hashCode = 1;<br /> if (getCity() != null) {<br /> _hashCode += getCity().hashCode();<br /> }<br /> if (getPin() != null) {<br /> _hashCode += getPin().hashCode();<br /> }<br /> if (getStreet() != null) {<br /> _hashCode += getStreet().hashCode();<br /> }<br /> __hashCodeCalc = false;<br /> return _hashCode;<br /> }<br /><br /> // Type metadata<br /> private static org.apache.axis.description.TypeDesc typeDesc =<br /> new org.apache.axis.description.TypeDesc(Address.class);<br /><br /> static {<br /> typeDesc.setXmlType(new javax.xml.namespace.QName("http://object.home/", "address"));<br /> org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();<br /> elemField.setFieldName("city");<br /> elemField.setXmlName(new javax.xml.namespace.QName("", "city"));<br /> elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));<br /> elemField.setMinOccurs(0);<br /> typeDesc.addFieldDesc(elemField);<br /> elemField = new org.apache.axis.description.ElementDesc();<br /> elemField.setFieldName("pin");<br /> elemField.setXmlName(new javax.xml.namespace.QName("", "pin"));<br /> elemField.setXmlType(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "int"));<br /> elemField.setMinOccurs(0);<br /> typeDesc.addFieldDesc(elemField);<br /> elemField = new org.apache.axis.description.ElementDesc();<br /> elemField.setFieldName("street");<br /> elemField.setXmlName(new javax.xml.namespace.QName("", "street"));<br /> elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));<br /> elemField.setMinOccurs(0);<br /> typeDesc.addFieldDesc(elemField);<br /> }<br /><br /> /**<br /> * Return type metadata object<br /> */<br /> public static org.apache.axis.description.TypeDesc getTypeDesc() {<br /> return typeDesc;<br /> }<br /><br /> /**<br /> * Get Custom Serializer<br /> */<br /> public static org.apache.axis.encoding.Serializer getSerializer(<br /> java.lang.String mechType, <br /> java.lang.Class _javaType, <br /> javax.xml.namespace.QName _xmlType) {<br /> return <br /> new org.apache.axis.encoding.ser.BeanSerializer(<br /> _javaType, _xmlType, typeDesc);<br /> }<br /><br /> /**<br /> * Get Custom Deserializer<br /> */<br /> public static org.apache.axis.encoding.Deserializer getDeserializer(<br /> java.lang.String mechType, <br /> java.lang.Class _javaType, <br /> javax.xml.namespace.QName _xmlType) {<br /> return <br /> new org.apache.axis.encoding.ser.BeanDeserializer(<br /> _javaType, _xmlType, typeDesc);<br /> }<br /><br />}<br />--------------------------------------------------------------------------------------<br />/**<br /> * Employee.java<br /> *<br /> * This file was auto-generated from WSDL<br /> * by the Apache Axis WSDL2Java emitter.<br /> */<br /><br />package home.object;<br /><br />public class Employee implements java.io.Serializable {<br /> private home.object.Address address;<br /> private java.lang.Integer empNo;<br /> private java.lang.String name;<br /><br /> public Employee() {<br /> }<br /><br /> public home.object.Address getAddress() {<br /> return address;<br /> }<br /><br /> public void setAddress(home.object.Address address) {<br /> this.address = address;<br /> }<br /><br /> public java.lang.Integer getEmpNo() {<br /> return empNo;<br /> }<br /><br /> public void setEmpNo(java.lang.Integer empNo) {<br /> this.empNo = empNo;<br /> }<br /><br /> public java.lang.String getName() {<br /> return name;<br /> }<br /><br /> public void setName(java.lang.String name) {<br /> this.name = name;<br /> }<br /><br /> private java.lang.Object __equalsCalc = null;<br /> public synchronized boolean equals(java.lang.Object obj) {<br /> if (!(obj instanceof Employee)) return false;<br /> Employee other = (Employee) obj;<br /> if (obj == null) return false;<br /> if (this == obj) return true;<br /> if (__equalsCalc != null) {<br /> return (__equalsCalc == obj);<br /> }<br /> __equalsCalc = obj;<br /> boolean _equals;<br /> _equals = true && <br /> ((this.address==null && other.getAddress()==null) || <br /> (this.address!=null &&<br /> this.address.equals(other.getAddress()))) &&<br /> ((this.empNo==null && other.getEmpNo()==null) || <br /> (this.empNo!=null &&<br /> this.empNo.equals(other.getEmpNo()))) &&<br /> ((this.name==null && other.getName()==null) || <br /> (this.name!=null &&<br /> this.name.equals(other.getName())));<br /> __equalsCalc = null;<br /> return _equals;<br /> }<br /><br /> private boolean __hashCodeCalc = false;<br /> public synchronized int hashCode() {<br /> if (__hashCodeCalc) {<br /> return 0;<br /> }<br /> __hashCodeCalc = true;<br /> int _hashCode = 1;<br /> if (getAddress() != null) {<br /> _hashCode += getAddress().hashCode();<br /> }<br /> if (getEmpNo() != null) {<br /> _hashCode += getEmpNo().hashCode();<br /> }<br /> if (getName() != null) {<br /> _hashCode += getName().hashCode();<br /> }<br /> __hashCodeCalc = false;<br /> return _hashCode;<br /> }<br /><br /> // Type metadata<br /> private static org.apache.axis.description.TypeDesc typeDesc =<br /> new org.apache.axis.description.TypeDesc(Employee.class);<br /><br /> static {<br /> typeDesc.setXmlType(new javax.xml.namespace.QName("http://object.home/", "employee"));<br /> org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();<br /> elemField.setFieldName("address");<br /> elemField.setXmlName(new javax.xml.namespace.QName("", "address"));<br /> elemField.setXmlType(new javax.xml.namespace.QName("http://object.home/", "address"));<br /> elemField.setMinOccurs(0);<br /> typeDesc.addFieldDesc(elemField);<br /> elemField = new org.apache.axis.description.ElementDesc();<br /> elemField.setFieldName("empNo");<br /> elemField.setXmlName(new javax.xml.namespace.QName("", "empNo"));<br /> elemField.setXmlType(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "int"));<br /> elemField.setMinOccurs(0);<br /> typeDesc.addFieldDesc(elemField);<br /> elemField = new org.apache.axis.description.ElementDesc();<br /> elemField.setFieldName("name");<br /> elemField.setXmlName(new javax.xml.namespace.QName("", "name"));<br /> elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));<br /> elemField.setMinOccurs(0);<br /> typeDesc.addFieldDesc(elemField);<br /> }<br /><br /> /**<br /> * Return type metadata object<br /> */<br /> public static org.apache.axis.description.TypeDesc getTypeDesc() {<br /> return typeDesc;<br /> }<br /><br /> /**<br /> * Get Custom Serializer<br /> */<br /> public static org.apache.axis.encoding.Serializer getSerializer(<br /> java.lang.String mechType, <br /> java.lang.Class _javaType, <br /> javax.xml.namespace.QName _xmlType) {<br /> return <br /> new org.apache.axis.encoding.ser.BeanSerializer(<br /> _javaType, _xmlType, typeDesc);<br /> }<br /><br /> /**<br /> * Get Custom Deserializer<br /> */<br /> public static org.apache.axis.encoding.Deserializer getDeserializer(<br /> java.lang.String mechType, <br /> java.lang.Class _javaType, <br /> javax.xml.namespace.QName _xmlType) {<br /> return <br /> new org.apache.axis.encoding.ser.BeanDeserializer(<br /> _javaType, _xmlType, typeDesc);<br /> }<br /><br />}<br /><br />--------------------------------------------------------------------------------------<br />/**<br /> * EmployeeWebService.java<br /> *<br /> * This file was auto-generated from WSDL<br /> * by the Apache Axis WSDL2Java emitter.<br /> */<br /><br />package home.object;<br /><br />public interface EmployeeWebService extends java.rmi.Remote {<br /> public void displayEmp(home.object.Employee employee) throws java.rmi.RemoteException;<br />}<br /><br />--------------------------------------------------------------------------------------<br />/**<br /> * EmployeeWebServiceBindingStub.java<br /> *<br /> * This file was auto-generated from WSDL<br /> * by the Apache Axis WSDL2Java emitter.<br /> */<br /><br />package home.object;<br /><br />public class EmployeeWebServiceBindingStub extends org.apache.axis.client.Stub implements home.object.EmployeeWebService {<br /> private java.util.Vector cachedSerClasses = new java.util.Vector();<br /> private java.util.Vector cachedSerQNames = new java.util.Vector();<br /> private java.util.Vector cachedSerFactories = new java.util.Vector();<br /> private java.util.Vector cachedDeserFactories = new java.util.Vector();<br /><br /> static org.apache.axis.description.OperationDesc [] _operations;<br /><br /> static {<br /> _operations = new org.apache.axis.description.OperationDesc[1];<br /> org.apache.axis.description.OperationDesc oper;<br /> oper = new org.apache.axis.description.OperationDesc();<br /> oper.setName("displayEmp");<br /> oper.addParameter(new javax.xml.namespace.QName("http://object.home/", "Employee"), new javax.xml.namespace.QName("http://object.home/", "employee"), home.object.Employee.class, org.apache.axis.description.ParameterDesc.IN, false, false);<br /> oper.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID);<br /> oper.setStyle(org.apache.axis.constants.Style.DOCUMENT);<br /> oper.setUse(org.apache.axis.constants.Use.LITERAL);<br /> _operations[0] = oper;<br /><br /> }<br /><br /> public EmployeeWebServiceBindingStub() throws org.apache.axis.AxisFault {<br /> this(null);<br /> }<br /><br /> public EmployeeWebServiceBindingStub(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {<br /> this(service);<br /> super.cachedEndpoint = endpointURL;<br /> }<br /><br /> public EmployeeWebServiceBindingStub(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {<br /> if (service == null) {<br /> super.service = new org.apache.axis.client.Service();<br /> } else {<br /> super.service = service;<br /> }<br /> java.lang.Class cls;<br /> javax.xml.namespace.QName qName;<br /> java.lang.Class beansf = org.apache.axis.encoding.ser.BeanSerializerFactory.class;<br /> java.lang.Class beandf = org.apache.axis.encoding.ser.BeanDeserializerFactory.class;<br /> java.lang.Class enumsf = org.apache.axis.encoding.ser.EnumSerializerFactory.class;<br /> java.lang.Class enumdf = org.apache.axis.encoding.ser.EnumDeserializerFactory.class;<br /> java.lang.Class arraysf = org.apache.axis.encoding.ser.ArraySerializerFactory.class;<br /> java.lang.Class arraydf = org.apache.axis.encoding.ser.ArrayDeserializerFactory.class;<br /> java.lang.Class simplesf = org.apache.axis.encoding.ser.SimpleSerializerFactory.class;<br /> java.lang.Class simpledf = org.apache.axis.encoding.ser.SimpleDeserializerFactory.class;<br /> qName = new javax.xml.namespace.QName("http://object.home/", "address");<br /> cachedSerQNames.add(qName);<br /> cls = home.object.Address.class;<br /> cachedSerClasses.add(cls);<br /> cachedSerFactories.add(beansf);<br /> cachedDeserFactories.add(beandf);<br /><br /> qName = new javax.xml.namespace.QName("http://object.home/", "employee");<br /> cachedSerQNames.add(qName);<br /> cls = home.object.Employee.class;<br /> cachedSerClasses.add(cls);<br /> cachedSerFactories.add(beansf);<br /> cachedDeserFactories.add(beandf);<br /><br /> }<br /><br /> private org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {<br /> try {<br /> org.apache.axis.client.Call _call =<br /> (org.apache.axis.client.Call) super.service.createCall();<br /> if (super.maintainSessionSet) {<br /> _call.setMaintainSession(super.maintainSession);<br /> }<br /> if (super.cachedUsername != null) {<br /> _call.setUsername(super.cachedUsername);<br /> }<br /> if (super.cachedPassword != null) {<br /> _call.setPassword(super.cachedPassword);<br /> }<br /> if (super.cachedEndpoint != null) {<br /> _call.setTargetEndpointAddress(super.cachedEndpoint);<br /> }<br /> if (super.cachedTimeout != null) {<br /> _call.setTimeout(super.cachedTimeout);<br /> }<br /> if (super.cachedPortName != null) {<br /> _call.setPortName(super.cachedPortName);<br /> }<br /> java.util.Enumeration keys = super.cachedProperties.keys();<br /> while (keys.hasMoreElements()) {<br /> java.lang.String key = (java.lang.String) keys.nextElement();<br /> _call.setProperty(key, super.cachedProperties.get(key));<br /> }<br /> // All the type mapping information is registered<br /> // when the first call is made.<br /> // The type mapping information is actually registered in<br /> // the TypeMappingRegistry of the service, which<br /> // is the reason why registration is only needed for the first call.<br /> synchronized (this) {<br /> if (firstCall()) {<br /> // must set encoding style before registering serializers<br /> _call.setEncodingStyle(null);<br /> for (int i = 0; i < cachedSerFactories.size(); ++i) {<br /> java.lang.Class cls = (java.lang.Class) cachedSerClasses.get(i);<br /> javax.xml.namespace.QName qName =<br /> (javax.xml.namespace.QName) cachedSerQNames.get(i);<br /> java.lang.Class sf = (java.lang.Class)<br /> cachedSerFactories.get(i);<br /> java.lang.Class df = (java.lang.Class)<br /> cachedDeserFactories.get(i);<br /> _call.registerTypeMapping(cls, qName, sf, df, false);<br /> }<br /> }<br /> }<br /> return _call;<br /> }<br /> catch (java.lang.Throwable t) {<br /> throw new org.apache.axis.AxisFault("Failure trying to get the Call object", t);<br /> }<br /> }<br /><br /> public void displayEmp(home.object.Employee employee) throws java.rmi.RemoteException {<br /> if (super.cachedEndpoint == null) {<br /> throw new org.apache.axis.NoEndPointException();<br /> }<br /> org.apache.axis.client.Call _call = createCall();<br /> _call.setOperation(_operations[0]);<br /> _call.setUseSOAPAction(true);<br /> _call.setSOAPActionURI("displayEmp");<br /> _call.setEncodingStyle(null);<br /> _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);<br /> _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);<br /> _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);<br /> _call.setOperationName(new javax.xml.namespace.QName("", "displayEmp"));<br /><br /> setRequestHeaders(_call);<br /> setAttachments(_call);<br /> java.lang.Object _resp = _call.invoke(new java.lang.Object[] {employee});<br /><br /> if (_resp instanceof java.rmi.RemoteException) {<br /> throw (java.rmi.RemoteException)_resp;<br /> }<br /> extractAttachments(_call);<br /> }<br /><br />}<br /><br />--------------------------------------------------------------------------------------<br />/**<br /> * EmployeeWebServiceService.java<br /> *<br /> * This file was auto-generated from WSDL<br /> * by the Apache Axis WSDL2Java emitter.<br /> */<br /><br />package home.object;<br /><br />public interface EmployeeWebServiceService extends javax.xml.rpc.Service {<br /> public java.lang.String getEmployeeWebServicePortAddress();<br /><br /> public home.object.EmployeeWebService getEmployeeWebServicePort() throws javax.xml.rpc.ServiceException;<br /><br /> public home.object.EmployeeWebService getEmployeeWebServicePort(java.net.URL portAddress) throws javax.xml.rpc.ServiceException;<br />}<br /><br />--------------------------------------------------------------------------------------<br />/**<br /> * EmployeeWebServiceServiceLocator.java<br /> *<br /> * This file was auto-generated from WSDL<br /> * by the Apache Axis WSDL2Java emitter.<br /> */<br /><br />package home.object;<br /><br />public class EmployeeWebServiceServiceLocator extends org.apache.axis.client.Service implements home.object.EmployeeWebServiceService {<br /><br /> // Use to get a proxy class for EmployeeWebServicePort<br /> private final java.lang.String EmployeeWebServicePort_address = "http://127.0.0.1:8080/empoperations/displayEmp";<br /><br /> public java.lang.String getEmployeeWebServicePortAddress() {<br /> return EmployeeWebServicePort_address;<br /> }<br /><br /> // The WSDD service name defaults to the port name.<br /> private java.lang.String EmployeeWebServicePortWSDDServiceName = "EmployeeWebServicePort";<br /><br /> public java.lang.String getEmployeeWebServicePortWSDDServiceName() {<br /> return EmployeeWebServicePortWSDDServiceName;<br /> }<br /><br /> public void setEmployeeWebServicePortWSDDServiceName(java.lang.String name) {<br /> EmployeeWebServicePortWSDDServiceName = name;<br /> }<br /><br /> public home.object.EmployeeWebService getEmployeeWebServicePort() throws javax.xml.rpc.ServiceException {<br /> java.net.URL endpoint;<br /> try {<br /> endpoint = new java.net.URL(EmployeeWebServicePort_address);<br /> }<br /> catch (java.net.MalformedURLException e) {<br /> throw new javax.xml.rpc.ServiceException(e);<br /> }<br /> return getEmployeeWebServicePort(endpoint);<br /> }<br /><br /> public home.object.EmployeeWebService getEmployeeWebServicePort(java.net.URL portAddress) throws javax.xml.rpc.ServiceException {<br /> try {<br /> home.object.EmployeeWebServiceBindingStub _stub = new home.object.EmployeeWebServiceBindingStub(portAddress, this);<br /> _stub.setPortName(getEmployeeWebServicePortWSDDServiceName());<br /> return _stub;<br /> }<br /> catch (org.apache.axis.AxisFault e) {<br /> return null;<br /> }<br /> }<br /><br /> /**<br /> * For the given interface, get the stub implementation.<br /> * If this service has no port for the given interface,<br /> * then ServiceException is thrown.<br /> */<br /> public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {<br /> try {<br /> if (home.object.EmployeeWebService.class.isAssignableFrom(serviceEndpointInterface)) {<br /> home.object.EmployeeWebServiceBindingStub _stub = new home.object.EmployeeWebServiceBindingStub(new java.net.URL(EmployeeWebServicePort_address), this);<br /> _stub.setPortName(getEmployeeWebServicePortWSDDServiceName());<br /> return _stub;<br /> }<br /> }<br /> catch (java.lang.Throwable t) {<br /> throw new javax.xml.rpc.ServiceException(t);<br /> }<br /> throw new javax.xml.rpc.ServiceException("There is no stub implementation for the interface: " + (serviceEndpointInterface == null ? "null" : serviceEndpointInterface.getName()));<br /> }<br /><br /> /**<br /> * For the given interface, get the stub implementation.<br /> * If this service has no port for the given interface,<br /> * then ServiceException is thrown.<br /> */<br /> public java.rmi.Remote getPort(javax.xml.namespace.QName portName, Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {<br /> if (portName == null) {<br /> return getPort(serviceEndpointInterface);<br /> }<br /> String inputPortName = portName.getLocalPart();<br /> if ("EmployeeWebServicePort".equals(inputPortName)) {<br /> return getEmployeeWebServicePort();<br /> }<br /> else {<br /> java.rmi.Remote _stub = getPort(serviceEndpointInterface);<br /> ((org.apache.axis.client.Stub) _stub).setPortName(portName);<br /> return _stub;<br /> }<br /> }<br /><br /> public javax.xml.namespace.QName getServiceName() {<br /> return new javax.xml.namespace.QName("http://object.home/", "EmployeeWebServiceService");<br /> }<br /><br /> private java.util.HashSet ports = null;<br /><br /> public java.util.Iterator getPorts() {<br /> if (ports == null) {<br /> ports = new java.util.HashSet();<br /> ports.add(new javax.xml.namespace.QName("EmployeeWebServicePort"));<br /> }<br /> return ports.iterator();<br /> }<br /><br />}<br /><br />--------------------------------------------------------------------------------------<br />Actual Client Program this is the one which initiates locator and access the server<br />--------------------------------------------------------------------------------------<br />package home.object;<br /><br />import java.net.MalformedURLException;<br />import java.rmi.RemoteException;<br /><br />import org.apache.axis.AxisFault;<br /><br />public class Client {<br /><br /> /**<br /> * @param args<br /> */<br /> public static void main(String[] args) {<br /> Employee employee = new Employee();<br /> employee.setName("Gangadhara Rao D");<br /> employee.setEmpNo(10662);<br /> <br /> Address address = new Address();<br /> address.setStreet("3rd Cross");<br /> address.setCity("Bangalore");<br /> address.setPin(111111);<br /> <br /> employee.setAddress(address);<br /> try {<br /> java.net.URL url = new java.net.URL("http://127.0.0.1:8080/empoperations/displayEmp");<br /> EmployeeWebServiceBindingStub employeeWebServiceBindingStub = new EmployeeWebServiceBindingStub(url, new org.apache.axis.client.Service());<br /> employeeWebServiceBindingStub.displayEmp(employee);<br /> } catch(MalformedURLException mfurle) {<br /> mfurle.printStackTrace();<br /> } catch(AxisFault af) {<br /> af.printStackTrace();<br /> } catch(RemoteException re) {<br /> re.printStackTrace();<br /> }<br /> }<br />}<br />--------------------------------------------------------------------------------------Gangadhara Rao Duvvarapuhttp://www.blogger.com/profile/13863602001434055410noreply@blogger.com0tag:blogger.com,1999:blog-754908438007765335.post-83638916970310742102009-06-29T03:20:00.000-07:002009-06-29T04:24:08.488-07:00Message Driven Bean<div style="text-align: center;"><span id="sort1"><span class="tdvamseel"><span style="color: rgb(153, 51, 153);font-size:180%;" ><span style="font-weight: bold;">Message Driven Bean</span></span></span></span><br /><span id="sort1"><span class="tdvamseel"></span></span></div><span id="sort1"><span class="tdvamseel"><br />Message Driven Bean (MDB) is an enterprise bean which runs inside the EJB container and it acts as Listener for the JMS asynchronous message . It does not have Home and Remote interface as Session or Entity bean. It is called by container when container receives JMS asynchronous message. MDB has to implement MessageListener which has a method onMessage(Message msg). When the container calls the MDB it passes the message to onMesage() method and then MDB process that message.<br /><br /><span style="font-weight: bold;">Example Program:</span><br /><br /><span style="font-weight: bold; font-style: italic;">Server Side Program</span><br /><br />package org.jboss.tutorial.mdb.bean;<br /><br />import javax.ejb.ActivationConfigProperty;<br />import javax.ejb.MessageDriven;<br />import javax.jms.BytesMessage;<br />import javax.jms.Message;<br />import javax.jms.MessageListener;<br /><br />@MessageDriven(activationConfig = {<br /> @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),<br /> @ActivationConfigProperty(propertyName="destination", propertyValue="queue/tutorial/example")<br />})<br />public class ExampleMDB implements MessageListener {<br /> public void onMessage(Message recvMsg) {<br /> System.out.println("----------------");<br /> System.out.println("Received message");<br /> System.out.println("----------------");<br /> System.out.println("Received message object: " + recvMsg);<br /> BytesMessage byteMsg = (BytesMessage) recvMsg;<br /> }<br />}<br /><br /><span style="font-weight: bold; font-style: italic;">Client Side Program<br /></span>package org.jboss.tutorial.mdb.client;<br /><br /><br />import java.io.FileInputStream;<br />import java.util.Properties;<br /><br />import javax.jms.Queue;<br />import javax.jms.QueueConnection;<br />import javax.jms.QueueConnectionFactory;<br />import javax.jms.QueueSender;<br />import javax.jms.QueueSession;<br />import javax.jms.TextMessage;<br />import javax.naming.InitialContext;<br /><br />public class Client {<br /> public static void main(String[] args) throws Exception {<br /> QueueConnection cnn = null;<br /> QueueSender sender = null;<br /> QueueSession session = null;<br /> <br /> Properties props = new Properties();<br /> props.load(new FileInputStream("EJBJNDI.prop")); //<br /> InitialContext ic = new InitialContext(props);<br /> <br /> //InitialContext ctx = new InitialContext();<br /> Queue queue = (Queue) ic.lookup("queue/tutorial/example");<br /> QueueConnectionFactory factory = (QueueConnectionFactory) ic.lookup("ConnectionFactory");<br /> cnn = factory.createQueueConnection();<br /> session = cnn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);<br /><br /> TextMessage msg = session.createTextMessage("Hello World");<br /><br /> sender = session.createSender(queue);<br /> sender.send(msg);<br /> System.out.println("Message sent successfully to remote queue.");<br /><br /> }<br />}<br /><br /></span></span><span style="font-weight: bold;" id="sort1"><span class="tdvamseel">EJBJNDI.prop</span></span><br /><span id="sort1"><span class="tdvamseel">java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory<br />java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces<br />java.naming.provider.url=localhost:1099<br /></span></span>Gangadhara Rao Duvvarapuhttp://www.blogger.com/profile/13863602001434055410noreply@blogger.com0tag:blogger.com,1999:blog-754908438007765335.post-84640042440514018482009-06-29T02:44:00.000-07:002009-06-29T03:16:56.755-07:00Web Service Security<div style="text-align: center;"><span style="font-weight: bold; color: rgb(102, 0, 204);font-family:times new roman;font-size:130%;" ><span style="font-size:180%;">Web Service Security Encryption with Rampart 1.4 and Axis2 1.4.1</span><br /></span><div style="text-align: left;"><span style="color: rgb(204, 51, 204);font-size:130%;" ><br /><span style="font-weight: bold; color: rgb(153, 51, 153);">Writing Client Based on the .JKS and .CER files</span></span><br /><ul><li>Download axis2-1.4.1-bin.zip (Standard Binary Distribution) from axis site, the URL is http://ws.apache.org/axis2/download/1_4/download.cgi</li><li>Download rampart-dist-1.4-bin.zip (Standard Binary Distribution) from Apache Rampart, the URL is http://ws.apache.org/rampart/download/1.4/download.cgi</li><li>Copy these 2 zip files in C:\ and extract it.</li></ul><span style="color: rgb(153, 51, 153);font-size:130%;" ><span style="font-weight: bold;">Creating Project in Eclipse AND CREATING CLIENT AND STUB</span></span><br /><ul><li>Create a new Project in C:\ using Eclipse with the name TestWSS. File --> New --> Java Project</li><li>Set your class path to JAVA_HOME</li><li>Open Command Prompt and Go to C:\axis2-1.4.1-bin\axis2-1.4.1\bin</li><li>Execute axis2.bat</li><li>Copy your wsdl file into C:\axis2-1.4.1-bin\axis2-1.4.1\bin (Assume the wsdl file name is meal.wsdl).</li><li>Execute the below command from command prompt<br /></li><li>C:\axis2-1.4.1-bin\axis2-1.4.1\bin>wsdl2java -uri C:\axis2-1.4.1-bin\axis2-1.4.1\bin\meal.wsdl</li><li>After executing the above command you will get the stub and Handler class in the C:\axis2-1.4.1-bin\axis2-1.4.1\bin with package.<br /></li></ul><span style="color: rgb(153, 51, 153);font-size:130%;" ><span style="font-weight: bold;">Placing Client Files in Project SRC and applying signature through Rampart 1.4</span></span><br /><ul><li><span style="color: rgb(0, 0, 0);">Copy generated file into C:\TestWSS\src folder.</span></li><li><span style="color: rgb(0, 0, 0);">Create a folder parallel to src with the name client-repo and copy module directory from C:\rampart-dist-1.4-bin\rampart-1.4\ to C:\TestWSS\client-repo.<br /></span></li><li><span style="color: rgb(0, 0, 0);">This module folder should contain rampart-1.4.mar and addressing-1.41.mar</span></li><li><span style="color: rgb(0, 0, 0);">Add all .jar files present in the C:\rampart-dist-1.4-bin\rampart-1.4\lib directory needs to add to the Eclipse Project build path.</span></li><li><span style="color: rgb(0, 0, 0);">Add all .jar files present in the C:\axis2-1.4-bin\axis2-1.4\lib directory needs to add to the Eclipse Project build path.</span></li><li><span style="color: rgb(0, 0, 0);">Refresh the project in Eclipse and compile it this time you won’t get any compilation errors because we already set the required jars to the class path.</span></li></ul><span style="color: rgb(153, 51, 153);font-size:130%;" ><span style="font-weight: bold;">Writing Client Policy File</span></span><br /><wsp:policy wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"><wsp:exactlyone><wsp:all><sp:asymmetricbinding sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"><wsp:policy><sp:initiatortoken><sp:algorithmsuite><sp:recipienttoken><sp:algorithmsuite><sp:wss10 sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"><wsp:policy><wsp:policy wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"></wsp:policy></wsp:policy></sp:wss10></sp:algorithmsuite></sp:recipienttoken></sp:algorithmsuite></sp:initiatortoken></wsp:policy></sp:asymmetricbinding></wsp:all></wsp:exactlyone></wsp:policy><wsp:policy wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"><wsp:exactlyone><wsp:all><sp:asymmetricbinding sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"><wsp:policy><sp:initiatortoken><sp:algorithmsuite><sp:recipienttoken><sp:algorithmsuite><sp:wss10 sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"><wsp:policy>As you can see, the above security policy contains two main security assertions: an asymmetric binding assertion and a signed parts assertion. Asymmetric binding defines what keys to be used and a few additional properties such as which algorithms to be used in cryptographic operations, layout of the security header, etc. Signed parts assertion defines what parts of the message should be signed. In this tutorial we will be signing the SOAP body of the message.</wsp:policy></sp:wss10></sp:algorithmsuite></sp:recipienttoken></sp:algorithmsuite></sp:initiatortoken></wsp:policy></sp:asymmetricbinding></wsp:all></wsp:exactlyone></wsp:policy></div></div>Gangadhara Rao Duvvarapuhttp://www.blogger.com/profile/13863602001434055410noreply@blogger.com0tag:blogger.com,1999:blog-754908438007765335.post-16503071601940118692009-06-29T00:28:00.000-07:002009-06-29T06:33:06.686-07:00Web Service Creation using tools<p><strong><span style="color: rgb(102, 255, 255);"><span style="color: rgb(102, 0, 204);">What are Web Services?</span><br /></span></strong>* Web services are application components<br />* Web services communicate using open protocols<br />* Web services are self-contained and self-describing<br />* Web services can be discovered using UDDI<br />* Web services can be used by other applications<br />* XML is the basis for Web services<br /><strong><span style="color: rgb(102, 0, 204);">How Does it Work?</span><br /></strong>* The basic Web services platform is XML + HTTP.<br />* XML provides a language which can be used between different platforms and languages and still express complex messages and functions.<br />* The HTTP protocol is the most used Internet protocol.<br />* Web services platform elements:SOAP (Simple Object Access Protocol)</p><p>* UDDI (Universal Description, Discovery and Integration)</p><p>* WSDL (Web Services Description Language)We will explain these topics later in the tutorial.</p><p><strong><span style="color: rgb(255, 102, 0);">Writing Web Service</span></strong></p><p><span style="font-weight: bold;"><span style="color: rgb(102, 0, 204);">Writing a sample Web Service Application. Create POJO classes, the below are the sample Code</span><br /></span></p><p><span style="font-weight: bold;"></span>///////////////////////////////////////////////////////////////////////////////// </p><p><br />package com.marlabs.gangadhar;<br />public class Address {<br />private String street;<br />private String city;<br />private Long pin;<br />/**<br />* @return the city<br />*/<br />public String getCity() {<br />return city;<br />}<br />/**<br />* @param city the city to set<br />*/<br />public void setCity(String city) {<br />this.city = city;<br />}<br />/**<br />* @return the pin<br />*/<br />public Long getPin() {<br />return pin;<br />}<br />/**<br />* @param pin the pin to set<br />*/<br />public void setPin(Long pin) {<br />this.pin = pin;<br />}<br />/**<br />* @return the street<br />*/<br />public String getStreet() {<br />return street;<br />}<br />/**<br />* @param street the street to set<br />*/<br />public void setStreet(String street) {<br />this.street = street;<br />}<br />}</p><p>////////////////////////////////////////////////////////////////////////////////</p><p><br />package com.marlabs.gangadhar;<br />public class Employee {<br />private String name;<br />private String empno;<br />private Address address;<br />/**<br />* @return the address<br />*/<br />public Address getAddress() {<br />return address;<br />}<br />/**<br />* @param address the address to set<br />*/<br />public void setAddress(Address address) {<br />this.address = address;<br />}<br />/**<br />* @return the empno<br />*/<br />public String getEmpno() {<br />return empno;<br />}<br />/**<br />* @param empno the empno to set<br />*/<br />public void setEmpno(String empno) {<br />this.empno = empno;<br />}<br />/**<br />* @return the name<br />*/<br />public String getName() {<br />return name;<br />}<br />/**<br />* @param name the name to set<br />*/<br />public void setName(String name) {<br />this.name = name;<br />}<br />}</p><p>/ ///////////////////////////////////////////////////////////////////////////////// <strong style="color: rgb(102, 0, 204);"></strong></p><p><span style="font-weight: bold; color: rgb(102, 0, 204);">Write the web service implementation class, below is the sample code</span><br /></p><p>package com.marlabs.gangadhar;<br /><br />import javax.ejb.Stateless;<br />import javax.jws.WebMethod;<br />import javax.jws.WebParam;<br />import javax.jws.WebService;<br />import javax.jws.soap.SOAPBinding;<br /><br />import org.jboss.wsf.spi.annotation.WebContext;<br /><br />@WebService(name = "Employee", targetNamespace = "http://gangadhar.marlabs.com/")<br />@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)<br />@WebContext(contextRoot = "/operations", urlPattern = "/sendEmployeeInfo")<br />@Stateless()<br />public class EmpWebImp {<br /> @WebMethod(operationName = "sendEmployeeInfo", action = "sendEmployeeInfo")<br /> public void sendEmployeeInfo(@WebParam(name = "Employee", targetNamespace = "http://gangadhar.marlabs.com/", partName = "employee")<br /> Employee employee) {<br /> System.out.println("Employee Name: " + employee.getName());<br /> System.out.println("Employee No : " + employee.getEmpno());<br /> Address address = employee.getAddress();<br /> System.out.println("Street : " + address.getStreet());<br /> System.out.println("City : " + address.getCity());<br /> System.out.println("PIN : " + address.getPin());<br /> }<br />}<br /><br /></p><p>/////////////////////////////////////////////////////////////////////////////////</p><p>Once you deploy the above code successfully in any application server, the server will automatically creates the .wsdl file</p><p>to see the wsdl file in Jboss server after successfull deployment, type the below url in browser.</p><p><a href="http://192.168.33.79:8080/jbossws/">http://192.168.33.79:8080/jbossws/</a> and then press enter you can able to view the services running the JBoss server. If you click on the link which the service is running it will displays the complete WSDL file. Save that wsdl into any one physical location which is the base to write the Web service client program.</p><p><strong><span style="color: rgb(255, 102, 0);">Writing Web Service Client</span></strong></p><p>To generate the client side stub and locator classes we have to have wsdlToJava.jar, and path should be set to JDK.</p><p>Assume we have saved wsdl file in C:\ the wsdl name is Employee.wsdl</p><p>1. Open Command prompt goto C:\</p><p>2. Set the Java Path and also set the class path to wsdlToJava.jar file</p><p>3. Execute the following command from command prompt.</p><p>C:\>java org.apache.axis.wsdl.WSDL2Java Employee.wsdl</p><p>4. It will generate all the classes under the appropriate packages.</p><p>5. You need to change the URL in the Locator class.</p>Gangadhara Rao Duvvarapuhttp://www.blogger.com/profile/13863602001434055410noreply@blogger.com0