Friday, April 26, 2013
Q
Wednesday, February 27, 2013
Q
రక్షణలు వేయి కలిగిన సిక్షితుడగు ఖలుడు పాప చిత్తున్ డగుటన్ !!
-బమ్మెర పోతన
Saturday, February 9, 2013
Friday, February 8, 2013
Wednesday, February 6, 2013
Spring register a new JSON Converter
Yesterday I had to modify the JSON during creation from an object. I want to add validation hints along with the json that travelled to the server. Spring has converters and uses MappingJacksonHttpMessageConverter to convert the object returned by the controller. SO i want to modify the converter to include the hints in the JSON generated.
A lot of googling happened for no luck finally I got the solution which reads as follows
First override the default handler: MappingJsonHttpMessageConverter
public class JSONHttpMessageConverter extends MappingJacksonHttpMessageConverter {
…
…
@Override
protected void writeInternal(Object object, HttpOutputMessage outputMessage) throws IOException,
HttpMessageNotWritableException {
now in spring xml modify the mvc:annotation-config; Please make sure that u dont have another annotation-config with in any of the spring xmls in ur classpath.
<mvc:annotation-driven validator="ExtendedValidatationAdaptor" >
<mvc:message-converters register-defaults="true" >
<bean class="wavecrest.foundation.validate.web.JSONHttpMessageConverter" p:somebean-ref="somref" />
</mvc:message-converters>
</mvc:annotation-driven>
and this should do.
Tested with spring-web-3.1.1.RELEASE.jar
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….
- restart eclipse; right click inn console; go to preferences
- make sure u select the below options and as these are
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
Saturday, November 10, 2012
Q
పుస్తక రుద్రాక్ష శస్త్ర హస్త పుటి,
కామాక్షి పక్ష్మలాక్షి కలిత విపంక్షి విభాసి వైరించి!!
మనోజపం మరుతతుల్యవేగం
జితేంద్రియం బుద్ధి మతాన్బరిస్థం
వాతాత్మజం వానరయూధ ముఖ్యం
శ్రీరామ దూతం సిరసానమామి
Monday, November 5, 2012
Simulating network packet loss
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
- The packets are checked for corruption; by CRC- cyclic redundancy check of the packet data
- packet sequencing;
- the CRC check is first done (at hardware lever in ether net card)
- then the packets are sent to the OS layer
- before which (i.e.. before the point 2 above) the packets are intercepted and acted upon
- Now the packet drop(by iptables rules) happens (ie.. in point 3 above) and then it reaches the OS layer
- OS layer now checks for sequencing and because packet drop (of point 4) has happened asks the tcpip to re-fetch the full packet.
- OS keep indefinitely asking for resend?
- or as OS is totally unaware of the packets it would just ignore.
Wednesday, October 3, 2012
Apache: fall-back mechanism
This is the recent requirement that i had faced w.r.t. virtual hosts.
- at a given location see if the static resource exist
- if it exist then serve form that location
- 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…