Posts

defining functions clojure

(defn saysomething      " i dont want to talk to you"      [name]      (str "why is it so?" name)) #'my-clojureproject1.core/saysomething => (println (saysomething "anjana") => (defn saymorethings "what do you want to hear" [name] (str "life is a box of chocolates" name)) #'my-clojureproject1.core/saymorethings => (println (saymorethings "nirosha")             ) life is a box of chocolatesnirosha nil

Learning clojure day-1

;; Clojure 1.6.0 => (count a[eee ttt tt]) CompilerException clojure.lang.ArityException: Wrong number of args (2) passed to: core/count--inliner, compiling:(C:\Users\\AppData\Local\Temp\form-init7824848865457405872.clj:1:1) => (count [eee tt 565 dfsxf 889 dfgd]) CompilerException java.lang.RuntimeException: Unable to resolve symbol: eee in this context, compiling:(C:\Users\\AppData\Local\Temp\form-init7824848865457405872.clj:1:1) => (count ["aaa" "ddd" 56 45 ""]) 5 => (def storages["ssss" "sddsdsd" "333dsfsd"]) #'my-clojureproject1.core/storages => (first storages) ssss => (second storages) sddsdsd => (last storages) 333dsfsd => (nthext storages 2) CompilerException java.lang.RuntimeException: Unable to resolve symbol: nthext in this context, compiling:(C:\Users\am055849\AppData\Local\Temp\form-init7824848865457405872.clj:1:1) => (nthnext storages 2) ("333dsfsd") =...

Deploy 2 spring .war with different context on JBOSS 7 AS

Image
Assume you have 2 applications SpringApp1.war SpringApp2.war when you try to deploy both on JBOSS 7 AS,  you will may see some error like this: Exception sending context initialized event to listener  instance of class org.springframework.web.util.Log4jConfigListener  java.lang.IllegalStateException: Web app root system property already set to  a different value: 'webapp.root' = [E:\jboss-as-7.1.1.Final\standalone\deployments\SpringApp1.war] instead of [E:\jboss-as-7.1.1.Final\standalone\deployments\SpringApp2.war]  - Choose unique values for the 'webAppRootKey'  context-param in your web.xml  ensure you add the below context param in web.xml of both the .war files:

How to get count of distinct column in ORACLE

select   DISTINCT COL_NAME_1,count( DISTINCT COL_NAME_2) as COUNT from TABLE_NAME   group by COL_NAME_1 ;

Compare Text in 2 files and write the difference in a new file

Here I am reading 2 files, first file data is added to list.second file data is added to another list.Then converting 2 list to 2 Hashset. Then i am removing 1st hashset from the 2nd one.In this process all the common string will get removed and the new Hashset will have the difference data. /**  * Getting 2 text files with single column data in each, need to find out the difference and write the difference between the 2 files to a new file.  */ public class CompareTwoFiles { public static List readcsv(String filename) { List l=new ArrayList(); String tempstr = ""; String dataStr = ""; int rownum = 0; try { BufferedReader br = new BufferedReader(new FileReader(filename)); try { String line = ""; while ((line = br.readLine()) != null) { l.add(line); // System.out.println(dataStr); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); ...

Capture AJAX response and assign to a variable using JQUERY

function checkforduplicateempname(){  var message=true;  /*Assigning AJAX response to a javascript variable*/  var empId = $.ajax({    url: 'checkforduplicateempname.relay',    data: oMyForms,    cache: false,    contentType: false,    processData: false,    global: false,    async:false,    type: 'POST',    success: function(data){     return data;        },error:function(){     $("#empname").notify("Unable to check for duplicate title.","error");        } }).responseText; //end of ajax capturing the response     if(empId!='0'){     $("#empaname").notify("Duplicate Title.","error");     message=false;     } return message; }//end of function

How to retain the space of the td after hidding it in Jquery

Image
If you use the following code snippet to hide and show tds- the UI will get disturbed. The next corresponding td will get shifted to the hidden td space.    var tablevar="#"+myTable;  $(tablevar+' tr:eq('+i+')').find('td:eq(3)').show();    $(tablevar+' tr:eq('+i+')').find('td:eq(2)').show(); So how to retain the td space and still achieve the functionality. use the this code snippet.    var tablevar="#"+myTable; $(tablevar+' tr:eq('+i+')').find('td:eq(3)').css("visibility", "hidden");  $(tablevar+' tr:eq('+i+')').find('td:eq(2)').css("visibility", "hidden");  $(tablevar+' tr:eq('+i+')').find('td:eq(4)').css("visibility", "visible");

How to extend a JSON array in Jquery

Suppose you get a JSON  Object like this var optionsoptions;  $.getJSON("relaytemplateattributes.json" , function(result){ optionsoptions=result.optionsoptions;  }); /*JSON LIST FORMAT*/ {"optionsoptions":[{"OPTIONID":-1,"COMBOITEM":"---SELECT--"},{"OPTIONID":1,"COMBOITEM":"-3U0Comp"}, {"OPTIONID":1,"COMBOITEM":""},{"OPTIONID":1,"COMBOITEM":"-U2comp"}, {"OPTIONID":1,"COMBOITEM":"Ipol"},{"OPTIONID":1,"COMBOITEM":"-U2"}, {"OPTIONID":1,"COMBOITEM":"-3U0"},{"OPTIONID":1,"COMBOITEM":"Dual"}, {"OPTIONID":2,"COMBOITEM":"0 deg"},{"OPTIONID":2,"COMBOITEM":"180 deg"} {"OPTIONID":3,"COMBOITEM":"1 out of 3"},{"OPTIONID":3,"CO...

Jquery Table Inline Edititing

https://jsfiddle.net/anjana6/yc1o97kL/5/embedded/result/ The Above link demonstrates inline editing of jquery. The  idea used to implement  is as follows: Table consists of two identical rows  first one is Parent row which is non editable Second one is Editable child row. By Default the Parent row is visible and on click on edit the parent row is hidden and child row is displayed. Save data displays all the modified row records and it stores it in a hidden string.

Convert Excel to XML in JEXCEL API

package com.relaytemplate.data; import java.io.*; import jxl.*; import jxl.demo.XML; import jxl.read.biff.BiffException; import java.util.*; import java.sql.*; public class ExceltoXML{ // public void readExcelFile() { public static void main(String args[]) throws BiffException, IOException{ File f = new File("TestConsolidated.xml"); OutputStream os = (OutputStream) new FileOutputStream(f); String encoding = "UTF8"; OutputStreamWriter osw = new OutputStreamWriter(os, encoding); String filename = "relaytemplate.xls"; WorkbookSettings ws = new WorkbookSettings(); ws.setLocale(new Locale("en", "EN")); Workbook w = Workbook.getWorkbook(new File(filename), ws); try { XML myxml=new XML(w,os,filename, false); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }

Spring JDBC Template- To get back the inserted values using Keyholder

public List insert(final Action action){ final String insertIntoSql ="INSERT INTO MIPUSER_ACTIONS(IACTIONID, SACTIONNAME) VALUES (nextval('SEQ_MIPUSER_ACTIONS'),?)"; KeyHolder holder = new GeneratedKeyHolder(); jdbcTemplate.update(new PreparedStatementCreator() {                            @Override                 public PreparedStatement createPreparedStatement(Connection connection)                         throws SQLException {                     PreparedStatement ps = connection.prepareStatement(insertIntoSql.toString(), Statement.RETURN_GENERATED_KEYS);                     ps.setString(1, action.getAction_name());                     retu...

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.

What are the Front ends Provided by Apache CXF

JAX-WS JAX-RS Simple JavaScript

What is Bindings in Webservice and types of Bindings

Bindings: Maps a webservice message to the protocol. Types of Bindings: SOAP bindings: Maps a webservice message to a SOAP service Pure XML Bindings :sends a raw xml message HTTP Bindings :Maps webservice message using a RESTFUL service.