Monday, January 21, 2013

eclipse tomcat startup: Reveal end of document error( internal Error)

 

I am not sure if this is the root cause, however when i do the below the error is gone….

  1. restart eclipse; right click inn console; go to preferences
  2. make sure u select the below options and as these are

image

if u unselect the checkbox: limit console output and if u r console generates a lot of print stmts u get the error.

Thursday, November 15, 2012

Q

image

Super kiran… I am so proud of u… Even in such difficult situations u r taking a very good stand

Saturday, November 10, 2012

Q

విమల పటి, కమల కుటి,
పుస్తక రుద్రాక్ష శస్త్ర హస్త పుటి,
కామాక్షి పక్ష్మలాక్షి కలిత విపంక్షి విభాసి వైరించి!!

మనోజపం మరుతతుల్యవేగం
జితేంద్రియం బుద్ధి మతాన్బరిస్థం
వాతాత్మజం వానరయూధ ముఖ్యం
శ్రీరామ దూతం సిరసానమామి 

Monday, November 5, 2012

Simulating network packet loss

Recently i had to simulate packet loss to test an application
At first i tried netem; however it errored out

[root@prithvivm3 ~]# /sbin/tc qdisc change dev eth0 root netem loss 0.1%
RTNETLINK answers: No such file or directory
i tried very hard, but couldnt fix this so tried packet loss using iptable
first i had to upgrade my current iptable

--> to install the iptables use the below command
# rpm -Uvh http://ftp.srce.hr/redhat/extras/el5/x86_64/iptables-1.3.5-5.3.el5_4.3.x86_64.rpm http://ftp.srce.hr/redhat/extras/el5/x86_64/iptables-ipv6-1.3.5-5.3.el5_4.3.x86_64.rpm

--> clear all rules of iptables
# iptables --flush
--> run the below command to view all rules in iptables. the below should not return any rules
#/sbin/iptables -vnL INPUT --line-numbers

--> now use the below to add a new rule. here we are telling IPTables to drop 1 packet for every 10 packets statistically random
The above returns all rules configured. as we said flush before this it will return a single line. now run the below command to add a rule
# iptables -A INPUT -m statistic --mode random --probability 0.1 -j DROP

--> save the above rule to ip tables file
# /etc/init.d/iptables save
--> view all rules of iptables
#/sbin/iptables -vnL INPUT --line-numbers

--> it should be visible as below
Chain INPUT (policy ACCEPT 5328 packets, 673K bytes)
num   pkts bytes target     prot opt in     out     source               destination
1     3510  480K DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           statistic mode random probability 0.100000

--> so we added our rule successfully

--> now restart the iproute table for the above rules to take affect
# /etc/init.d/iptables restart



to monitor the packets run the below command
watch 'iptables -vL'

the output will be as follows
Every 2.0s: iptables -vL  Mon Nov  5 14:17:13 2012

