Tuesday, November 3, 2009

Converting Groovy Array type to Java Array Type

Following is the code snipped in groovy that demonstrate the conversion Groovy Array type to Java Array Type.
Code for Groovy

def param=[]
param+="paramater 1"
param+="paramater 2"
param+="paramater 3"
param+="paramater 4"
def stringArgForJava = (String[])params

Test.callJavaClass(stringArgForJava) //static method

The sample java class is as follow;

class Test
public static void callJavaClass(String[] arg)
for(int i=0;i {
System.out.println("params "+i ":" +params[i]);



Tuesday, October 13, 2009

Read a variable defined on the config file from a controller in a grail application

Let's say, you have the config.groovy file as follow.


environments {
production {
myVariable1="I am variable1 on RPOD"
myVariable1="I am variable1 on RPOD"

development {
myVariable1="I am variable1 on DEV"
myVariable1="I am variable1 on RPOD"

log4j {
appender.stdout = "org.apache.log4j.ConsoleAppender"

Now the above varaible can be easily access through any of the controller as follow.

def config = ConfigurationHolder.config
def myVaraible1 = config.myVaraible1
def myVaraible2 = config.myVaraible2


Wednesday, July 8, 2009

Reading the status code of HTTP Request !

When you make an HTTP request to any server url throuh your client software, lets say IE, HTTP Status codes are returned by the server to the client software to determine the outcome of your request. There are five different classes of status code range. They are
Status codes 100-101
Status codes 200-206
Status codes 300-307
Status codes 400-417
Status codes 500-505

Following is a simple program written in groovy that checks and returns the status code of any url.

import java.net.URL;
def url
def message =""
boolean fail=true
def urlString=""
println checkURL(urlString)

def checkURL(urlString){
int status_code
def tempmessage=""
URL URLserver = new URL("urlString");
URLConnection connection = (HttpURLConnection)URLserver.openConnection();

status_code = connection.getResponseCode();

switch (status_code)
case 200:
tempmessage=" Connection Successful"
case 401:
case 405 :
tempmessage= " Resource Not Found"
case 408:
tempmessage="Request Time-out"
case 500:
tempmessage="Internal Server Error"
case 502:
tempmessage="Bad Gateway"
case 503:
tempmessage="Service Temporarily Unavailable"
default :
tempmessage= connection.getResponseMessage()

catch (Exception exc){


return "\n "+urlString+" :"+status_code+":"+tempmessage;


Visit http://www.w3.org/Protocols/HTTP/HTRESP.html for detail about the status codes.


Friday, June 12, 2009

Problems with Hotmail login

Hotmail has been going under the planned maintenance on its servers, So you might face some problem accessing your hotmail. Some of the problems that I am facing are like
1. Asking to enter password for multiple times
2. When i type in the address http:// hotmail.com in the address bar and enter than I get a message “The requested URL could not be retrieved”. Sometimes it loads the page but once I enter the password and username it throws the message “The requested URL could not be retrieved”, i.e. the connection timed out.
3. Some time I am able to log in but I get the same problem while sending or opening a message.
Following are some of the solutions recommended by Microsoft,.
1. http://windowslivehelp.com/solutions/servicemgt/archive/2008/12/26/what-to-do-if-you-can-t-sign-into-windows-live-hotmail.aspx
2. http://windowslivehelp.com/solutions/accounts/archive/2009/03/03/How-to-optimize-Internet-Explorer-browser.aspx
3. http://windowslivehelp.com/solutions/servicemgt/archive/2008/08/22/how-to-determine-which-server-you-are-on.aspx

Thursday, May 28, 2009

Microsoft to replace its live search engine with a new decision based engine “ Bing”

In order to compete with the giant search engine, Google, Microsoft has unveiled its new search engine, Bing. On May 28, 2009, Microsoft CEO Steve Ballmer has announced the new incarnation of live search as Bing, formerly code-named "Kumo". Bing is fully available from June 3, 09.
Microsoft has claimed that Bing is not only the search engine but a Decision Engine, designed to empower people to gain insight and knowledge from the Web, moving more quickly to important decisions.
“Today, search engines do a decent job of helping people navigate the Web and find information, but they don’t do a very good job of enabling people to use the information they find,” said Steve Ballmer, Microsoft CEO. “When we set out to build Bing, we grounded ourselves in a deep understanding of how people really want to use the Web. Bing is an important first step forward in our long-term effort to deliver innovations in search that enable people to find information quickly and use the information they’ve found to accomplish tasks and make smart decisions.”

Microsoft has aimed to gun down Google with Bing. Microsoft has already announced an $80 to $100 Million ad campaign for Bing. Google has spent about $25 million on all its advertising last year with $11.6 million for recruiting.
As show in the graph Microsoft search market share has been lowering down with just an 8.2% share of the market for core search compared to 64.2% for Google and 20.4% for Yahoo. Microsoft has been struggling to for improving its search advertisement revenue. Last year only Microsoft has offered more than $47 billion dollar bid. They might come up with another Microsoft-yahoo search deal by mid July.
Good luck to the Microsoft for the new product!


Friday, January 30, 2009

Read Environment Variables with Groovy

Environment variables can be easily accessed with Groovy with getenv() method as shown below.

def env = System.getenv()
//Print all the environment variables.

println it
// You can also access the specific variable, say 'username', as show below
String user= env['USERNAME']



 ©mytechtoday.com 2006-2010