Search This Blog

Friday 19 September 2014

DBCursor - size,length and count

Consider the below method:
public static String DB_NAME = "fruits";
   public static String COLLECTION_NAME = "fruits";

Wednesday 27 August 2014

More querying in MongoDB

In the last post we started running queries on MongoDB. To continue on the operators, I decided to do a find on the auto generated id:

Thursday 14 August 2014

Tinkering with blogger - Adding a scrolling headline

OK first and foremost - This is not related to Java. And second - This was all done with the purpose of getting an internship (yes selfish and self serving reasons for this post people).

Sunday 10 August 2014

Using query language with MongoDB

In the previous posts we have seen how to insert and read data from the MongoDB client and from the Java API. Now to fetch documents by executing queries on the collection.

Sunday 3 August 2014

The ReadWriteLock

The lock interface in Java has a specialized version - ReadWriteLock. As per the interface documentation:

Thursday 24 July 2014

Conditions and Locks

In the previous post we saw how the Lock API could be used as an alternative to synchronized block. We also saw how the Lock API allowed us to do chain locking. There is also a condition object closely associated with Locks:

Saturday 12 July 2014

Locks in Java

After semaphores I decided to look at the Lock interface in Java. The first question that comes is "Why use locks when wait notify works well enough ?" I looked in the documentation for the class and the below lines stand out:

Monday 16 June 2014

Read-Write to MongoDB via java

In the last post I used the java driver to connect to the MongoDB. Now to read the documents from the collection:

UD - The Update and Delete in CRUD

We have already seen Create and Read operations with MongoDB. We were able to create collections in the database and add documents to them. Now to try updating and deletion of documents.

Sunday 15 June 2014

Talking to MongoDB via java

In our last post we got started on creating a database and adding docs to a collection. Being a java guy, I wanted to try and use the database connectivity driver provided by MongoDB for use with java applications.

Thursday 29 May 2014

Talking to MongoDB

In our previous post we saw how to set up MongoDB for running. The application we started was the MongoDB server. It is not a client. To perform any operations, what we need is a way to connect to the server. For this I decided to initially use the mongo shell:

Wednesday 21 May 2014

Baby steps at understanding MongoDB

I have never ventured outside the world of relational databases. So when an opportunity to peak into Big Data arrived, I couldn't let the opportunity go. I decided to start with a no sql database first.
After careful thought and deep analysis over a long long period of  5 minutes, I settled on MongoDB. (ovation please !!)

Thursday 15 May 2014

The Phases in the Inbound chain - When does marshaling occur ?

In our last post we saw a simple Interceptor that read the request and modified it before sending it to our endpoint. The interceptor was executed in the PRE_INVOKE phase

Saturday 3 May 2014

Interceptors in CXF

In an earlier post I used JAX-WS Handlers to modify the soap body and soap headers. The same can be achieved by directly writing CXF Interceptors . Consider our random web service operation that returns a random result. I decided to add an interceptor to modify the SOAP body

Thursday 24 April 2014

Creating a Database in Oracle and in PostgreSQL

As a part of my college project, I needed to create a database in oracle. It went fine. A I had a PostgreSQL set up at home, I decided to run the scripts on the PostgreSQL setup. Some interesting observations...

Monday 21 April 2014

Scopes and Dependencies

We saw an example of request and session scoped beans earlier. We saw how the ApplicationContext was used to get access to these beans. However making the code ApplicationContextAware may not be an acceptable solution.Who would be keen to have Spring's core classes intruding into the code ? Knowing this Spring does provide us with an alternative solutions involving AOP.

Sunday 13 April 2014

Request and Session Scope

I have never used a request scoped bean. Always Singleton. And once I dabbled with Prototype but that too never went beyond the prototype stage.
I can't really think of a scenario where I might need request or session scoped beans (yet!). The job is generally achieved with stateless singleton beans and data in request and session attributes.
Anyway I decided to try out a request scoped bean.

Tuesday 8 April 2014

The Holder class in JAX-WS. Why and How ?

Consider the operation in the below wsdl file. It talks about a simple Port that has one operation - to update the data received. Nothing fancy about it. The service will return the updated and if necessary modified data.

Tuesday 1 April 2014

How HashMap works in Java

I was looking at the HashMap source code the other day and felt like writing down what I learned. Consider the start point to using the HashMap:
Map<String, Integer> map = new HashMap<String, Integer>();
This will Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).

Thursday 20 March 2014

My own primitive Single Sign On - Last Lap

In our previous post we saw how PlatformApp1 was able to read the cookie created by AuthPlatform. The PlatformApp1 verifies with the AuthPlatform if this cookie is valid (maybe through shared data or a simple REST API exposed by AuthPlatform) and accordingly lets the user proceed.

Tuesday 18 March 2014

My own primitive Single Sign On - Part 2

In the previous post I started on creating of my custom SSO solution. I have decided to name it "SimplySSO". To continue with the application flow, lets start with the login flow:

Monday 17 March 2014

My own primitive Single Sign On

I have often worked on web applications which used SSO. In fact my blogger profile also works through an SSO flow. If I am logged in into Gmail than all fine, else I need to login into Gmail or more specifically my Google account.

Wednesday 12 March 2014

The Different Type of JAX-WS Handlers available

In the last post we saw how we could use Handlers to access various properties associated with the web service requests and responses. But can we modify them ? I guess it is time the CrazyHandler actually did something crazy !

Monday 3 March 2014

handleMessage method of Handler being called twice ?

In our previous post we saw how a handler is invoked with CXF. We also saw that our handler was invoked twice - once as a part of the inbound flow and once as a part of the outbound flow. There is a slight problem here. The same handleMessage method of the same Handler instance is used in both cases - which means the same code executes twice!

Monday 24 February 2014

Reference Queues

In the previous posts we had a look at weak and soft references. The java.lang.ref package also includes a class ReferenceQueue. As per the class documentation:
Reference queues, to which registered reference objects are appended by the garbage 
collector after the appropriate reachability changes are detected.

Tuesday 18 February 2014

Soft References in Java

In the last post I looked at using weak references in my java code. As we saw Java has not just strong and weak but also soft and phantom references.
Firstly, what are soft references ?

Sunday 9 February 2014

Weak References in Java

I have been looking at the java.lang.ref package with a view to understanding references in java. It all started when I tried to understand WeakHashMap and its use in string pools. The various related terms mentioned totally flummoxed me and made some additional study essential. Below is a summary of my attempts at understanding.
Java objects in the memory are classified as:

Sunday 2 February 2014

Views in ModelAndView

We had an interesting scenario in our code. It all started out when we had this complex controller that included methods specific to a certain flow. In case of any exception, we used an error handler to redirect the flow to an error page. The code would be along the lines of

Monday 27 January 2014

Semaphores in Java

What exactly is a semaphore ?
To use the wiki definition:
In computer science, particularly in operating systems, a semaphore is a variable 
or abstract data type that is used for controlling access, by multiple processes, 
to a common resource in a parallel programming or a multi-user environment.

Monday 20 January 2014

Mapping a Filter directly to a Servlet

I guess we have all used filters in our web projects. The common approach that I have followed is specifying the URL patterns to be intercepted by the filter.
<filter>
    <filter-name>someFilter</filter-name>
    <filter-class>com.filter.SomeFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>someFilter</filter-name>
    <url-pattern>*.do</url-pattern>
</filter-mapping>
All urls having the .do extension will now pass through the filter. There is also one more way to specify the filter pattern.

Monday 13 January 2014

Which Log message belongs to which user ?

I created a very simple web application. In it any calls to URLs ending in ".do" reach the below servlet :

Thursday 9 January 2014

Handlers and Interceptors in CXF - Are they related ?

I have been trying out some things in CXF (and also feeling pretty good about it :P ) The other day I needed to modify the message of more than one web service in a common manner. I achieved the same using a CXF interceptor. However another team member did the same task using Handlers. Interestingly Handler is more a part of the JAX-WS vocabulary than Interceptor. So I decided to look at this option too.

Thursday 2 January 2014

Writing Logs to the Database

With loggers we have something called as an Appender. Simply defined an appender is a component responsible  for taking a log request, building the log message in a suitable format and sending it to the output device.