Chain INPUT (policy ACCEPT 5680 packets, 702K bytes)
 pkts bytes target     prot opt in     out     source               destination
 3726  496K DROP       all  --  any    any     anywhere             anywhere            statistic mode random probability 0.400000

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 7336 packets, 593K bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain LOGGING (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain RH-Firewall-1-INPUT (0 references)
 pkts bytes target     prot opt in     out     source               destination



After having done the above .. i ran my client that tries to communicate to server on plain sockets.

Learning:
Initially i was expecting some issues... 'cos we are dropping packets that are going to the socket. So on server side i was expecting server to read some wrong data/ throw some array out of bound exception. however no such thing had happend. I am trying to understand it.

So... In transport layer two things happen
  1. The packets are checked for corruption; by CRC- cyclic redundancy check of the packet data
  2. packet sequencing; 
if any of the above is not valid/ out of sequence tcp/ip layer takes corrective action i.e.. ignore the packets and then ask for a resend. My initial belief was the packets get dropped (because of iptables rules is) after the above check is done. But when running the experiment using VI editor; or when my local windows java program was sending bytes tothe linux server.. i never noticed server misbehaving. Atmost i could see was only delay in communication; as such server was never getting incorrect data/ garbled data from the socket.

so by this I think...
  1. the CRC check is first done (at hardware lever in ether net card)
  2. then the packets are sent to the OS layer
  3. before which (i.e.. before the point 2 above) the packets are intercepted and acted upon
  4. Now the packet drop(by iptables rules) happens (ie.. in point 3 above) and then it reaches the OS layer
  5. OS layer now checks for sequencing and because packet drop (of point 4) has happened asks the tcpip to re-fetch the full packet.
Given this understanding.. i m wondering what will happen if in iptables we asked to drop all packets fro a given ip; will...
  1. OS keep indefinitely asking for resend?
  2. or as OS is totally unaware of the packets it would just ignore.
i was trying to get an evidence to the above points; however couldnt... so incase u find any please let me know the same...






Wednesday, October 3, 2012

Apache: fall-back mechanism

 

This is the recent requirement that i had faced w.r.t. virtual hosts.

  1. at a given location see if the static resource exist
  2. if it exist then serve form that location
  3. otherwise fallback to a default location

after a day of investigation… this was the solution i finally discovered

 

NameVirtualHost *:81
#telling virtual host to listen on this port
<VirtualHost *:81>
ErrorLog logs/rewrite-log
CustomLog logs/rewrite-log combined
DocumentRoot E:/proj/nono2_2_10_3/config/
LogLevel debug

<IfModule rewrite_module>
RewriteLog logs/rewrite.log
RewriteLogLevel 3
</IfModule>

RewriteEngine on
    #if the file at the below path doesnt exist then the rule applies. Both these are part of the same rule
RewriteCond %{DOCUMENT_ROOT}httpd/templates-mobile/js/$3 !-f
    #rule is to serve the files from default templates folder and skip the next rule (see s=1). Make this rule as the last rule(see L)
    #note the $1,$2,$3 are interpreted from he below rule. Each ‘()’ represents $n. where n increments per bracket
    # the above rewriteCond take $1,2,3 from this rule below
RewriteRule ^(/ui)(/tpl/js)(.+)$ %{DOCUMENT_ROOT}httpd/templates/js/$3 [L,S=1]
    #serve from templates-mobile folder     
RewriteRule ^(/ui)(/tpl/js)(.+)$ %{DOCUMENT_ROOT}httpd/templates-mobile/js/$3 [L]

</VirtualHost>




Hope this helps somebody…

Wednesday, August 22, 2012

Downloading a complete page from website

when working with css or js we often convenient to get the website page on our desktop. We generally endup saving as html, then saving each of the css and js files. I discovered an easier way to do the same.

This is supported in linux or cygwin (linux version on windows). Run this command

Command
wget -E -H -k -K -p http://www.something.com

Monday, July 23, 2012

Generating gradiants with out using images


This is written in JQuery. Below is the code.


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" > </script>

<script>
$(function(){
gradiant('div.newGradiant',[255,0,0],[0,0,0]);
});

function gradiant(selector,rgb1,rgb2){
var $src = $(selector);
var height = $src.height()*1;
$src.css('background','yellow');
var x = $src.offset().left + $src.width();
var y = $src.offset().top;
//var r=256,g=256;b=256;
var r=rgb1[0],g=rgb1[1];b=rgb1[2];
var rr=rgb2[0],gg=rgb2[1];bb=rgb2[2];
for(var i=0;i<height;i++){
var tr= Math.round(r+((rr-r)*i/height));
var tg=Math.round(g+((gg-g)*i/height));
var tb=Math.round(b+((bb-b)*i/height));
var newColor = hex(tr)+hex(tg)+hex(tb);
var div =('<DIV style="BORDER-BOTTOM: #ffffff 0px;'
+' BORDER-LEFT: #ffffff 0px solid; BACKGROUND-COLOR: '
+'#'+ newColor +'; MIN-HEIGHT: 1px; HEIGHT:'
+' 1px; FONT-SIZE: 1px; OVERFLOW: hidden; BORDER-TOP: '
+'#ffffff 0px; BORDER-RIGHT: #ffffff 0px solid"></DIV>');
$src.append($(div));
}
}

var hexDigits = new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"); 

function hex(x) {
return isNaN(x) ? "00" : hexDigits[(x - x % 16) / 16] + hexDigits[x % 16];
}

</script>

<div class="newGradiant" style="width:100px; height:200px; background:yellow; border: 1px solid black">

 
This generates the gradiant as follows. The algo can be modified to take the edge rgb values and then do the magic. This is just a naive example ;)
Tested this on IE-7, IE-8, IE-9. Chrome 20.0, firefox 13.0 version.



image


The only issue i see is when we combine this with jQuery corner apis. The results are working in IE but not in chrome!!!

eclipse: deploying classpath jars into tomcat container

