Skip to main content

Posts

AWS API Gateway - Handling CORS errors

  AWS API Gateway Console provides a simple mechanism to enable CORS and handle Cross-Origin browser requests to REST Apis/ Services. You may select any "resource" in the API Management console and select "Enable CORS" from the "Actions" Dropdown.   You may expect this feature would be simple click and forget solution but you might still encounter CORS issues when you make API request calls from your favourite UI frameworks such as React, Angular, Vue and even plain vanilla javascript. You may end up tinkering your backend service irrespective of the technology used; Lambda (AWS), Springboot (Java), Flask, Express (nodejs) ...never ending list of REST API platforms. Either you end up lucky solving the issue or left searching for answers. You might encounter errors such as - Origin http://[yourdomain].com is not allowed by Access-Control-Allow-Origin.  Origin http://localhost:4200 is not allowed by Access-Control-Allow-Origin.  Reason: CORS header 'Acce...

Navigating the log files

  Often you may find yourselves in the middle of searching for a keyword in your log files.  On the linux environment , you will easily find by using the command            grep 'your keyword' filename.log Sometime you may want to know what happens before and after the occurrence of your keyword.  In the example below I tried to look for an exception using grep command. The output alone is not really helpful to identify the problem that I'm looking for. We need to understand what happened before and after the exception that occurred. The first step is to get the line number of the first occurrence of this error. Let's use the command with grep -n command We can now see the line numbers; 2449 and 2515. The next step is to find out the content of the log few lines adjacent to line 2449 in this example. The following command gives the desired result that is connect of the log file between the lines shown in the example below. sed -n '2440,...

Grails - Querying complex associations

Criteria class allows performing complex searches on grails objects. There are number of shortcut methods for performing queries but these methods have limitations in terms of number of conditions used in "where clauses". Traditional sql "joins" are not possible as shown in some of the Grails "Finder" methods shown below. Sample 1: def list = AccountTransaction.findAllByCompanyCodeAndVoucherDateBetween(branch, fromDate, toDate, params) Sample 2: def list = AccountTransaction.findAllByCompanyCodeAndVoucherDateGreaterThanEquals(branch, fromDate, params) Sample 3: def list = AccountTransaction.findAllByCompanyCodeAndTransGroup(branch, group, params) "params" contains attributes related to sorting, paging etc. It is very easy to use finder methods but when you want to filter objects by more conditions we need to look for alternatives. For understanding the relationships used in this sample, I listed the grails domain classes. class TransactionTyp...

Implementing advanced sort in Grails

The "list" pages generated by inbuilt scaffolding/template features of grails have pagination and sorting features. However, if the domain object displayed in the list is a nested object having another domain object as a property, you may notice that sort is not enabled for that field. Boiler plate code for the header of the list is shown below. As you would have noticed few columns have sortable columns automatically generated by Grails command, generate-all or generate-views. The properties 'partyAccount' and 'bankAccount' in this sample are domain classes nested in the domain class 'partyTransaction'. We could convert them to sortable columns by using the tag g:sortableColum...

SVN - Version control system on Amazon EC2

There are number of hosted SVN providers who offer hosting services along with add-on services like project management, bug tracking etc. If your requirement is purely to host the version control system we may end up paying little bit premium for the add-on services. The charges tend to increase when your storage requirements increases. You may compare the prices offered by Unfuddle and Beanstalk . If your storage requirement is about 10 GB and you have would like to install your own SVN server, you can save significantly by going for Amazon EC2 micro instance. I detailed the steps below to get your SVN server up and running. 1) Go for reserved Amazon EC2 instance on a long term plan ( 1 year/3 years). Choose micro instance that costs about $54 annually and a monthly recurring fee about $7. 2) Launch new instance from EC2 tab of Amazon web services customer portal. 3)Choose Basic 32-bit Amazon Linux AMI and Continue to next option. 4) In the above screen choose Instance type as ...

CCAvenue and Magento Integration

India based e-commerce portals have to consider CCAvenue Payment Gateway as one of option for its simplicity and reliability. Magento e-commerce platform has several ready to use payment gateway plugins and a rich set of API to enhance its functionality to add new payment gateways that are not provided as part of its standard release. For one the projects we have to integrate Magento with CCavaenue. We browsed several forums for a free and ready to use plugin without much luck. Though there is no mention of any such plugin on CCAvenue website, we just tried calling the CCAvenue help desk and immediately we got an integration toolkit with detailed steps for integration. It works like a charm.

Cheap Grails hosting

We can use Amazon EC2 micro instance (~615mb RAM) to run grails application with Tomcat and Mysql. If you need higher JVM memory, we can try to keep the memory footprint low by using memcached or ehcache. The price is nearly $5/month if you commit for a one year contract. Since November this year, this service is offered for free for the first year for new customers. If your server server load is higher, with more number of visitors/hits, your website must be in revenue generation mode and I'm sure it will pay for itself for additional server resources. Alternatively, you can run your Grails Application on Google AppEngine. There may be few constraints in terms using some of your favorite plugins. If you careful build the application keeping the constraints in mind, you may get away with almost free webhosting. ($0/month - provided usage is within the boundaries defined by GAE platform) Both Amazon and GAE, have billing mechanisms based on the bandwidth, data storage and few add-on...

Partial page loading with Grails and Jquery

Most web applications greet their users with a fancy dashboards to display various statistics of interest. The generation of dashboards are often resource consuming and therefore it is advisable to optimize the page loading time. One option is to display page content while showing certain parts of the page in loading state. In this tip, this is achieved by partially loading parts of the page by using jQuery - javascript ajax library. Though I used Grails in this sample, it can be used for other web programming languages/platforms.

jqgrid grails : editing rows with drop-downs/combo boxes

Jqgrid is a jquery plugin that allows formatting data as table and has number of options - paging, sorting, filtering, inline editing etc. There are few good tutorials explaining the process to integrated jqgrid in your grails application. http://pramodnepal.com.np/?p=119 http://www.grails.org/plugin/jqgrid Following is a typical jquery script that can be used in a grails application. The property 'editable=true' make any of the field in grid as editable.

Partial form submit with Grails and JQuery

At times you would want process a part of the form and refresh the page with the results obtained from the partial form submission. Given below is a screen shot of the typical use case. It is a form used in a sales application. Take a look at the section "Particulars" in the screen. The fields - Item, Unit Price, Quantity, Discount%, Tax% are editable and fields - Total Discount, Total Tax and Grand Total are calculated as the result of clicking "Calculate" link in this section. There is on option to add multiple rows to this table by selecting "Add" in the first cell of this table. The section of the code used for the table "Particulars" is given below.

Grails - Import data from excel spreadsheets

Importing data from excel spreadsheets to a grails application is quiet simple. You could your favorite spreadsheet processing libraries for Java like Jexcelapi or Apache POI . In this example, I used Apache POI. Step1: Copy the required libraries to libraries/lib folder of your grails applications. Step2: Create a grails controller class. Eg: Uploader

Clicktale with Blogger/ Blogspot

I am curious to know how visitors are finding my blog content. I heard lot of good things about this tool, Clicktale , and I implemented for my blog. Just two steps to get started: 1) Create an account with Clicktale and get the tracking code for your domain. I used http://sguthula.blogspot.com as domain. The instructions to get the tracking code are simple and easy to follow. 2) Login to your Blogspot account. Choose "Layout" and "Edit HTML" as shown in the picture below. Copy the tracking code provided by Clicktale. CAUTION: Take a backup of your html in the "Edit HTML" box to revert back to your previous state of the blog when you do not need the tracking.

Overlay Graphs in Grails Application - Open Flash Chart

Ofchart plugin available for Grails, makes it is easy to integrate Open Flash Chart. The plugin can be downloaded from http://grails.org/plugin/ofchart The documentation is available at http://mybytes.wordpress.com/2009/03/09/grails-open-flash-chart-06-is-out/ Though the Open Flash Chart has number of chart options - ofchart plugin documentation has limited information. I believe the documentation work is in progress and may be available anytime soon. An inquisitive mind can experiment and try to accomplish most of the features in Open Flash Chart. Best place to start is to read the API documentation A simple example I tried - overlaying a Bar chart and Line chart on a single Chart. It requires a Grails controller and a GSP as listed below. We can include the "action" to render the chart in any of your existing controllers.

How software project development teams slip deadlines?

Poor quality of the project estimation is often attributed as the main reason for missing deadlines in most of the software projects. Slipping deadlines is most common and even management teams anticipates this event and accordingly negotiate pricing with their customers. As this happens to be "known Risk" and corrective actions are taken upfront, the people involved in the wrong estimates are not penalised. Even if they do, it is only going to impact their "annual" appraisal. They might slip just "one" grade. Most people try their best to arrive at right estimates but there are few scenarios I will try to discuss later in this post that may impact the success. On the otherhand there are certain cases where there is higher propabiliy of failures. 1) Manager/Project Lead, who is estimating the project, divides the task into various functional tasks, allocates tasks to individual developers to provide estimates. He/She uses their prior experience to adjust ...

Bind Exception, Netbeans 6.7.1 and Jetty server running Grails applications

While developing Grails applications on Netbeans IDE 6.7.1, I noticed an issue with the inbuilt servlet container, Jetty that is packaged with Netbeans IDE. Sometimes, Jetty server wouldn't stop even if we stop from the "Services" tab of the Netbeans IDE. It might show that it is already stopped under the "Services" section while it is still running in the background. Any attempts to Run the grails application after this event, will fail. You may get errors saying "Port already in Use" or "Address already in use: bind". The environment is windows/xp/vista. I'm assuming Jetty is using Port 8080 by default. The exception message in the console says " Server failed to start: java.net.BindException " Run the following command from the command prompt. netstat -o -n -a | findstr 8080 You may get output as below: TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 7972 In the above line, the PID(Process Identi...

Paging techniques for applications using google appengine for java

Paging technique is implemented in tons of websites and there are many libraries, both opensource and commercial components, that are easy to integrate into any website. Ajax based tables (excel like) with navigators for paging to and fro, are integral part of RIA applications. Why do we need a different technique to implement paging for Google appengine application when so many components exists today? To answer this, we need to understand two aspects. 1) How majority of the "paging" components are designed for usability? 2) How data is stored and retreived in applications that use Google Appengine? I used my favourite "paging" library Jqgrid to explain the techniques. The component is based on JQuery and is well documented. Click the link for jqgrid demo The above picture shows, - options to navigate page by page - total number of records available - total number of pages etc

YSlow - Grade A - may not equate to a high performance website

YSlow, an add-on plugin for Firebug, a must have tool for all web developers concerned about performance of their website. As shown in the picture below, analysis using Firebug reveals all the the performance bottlenecks. YSlow, add-on plugin used along with Firebug, gives more detailed analysis and suggests useful tips to improve the performance. It has a grading system on a scale of A to F, A being the highest performer. Given below is the snapshot of its report run on this blog.

Amazon's RDS - Performance?

Majoriy of the typical application design warrants an Application server and database servers. The application servers interact with database server instance using connection/pooled connections. The interaction between app server and database server is highly I/O intensive and performance is good when these two instances(App server and DB) are on the same physical server or atleast better when they are on same LAN. Is it advisable having to rely on Relational Database Services from Amazon and an appserver running elsewhere? May be if the application runs on EC2 cloud and access Relational Database Services, it offers required performance. However, if we consider a small application, paying 11cents/hr for an EC2 instance and another 11 cents/hr for an RDS instance may be an expensive affair. If it is expensive for small applications what are the other scenarios where one can benifit from Amazon's Relational Database as Service? 1) If the application is a Client-Server based? (If th...

Grails - cross-field Date validation - Method using controllers

In continuation of my earlier post on the cross-field date validation , I'm going to discuss another method using grails controller. The following code in "save" and "update" method of the controller validates the date fileds used in the student domain object that is discussed in the previous post def save = { def studentInstance = new Student (params) if (studentInstance.endDate.before(studentInstance.startDate)) { studentInstance.errors.rejectValue('endDate', 'student.endDate.shouldbegreater') } ... .. } Note that the code highlighted as bold is the addition to the boiler-plate code generated by using the grails command "grails generate-all" on the domain class "Student" Following message is to be added to the "messages.properties" file

Grails - cross-field Date validation

Often we run into domain classes with date fields. If the domain class has two datefields, startDate and endDate, and the rule for a valid combination is "endDate to be greater than startDate", how do we handle? I listed below two of the options, either using domain level constraints or using the domain classes. Option 1: Using domain constraints. Let us take a sample Grails Domain class class Student{ String name String school Date startDate Date endDate } Add the following constraints to enforce validation rules where name, school, startDate cannot be blank and endDate if present should be greater than startDate.