Tuesday, 1 April 2014

How To Fix jQuery msgBox IE Security Warning Error

jQuery MsgBox is a jQuery plugin highly configurable to replace the basic functionality provided by the standard javascript alert(), confirm(), and prompt() functions.

BROWSER COMPATILITY:

Firefox,Chrome,Safari,Opera , IE > 7

But for IE Version 8 it throws a security warning error as it loads & Removes the div with background image using background-url which is a know bug in IE *


Solution :


Remove the Background Image Url and use CSS instead.

Replace Line 167 of Plugin or Overide the Show method of Plugin:
divMsgBox.css("background-image", "url('"+msgBoxImagePath+"msgBoxBackGround.png')");
with
divMsgBox.css("background-color", "#FFFFFF"); 
For Auto Scroll Modify the CSS with :
div.msgBoxContent 
{ 
    font-size:11pt; 
    margin:0 3px 6px 3px; 
    display:inline-block; 
    float:left; 
    height:90px; 
    width:319px; 
    overflow-y: auto; 
}
For Full Functionality with JS and CSS Visit this fiddle

Post Comments And Suggestions !!

Tuesday, 25 March 2014

How to Make String Palindrome

Problem : Write a program to find whether the string is a palindrome or not.
If it is palindrome, return empty string. If it is not, return the minimum length string which should be appended at the end of it to make it palindrome.

public class PalindromeTest
{
 public String palindrome(String s)
 {

  char[] input = s.toCharArray();

  int start = 0;
  int end = input.length - 1;

  if (isPalindrome(input, start, end))
   return "";
  else
  {
   start++;
   while (start < end)
   {
    if (isPalindrome(input, start, end))
    {
     break;
    }
    start++;

   }
   char[] toReturn = new char[start];
   for (int i = 0; i < toReturn.length; i++)
   {
    toReturn[i] = input[--start];
    //start--;
   }
   return new String(toReturn);

  }

 }

 public boolean isPalindrome(char[] input, int start, int end)
 {
  boolean isPalindrome = true;
  while (start < end)
  {
   if (input[start] != input[end])
   {
    isPalindrome = false;
    break;
   }
   start++;
   end--;
  }
  return isPalindrome;

 }
 
 public static void main(String[] args)
 {
  
  PalindromeTest test = new PalindromeTest();
  System.out.println(test.palindrome("NITI"));
  System.out.println(test.palindrome("aaab"));
  System.out.println(test.palindrome("abb"));
  System.out.println(test.palindrome("abc"));
  System.out.println(test.palindrome("abcde"));
  System.out.println(test.palindrome("abcaba"));
  System.out.println(test.palindrome("system"));
  
  
  
 }

}


Tuesday, 18 March 2014

How To Fix IE 8 Warning For HTTPS Connections

When Your web application is running on HTTPS then you might get an annoying warning like this in Internet Explorer . Internet Explorer will give you warning like this :

Do You Want to view Only the webpage content that was delivered securly ?

This webpage contains contents that will not be delivered using a secured HTTPS connection , which could compromise the security of entire web page.










This warning occur because one or more resources in your web page are accessed via HTTP protocol while the parent page is loaded through HTTPS . The resource may be a image , js , css or anything .


This warning may be removed by doing some setting in internet explorer , but that is not a good solution because you don't expect your client to do that job .

The other option is , to make every resource in your web page to be accessed via HTTPS only . To know which resources of your web pages are accessed via HTTP , you need to install a HTTPWATCH tool .

This tool will give you all the information about the resources getting loaded . From this you can find out what all resources are getting loaded via HTTP , and then you can fix these resources .

















Update : This error can also occur if the web page script calls removeChild on a div which references a background image
You can read more about this on this security warning in Internet Explorer. This error occurs on IE 6 , IE 7 and earlier versions of IE 8 .


You can refer to this link to fix this error when using JQuery MsgBOX. Post Comments And Suggestions !!

Thursday, 13 March 2014

How to Handle Exceptions in Jersey And Mule

This post describes how to handle exceptions in jersey component of mule .We can use ExceptionMappers for converting exception in jersey response .


Here is the RestClass which throws a custom exception .
package com.test;

import java.io.File;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;


@Path("/application")
public class RestClass {
   
  
  @GET
  @Path("/exception")
  @Produces(MediaType.TEXT_PLAIN)
  public Response exceptionTest() throws Exception{
   throw new MyException(401,"User is not Authorized");
  }

}


Exception Class .
package com.test;

public class MyException extends Exception 
{
 private int statusCode ;
 private String msg ;
 
 public MyException(int statusCode , String msg)
 {
  this.statusCode = statusCode ;
  this.msg = msg ;
 }

 public int getStatusCode()
 {
  return statusCode;
 }

 public void setStatusCode(int statusCode)
 {
  this.statusCode = statusCode;
 }

 public String getMsg()
 {
  return msg;
 }

 public void setMsg(String msg)
 {
  this.msg = msg;
 }
}


Here is the mapper class which will map our custom exception to JAX-RS response .
package com.test;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;


public class JerseyExceptionMapper implements ExceptionMapper
{

 @Override
 public Response toResponse(MyException arg0)
 {
  System.out.println(arg0.getStatusCode());
  return Response.status(arg0.getStatusCode()).entity(arg0.getMsg()).build();
 }
 
}