Aaaah! this is a big pain.. u will have all jars in classpath, and when u say run as server they dont get copied to the server. the Fix is simpl ( eclipse should have taken care of it by default.. however.. ).

  1. click on the poject,
  2. press ctrl + enter.
  3. Now u see a properties window of the project
  4. search for deployment assemble and click on it.
  5. Now in web-deployment assembly plane click on add button
  6. select java build path entities
  7. click on next. now select all jars (ctrl + a); then OK
  8. now click finish.

Deploy the stuff on tomcat and u will see classpath entities are being copied to the server

image

Sunday, July 8, 2012

Near Random number… 2

In continuation to my previous post.. i made a few more refinements and made the program more simple..

  • The advantage of this new one is it allows the total digits we want to alter w.r.t the previous one.
  • we can dictate the number of variants between consecutive integers

it reads as follows

import java.util.Random;

public class NearRandomIncrements2 {
private static final Random rand = new Random(99L);
private static final int maxVariants = 10;
private static final int maxVariableDigits = 10000;
private static int[] variantArr = new int[maxVariants];
private static int[] cummulativeArr = new int[maxVariants];
private static int sum;

static {
for (int i = 0; i < maxVariants; i++) {
int nextVariant = Math.abs(rand.nextInt()) % maxVariableDigits;
variantArr[i] = nextVariant;
sum += nextVariant;
cummulativeArr[i] = sum;
System.out.println(">>" + nextVariant + " cumm:" + cummulativeArr[i]);
}
}

public static void main(String[] s) {
long prev = 0;
for (long i = 0L; i < 40; i++) {
int index = (int) (i % (maxVariants));
long cycles = (i / (maxVariants)) + 1;
long newVal = cycles + cummulativeArr[index] + index;
if (newVal < 0) {
newVal = Long.MAX_VALUE + newVal + 1;
}
// if (newVal >= 0 && newVal < 100) {
System.out.println(i + " new no:" + newVal + " cycle:" + cycles + " variant:" + (newVal - prev));
// }
prev = newVal;
}
}
}



For the given maxVariable digits the random numbers generated are as follows

>>5722 cumm:5722
>>6916 cumm:12638
>>4859 cumm:17497
>>1273 cumm:18770
>>696 cumm:19466
>>3525 cumm:22991
>>5948 cumm:28939
>>9283 cumm:38222
>>5856 cumm:44078
>>9198 cumm:53276



The numbers remain the same on multiple runs also.

0 new no:5723 cycle:1 variant:5723
1 new no:12640 cycle:1 variant:6917
2 new no:17500 cycle:1 variant:4860
3 new no:18774 cycle:1 variant:1274
4 new no:19471 cycle:1 variant:697
5 new no:22997 cycle:1 variant:3526
6 new no:28946 cycle:1 variant:5949
7 new no:38230 cycle:1 variant:9284
8 new no:44087 cycle:1 variant:5857
9 new no:53286 cycle:1 variant:9199
10 new no:5724 cycle:2 variant:-47562
11 new no:12641 cycle:2 variant:6917
12 new no:17501 cycle:2 variant:4860
13 new no:18775 cycle:2 variant:1274
14 new no:19472 cycle:2 variant:697
15 new no:22998 cycle:2 variant:3526
16 new no:28947 cycle:2 variant:5949
17 new no:38231 cycle:2 variant:9284
18 new no:44088 cycle:2 variant:5857
19 new no:53287 cycle:2 variant:9199
20 new no:5725 cycle:3 variant:-47562
21 new no:12642 cycle:3 variant:6917
22 new no:17502 cycle:3 variant:4860
23 new no:18776 cycle:3 variant:1274
24 new no:19473 cycle:3 variant:697
25 new no:22999 cycle:3 variant:3526
26 new no:28948 cycle:3 variant:5949
27 new no:38232 cycle:3 variant:9284
28 new no:44089 cycle:3 variant:5857
29 new no:53288 cycle:3 variant:9199
30 new no:5726 cycle:4 variant:-47562
31 new no:12643 cycle:4 variant:6917
32 new no:17503 cycle:4 variant:4860
33 new no:18777 cycle:4 variant:1274
34 new no:19474 cycle:4 variant:697
35 new no:23000 cycle:4 variant:3526
36 new no:28949 cycle:4 variant:5949
37 new no:38233 cycle:4 variant:9284
38 new no:44090 cycle:4 variant:5857
39 new no:53289 cycle:4 variant:9199
if u observe no two numbers are related to each other; and to know the sequence we need to see atleast 30 consecutive numbers (say we have maxVariant by 10 numbers) So by putting the maxVariants a high number and giving the gerated numbers to a trusted client we may use this algo to generate proxies not loosing even one number in the seq bts 0-> Long.Max_Value
any better soln?