IntelliJ with Tomcat and Gradle using Gretty plugin

by GarciaPL on Thursday, 27 April 2017

This time I would like to describe briefly how to enable Tomcat in debug & class reload mode on IntelliJ when project is built using Gradle using this time Gretty plugin [1].

1) Add below line to build.gradle after applied war plugin

apply from: ''

2) At the end of build.gradle add also below statement which allows us to reload classes in container in the fly after change made by you in IntelliJ

gretty {
    managedClassReload = true

3) Add Remote item in IntelliJ [3]

4) Run project using below command line

gradle tomcatStartDebug --info

5) Pickup Remote item in IntelliJ and run it in debug mode

6) Place breakpoints and run the code to catch them

Reference :
[2] Hot deployment in Gretty
[3] Adding Remote item in IntelliJ

Oracle - duplicate keys found for novalidate unique constraint

by GarciaPL on Tuesday, 10 January 2017

I was trying recently to add unique constraint on few fields on Oracle. At the beginning I thought that it might be a easy task to do, but at the end some workaround was needed. So, in case of error you might get below message which indicates that Oracle found some duplicate records in your table, even though you specify NOVALIDATE flag which allows you to do not check existing data against that constraint.

Error report -
SQL Error: ORA-02299: cannot validate (DB.MY_UNIQUE_CONSTRAINT) - duplicate keys found
02299. 00000 - "cannot validate (%s.%s) - duplicate keys found"
*Cause:    an alter table validating constraint failed because the table has
           duplicate key values.
*Action:   Obvious

That's why we need to define simple INDEX on fields which will be used during setting UNIQUE CONSTRAINT before setting our UNIQUE CONSTRAINT.

References : [1] ENABLE NOVALIDATE validating existing data - Ask Tom [2] NOVALIDATE Constraints – No really - richardfoote

Spring Integration - Header Routing by Header Key

by GarciaPL on Sunday, 8 January 2017

As you can see Spring Integration posts are going to be continued! This time I would like to share with you small hint of code which will help you to route your message based on existing or not key Signature in your headers.

<int:router id="headerRouter" expression="headers.containsKey('Signature')"
    <int:mapping value="false" channel="drop"/>
    <int:mapping value="true" channel="processFurther"/>

References :  [1] Spring Docs - Message Routing

Spring Integration - Cache requests for inbound/outbound gateway

by GarciaPL

Do you use inbound or outbound http gateway in Spring Integration and you was thinking about caching some requests ? There is a solution for that! It's can be achieved with <request-handler-advice-chain> and Spring Cache Advice.

              <cache:caching cache="cacheKey">
                    <cache:cacheable method="handle*Message" key=""/>

You might see above that handle*Message will be considered by Spring Cache Advice to invoke cache functionality. To be more specific we are thinking about handleRequestMessage method and it's parameters defined as a part of HttpRequestExecutingMessageHandler which will be considered as a key - id in our case. Moreover you need to define explicitly cacheManager bean and define key for cache entry (cacheKey in our case) using for instance EhCache.

References : [1] Spring Integration - Cache for inbound/outbound gateway

Packer by HashiCorp

by GarciaPL on Saturday, 10 December 2016

Some of you might be interested in presentation which I made recently for internal training purpose. Topic is "Packer by HashiCorp".

Android Stack Careers Pull Request - Feed API and OkHttp

by GarciaPL on Sunday, 18 September 2016

Some of you might know this unofficial Stack Careers Android app which allows you search job in IT sector. There is a link => Stack Careers on Google Play. I have been using it for a while, but some time ago it stopped working. Only what I got was : 'No Results'. So, I downloaded repository and found out that feed API of Stack Careers has been changed. I mean that application got HTTP 301 status which means Moved Permanently and no redirect has been performed using standard HttpConnection component of Android stack. More info about what I did you might find below and under pull request link.

In fact that I have been using you app occasionally, I found someday that it does not work now. I managed to figure out that guys from Stackoverflow changed feed API and moreover you app was not able to follow up redirect (HTTP 301 Moved Permanently).

So, according to this pull request what I did and what I did not :

  • feed API has not been changed 
  • added OkHttp library within required by it another library called Okio 
  • replaced HttpURLConnection with client from OkHttp 
  • added required rules for proguard to cover up OkHttp 
I pushed changed content around usage.txt, seeds.txt, mapping.txt and dump.txt within this pull request, but I will leave decision up to you if you are going to discard it or not.

I also would like to mention that feed API for Stack careers has been changed from =>

PS. I hope that author of Stack Career will accept my fix for that problem and eventually some day we might be able to download new app from Google Play.

Reference :
[1] Stack Careers - pull request