Specify this exception mapper in jersey resource of mule flow .
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:servlet="http://www.mulesoft.org/schema/mule/servlet" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd 
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd 
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd 
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd 
http://www.mulesoft.org/schema/mule/servlet http://www.mulesoft.org/schema/mule/servlet/current/mule-servlet.xsd ">
   
    
 <flow name="servletTestFlow1" doc:name="servletTestFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
        
        <jersey:resources doc:name="REST">
            <component class="com.test.RestClass" ></component>
            <jersey:exception-mapper class="com.test.JerseyExceptionMapper" />
        </jersey:resources>
        
    </flow>
    
</mule>

Monday, 3 March 2014

How to Use SSL in RAILS

Here Are the steps to be used in order to enable HTTPS in your rails web app .

Create SSL Certificate to Use HTTPS In Rails ENV (Rails Version > 3.0.0)

 # Self Signed SSL Certificate to Use with rails

  •  Go To Your Project Root Folder 
  •  Type “mkdir .ssl”
  •  Type “openssl req -new -newkey rsa:2048 -sha1 -days 365 -nodes -x509 -keyout .ssl/localhost.key -out .ssl/localhost.crt”   
Command Explanation:
# req      --> Create a new Request.
# -x509    --> The result of this will be an X.509 certificate, not a Certificate Signing request.

# -sha1    --> Make sure to use SHA1 as this certificate's hashing algorithm. (newer versions of OpenSSL should default to this)

# -newkey  --> create a new key.

# rsa:2048 --> the key will be of type RSA, and will be 2048 bits long

# -nodes   --> Don't encrypt the key


Here is the Sample Input for the following parameters:
Generating a 2048 bit RSA private key

....+++

..................................+++

unable to write 'random state'

writing new private key to '.ssl/localhost.key'

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [AU]:IN

State or Province Name (full name) [Some-State]:RAJASTHAN

Locality Name (eg, city) []:Bhilwara

Organization Name (eg, company) [Internet Widgits Pty Ltd]:JavaRoots

Organizational Unit Name (eg, section) []:Rails

Common Name (e.g. server FQDN or YOUR name) []:RAILS DEV TEAM

Email Address []:railsdevteam@devteam.com


This will create following files in your SSL folder :
1. localhost.crt

2. localhost.key

Now After creating ssl files , following steps will be required :

  • Run “echo "127.0.0.1 localhost.ssl" | sudo tee -a /private/etc/hosts”
  • Edit you GemFile and add gem “thin”
  • Create a New Initializer file named ssl_config.rb add these lines:
    ActionController::ForceSSL::ClassMethods.module_eval do
      def force_ssl(options = {})
        config = Rails.application.config
    
        return unless config.use_ssl # <= this is new
    
        host = options.delete(:host)
        port = config.ssl_port if config.respond_to?(:ssl_port) && config.ssl_port.present? # <= this is also new
    
        before_filter(options) do
          if !request.ssl?# && !Rails.env.development? # commented out the exclusion of the development environment
            redirect_options = {:protocol => 'https://', :status => :moved_permanently}
            redirect_options.merge!(:host => host) if host
            redirect_options.merge!(:port => port) if port # <= this is also new
            redirect_options.merge!(:params => request.query_parameters)
            redirect_to redirect_options
          end
        end
      end
    end
    
    
    
  • Open your config/application.rb and add “config.use_ssl = false”
  • Now edit your enviroment files to
     development.rb => 
      “config.use_ssl = true”
      “config.ssl_port = 3000”
    
  • Now Add “force_ssl” to app/controllers/application_controller.rb at top priority.
  • Now Run your Server using this command:
     “thin start -p 3000 --ssl --ssl-verify --ssl-key-file .ssl/localhost.key --ssl-cert-file .ssl/localhost.crt”
    
    
Voila !! Now your rails server is configured to use HTTPS !!!


Njoy Coding in Rails.


A Big Thanks to Santosh for writing this post !!

Thursday, 27 February 2014

Koding : An Online Development Enviornment

Koding.com is an online development enviornment where developers can write code and execute it on the internet . Users can also create teams or groups and collaborate with each other easily .Users can create and run apps in Ruby, Go, Java, NodeJS, PHP, C, and Python , facebook apps , wordpress , angular js etc. It also provides databases like MySql and Mongo .Every User will be assigned a vm , on which he can work on his code.


It's a great tool for beginners to learn new languages with no need to worry about setting up enviornment and configurations .


A very nice story behind this venture .


Enjoy Coding !!

Monday, 24 February 2014

How To Write Cron Job In Mule : Example

Creating Cron Job or a Scheduler in Mule is very easy by using Mule's Quartz Transport . Here's is simple mule flow which triggered every five minutes .








You have to write cron expression in quartz endpoint of mule like this :
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd 
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd 
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
   <spring:beans>
    <spring:bean class="TestBean" name="test" id="test">
    </spring:bean>
    </spring:beans>
 <flow name="generateStockTicks" doc:name="generateStockTicks">
        <quartz:inbound-endpoint jobName="eventTimer" doc:name="Quartz" 
        cronExpression="0 0/5 * * * ?">
            <quartz:event-generator-job>
                <quartz:payload>tick-tock</quartz:payload>
            </quartz:event-generator-job>
        </quartz:inbound-endpoint>
        
             <component doc:name="Java">
            <spring-object bean="test"/>
        </component>
        <set-payload value="123456" doc:name="Set Payload"/>
        <logger message="Cron Job Running #[message.payload]" doc:name="Logger" level="INFO"/>
       
        
    </flow>
    
    
</mule>

Download the complete source code of mule cron job example .


Post Comments and Suggestions !!