Posts

Java use different methods as mock in different environments

Many a time we feel that there should be a way by which we can invoke different functionality in a flow depending on the environment. How great it would be if in development environment one can just mock the database or any other external call and return dummy data for debugging purpose. However. , there are existing frameworks for testing like Mockito which let one simulate external objects by mocking return objects. Spring profile is also helpful to an extent by creating different profiles. All these existing frameworks are good for either testing or running code in any live environment, but for the desktop IDE based environment it is too much work to set them up. I wanted a simple approach that there should be some library which I can include and annotate my code to use a different method instead of real one in "test" and "development" environment. So I created one which is easy to use with no code pollution for myself. Since I find it good to use, I am sh...

find a jar file by the name of class

A utility to find the text from archives. This strain is specifically useful for finding the particular jar file if it contains the given class. Use it freely on any Unix and Linux platform. for f in `find $1 -name "*.jar"` do if [ `jar tf $f | grep "class" | sed 's|/|.|g' | grep $2 | wc -l` -gt 0 ] ; then echo $f fi done Example usage: $ ./jarFinder . com.ibm.ws.webservices.engine.description.OperationDesc Output ./libs/Lib/com.ibm.ws.runtime.jar ./libs/Lib/com.ibm.ws.runtime.jar

find a file by content with line number on unix linux platform

Find a file on linux/ unix/ cygwin platform by the content. This inline script will give the name of the file, line number of searched text in nested directories. Find command adds the selection of file and can be used to accommodate others variations like since date modified, file type etc. find . -name "*.java" -exec grep -H -n "express" '{}' \; Example Output ./com/abc/HttpRequestInterceptor.java:120:           if (StringUtils.isEmpty(request.getHeader("express"))) { ./com/abc/HttpRequestInterceptor.java:123:           if (!request.getHeader("xxxxx").equalsIgnoreCase("true")) { ./com/abc/xyz.java:10: *  either expressed or implied. ./com/xxxx/abc.java:282:          String expression = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$"; ./com/xxxxx/AddressChangeUtil.java:284:        ...

Unix/Linux Inline command for extracting file and filetype

filetype=`echo $f | awk '{n=split($0, a, ".")} END{print a[n] }'` filename=`echo $f | awk '{n=split($0, a, "/")} END{print a[n] }'` where $f is the full path of the file. It can be used directly too as.. filetype=`echo "/home/myuser/a.b.c.d.txt" | awk '{n=split($0, a, ".")} END{print a[n] }'` output : txt filename=`echo "/home/myuser/a.b.c.d.txt" | awk '{n=split($0, a, "/")} END{print a[n] }'` output: a.b.c.d

VitualBox Host Only Adapter & NAT configuration.

Image
Oracle Virtualbox is great virtualisation  solution for developers. The best feature of VirtualBox is, "it's free" and its runs on Linux, Mac & Windows. Many time when people want to set up Virtualbox they have two common requirements. 1. To connect to internet from guest i.e. the virtual machine. 2. To be able to connect to virtual machine from host computer. Now let's talk on solution. Requirement '1' can be met with configuration of 'NAT', like in screenshot below. This will enable the virtual machine to connect to internet. Now we want to enable LAN sort of connectivity between host and guest machines. For this we have to follow following steps. 1. Create a host only adapter by going to Virtualbox > Preferences 2. Add a host only adapter as shown. 3. Setup up DHCP if you want. I personally don't like DHCP, so my example will have manual setup in it. If you are following this example, be sure to uncheck DHCP confi...

The object identified by: 31 could not be found

The Problem Abstract  I encountered a strange exception while restarting my admin WebLogic server. Everything was working fine a day ago. But a day later its was giving me strange issue of "object 31" error. After struggling for a while I realized that some startup option was creating the issue. The startup options was containing JVM arguments "-Dweblogic.management.server=t3://10.188.103.55:7002" . The admin server should not contain this, as it makes the server to run in managed server mode. So the issue was, admin server was starting as managed server and trying to contact itself, creating a deadlock kind scenario. Usually ${ADMIN_URL} sets up the variable "weblogic.management.server". I tried to find out that who set this variable for admin mode startup, as setDomain.sh script enforces this variable is null for admin server startup sequence. On little debugging on environment variables at operating system level, it was clear ${JAVA_OPTS} was export...

JQuery/ Javascript text box text slides to label and mandatory field validation

I was thinking about an effect where on click or on focus the indicative text of text box become a label and slides animatedly to left. If one leaves the text box blank then the label again slides into text box and validation check is done. Attached is the code. View the example at  http://jsfiddle.net/rfL96u6c/ HTML < head > < meta http-equiv = "Content-Type" content = "text/html; charset=US-ASCII" > < title > Insert title here </ title > < script src = "http://code.jquery.com/jquery-1.9.1.min.js" ></ script > < script   type = "text/javascript" src = "../js/textboxanim.js" ></ script > < link href = "../css/registration_page.css" rel = "stylesheet" type = "text/css" > < style type = "text/css" > </ style > </ head > < body > < form action = "doRegistration" method = ...