Thursday, August 22, 2019

How to check what version of JQuery is loaded in browser

Sometimes we might want to know what version of jQuery a particular site is using. It is not always possible to know the version of jQuery we are using through the jQuery File name or reading the content of the files, specially when the jQuery is minimized.

Following snippet can tell us the version of jQuery loaded by a site.

if (typeof jQuery != 'undefined') {  
    // jQuery is loaded => print the version

Simply go to the console of the browser, once the webpage is loaded, and then type. the above command on the console. It should display the version as an Alert.

Tuesday, August 20, 2019

How to generate sitemap for Blogs hosted on Blogger

Blogger comes with some goodies, like the atom feed URL, which can be used to generate sitemap for bloggers.
  1. Sign in to Google Search Console.
  2. Select the Blog from the left hand side.
  3. Click on Sitemaps link.
  4. At the top of the page with title "Add a new sitemap"
  5. Add the below code in the text field.
Google Search Console

Example :
Press “Submit Sitemap” button.

Tuesday, August 13, 2019

Handle 409 conflict document in couchdb

Problem Use case:

 CouchDB Error 409 conflict document.

Exception Details [Truncated]:
CouchDB is throwing error 409 conflict while calling REST API to update data.
CouchDB will throw 409 conflict document exception if the payload is not proper. Following are some of the cases.
"_id" : This attribute is present, but the "_rev" attribute is not present or is wrong.
CouchDB uses both the "_id" and "_rev" attribute while updating a Document. Every time we update a document the "_rev" attribute value gets updated.

If we want to update data, then make sure both "_id" and "_rev" attributes are carrying proper values respectively.

Referance Links related to CouchDB:

CouchDB Error 412:Precondition Failed

Problem Use case:
 CouchDB Error 412:Precondition Failed

Exception Details [Truncated]:
CouchDB is throwing error while calling REST API to update data.

CouchDB will throw 412:Precondition Failed exception if the payload does not contain the unique identifier "_id" attribute or its value is missing. Check the payload for PUT or POST to make sure the "_id" attribute is not missing.

Referance Links related to CouchDB:

Tuesday, April 30, 2019

Starting Spring Boot Application in Debug mode

Start the Spring boot application with the following jvm argument.

mvn spring-boot:run -Drun.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

Saturday, April 20, 2019

Maven attach source code for external Jar

For Java project that uses Maven for dependency and building we can attach the third party library source. By default the source is not available, using the following commands we can down load the associated source and java doc from maven repository by reading the project pom file.

Maven will not be able to download sources and docs if those were not published for a particular library.

mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc
//to download source for only one library
mvn dependency:sources -DincludeArtifactIds=spring-boot

Now after executing the above two commands, maven will download the respective sources and java docs. Now we can attach the source in the IDE. For eclipse specially it is better to use the Maven Eclipse plugin

mvn eclipse:eclipse -DdownloadSources=true
mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=false

Executing the above commands will also download the sources and it also updates the .classpath file. Now refreshing the Project in side eclipse should be able to map the corresponding sources for the external jars.

Saturday, April 13, 2019

Failed to instantiate [java.util.List]: Specified class is an interface in HTTP controller handler?

Problem Use case:

Following SpringBoot Rest Controller is not able to map the request payload

  public class BlogController {  
    @RequestMapping(value = "/blogstories", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
       public ResponseEntity<List<BlogStoryObject>> addUpdateblog(List<BlogStoryObject> blogItems) {
          List<BlogStoryObject> result = new ArrayList<BlogStoryObject>();
    //TODO:: Call Service to update/save objects
    return new ResponseEntity<List<RootBlogStoryObject>>(result, HttpStatus.OK);

Exception Details [Truncated]:

And the error thrown at runtime is Failed to instantiate [java.util.List]: Specified class is an interface.


Solution to the problem is to @RequestBody annotation to the method definition, so the following will work.

public ResponseEntity<List<RootBlogStoryObject>> addUpdateblog(
  @RequestBody List<RootBlogStoryObject> blogItems) {
  /////implementation goes here