Archive

Archive for the ‘Java’ Category

How to unit test Hibernate DAO’s with H2 and Spring

May 12, 2014 Comments off

Source can be downloaded from link;

Writing Unit test cases are very common these days.We can write a Unit test for the functionality with Mocking.I personally feel we should not do Mocking while testing DAO.I prefer to write test cases for the DAO’s by pointing to the Database itself.Here the problem is we cannot execute tests on the production or development database since it will spoil the existing data, because we can build the same project any number of time, especially when we configure continues integration.

In memory databases or file based database comes in handy in this particular situation.There are lot many databases available of this kind like h2, HSQLDB e.t.c.

Here below i have extended a sample created in the below post and have written unit test with h2 database.

Link : http://examples.javacodegeeks.com/enterprise-java/spring/jpaorm/spring-hibernate-mysql-and-maven-showcase/

Project Structure

Image

 

Create a test class with the similar package structure as source class in src/test/java

Image

Sample Insert.sql below.

Image

Sample delete.sql below

Image

Now the main part come into the picture.applicationcontext.xml

We need to configure the h2 database data source as per below.

Image

and the Session Factory as per below.

Image

and we have to add spring-test dependency to the pom file.

Image

Categories: H2, Hibernate, Java, Maven, Spring Tags:

Performance optimizations for Apache Camel

April 16, 2014 Comments off
Categories: Apache Camel, Java Tags:

Integrating WebDav enabled server to a java applications

February 23, 2014 Comments off

HI Guys, this time my task is to integrate a WebDav enabled server to my java application.First of all, what is WevDav, sound completely new? with a quick google search I landed on this link.

Web Distributed Authoring and Versioning (WebDAV) is an extension of the Hypertext Transfer Protocol (HTTP) that facilitates collaboration between users in editing and managing documents and files stored on World Wide Web servers.

I am not going much into details about the WevDav.But it’s a really cool standard for collaboration over Http.

By implementing WebDAV we can make our web server/application server to behave like a cloud storage.

Link for converting tomcat to a WebDav Server

similar way we can convert Apache HTTP server as a WebDAV server.

The browser is the best client to navigate through the webdav server.but it you want to integrate with your java application, Home :there are quite a few apis available like Sardine, Jackrabbit e.t.c.After a long research i found Saradine in is the most easiest api to use.so i continued with saradine.

Note : Disadvantage of Saradine is most of the security protocols are implemented,but i faced few problems with NTML authentication.now i am testing it,will post the results once it is completed.

Below are the few useful links for using sardine.

PrHome:https://github.com/lookfirst/sardine

working with saradine is straightforward.check out the code and have a look at its test.

Restrictions : 

Sardine validates https certificates very strictly.if you want to ignore the certificated u have to implement your own httpclient object and pass it to the SaradineImpl class and construct.

please leave a post if any one needs some help while implementing this.

Categories: Cloud, General, Java, Storage Tags: ,

Integrating Ubuntu One drive to a java Application.

January 6, 2014 Comments off

HI Guys,I have been working for a while on integrating Ubuntu One cloud storage  and i would like to share my experiences here.

First of all What is Ubuntu One ? Ubuntu One is a cloud space provided by ubuntu, like dropbox,google drive e.t.c.The advantage Ubuntu One gives

  • Gives you 5Gb of free space,to store any thing whatever you would like.
  • All latest versions of Ubunutu distributions comes with Ubuntu One pre-installed.so not need to install any extra clients.
  • It has provided a rich set of apis for application integration as REST services.
  • Web client,where you can view,download and upload files without installing any of the client.

Now the pain points :

  • even though Ubuntu One has provided apis with documentation,its really hard to find out quick samples for java.so,after a long struggle i have found out few projects in the Ubuntu Code Space.

Ubuntu One uses OAuth 1.0 authentication while communicating with their apis.

Below are the Useful Links.

Ubuntu One api Documentation : https://one.ubuntu.com/developer/

Ubuntu One java api : https://launchpad.net/ubuntuone-files-java-library

Ubuntu One java api source : http://bazaar.launchpad.net/~ubuntuone-client-engineering/ubuntuone-files-java-library/trunk1.x/files

You can download the code,modify and use it.

Note : Check the license,before you redistribute this.

I will post few examples and sample projects in my next posts.

Good Links

June 30, 2013 Comments off

Interview Preparation

Data Structures and Algorithms

Sample Questions: http://www.qubeet.com/

Linked List: http://giridhar-mb.blogspot.in/2012/11/linked-list-implementation-in-java.html?_sm_au_=iNsvkqGtW40Fn0st

Quick Sort: http://www.vogella.com/articles/JavaAlgorithmsQuicksort/article.html?_sm_au_=iNsvkqGtW40Fn0st

Bubble Sort: http://www.cs.rit.edu/~atk/Java/Sorting/sorting.html?_sm_au_=iNsvkqGtW40Fn0st

All Sorts: http://thilinasameera.wordpress.com/2011/06/01/sorting-algorithms-sample-codes-on-java-c-and-matlab/?_sm_au_=iNsvkqGtW40Fn0st#_Insertion_Sort

Java

http://javarevisited.blogspot.in/

http://howtodoinjava.com/?_sm_au_=i7s4kDQ0LfD1sfNM

Java Threads and Concurrency

http://jlunaquiroga.blogspot.in/2013/04/java-concurrency-part-1.html?_sm_au_=i7s4kDQ0LfD1sfNM

Java Collections

http://jlunaquiroga.blogspot.in/2013/06/java-collections-framework-part-1-intro.html?_sm_au_=i7s4kDQ0LfD1sfNM

Spring

http://javacodebook.com/category/spring/spring-book/?_sm_au_=i7s4kDQ0LfD1sfNM#

Hibernate Exception – No CurrentSessionContext configured

June 30, 2013 Comments off

Java – Response was of unexpected text/html ContentType. Incoming portion of HTML stream: (none)

June 30, 2013 Comments off

Exception :

javax.xml.ws.soap.SOAPFaultException: Response was of unexpected text/html ContentType.  Incoming portion of HTML stream: (none)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:146)
at $Proxy701.processThirdPartyRequest(Unknown Source)
at com.mt.tpi.event.processor.TpiResponseProcessor.process(TpiResponseProcessor.java:112)
at com.mt.tpi.event.processor.TpiResponseProcessor.process(TpiResponseProcessor.java:31)
at com.mt.event.jms.receiver.JMSMessageReceiver.onMessage(JMSMessageReceiver.java:73)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:518)
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:479)
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:451)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:323)
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:261)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:982)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:974)
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:876)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.cxf.interceptor.Fault: Response was of unexpected text/html ContentType.  Incoming portion of HTML stream: (none)
at org.apache.cxf.interceptor.StaxInInterceptor.handleMessage(StaxInInterceptor.java:79)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:762)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1582)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1467)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1375)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:56)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:623)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:510)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:440)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:343)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:295)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
… 13 more
~

Solution

Check the WSDL URL.

URL has to be given till ?wsdl

%d bloggers like this: