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
Recent posts

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,2460 {  p; }' < nohup.

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 &qu

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