Saturday, July 30, 2016

HAX kernel module is not installed

Hi Guys,
You might have seen this error message when you try to run for application in Android Developer Studio . There can be several reasons for this .
1. You have not installed Intel x86 emulator Accelerator .
Solution : Go to android Sdk Manager and check the option   Intel x86 emulator Accelerator . Android Developer Studio will download it to your Skd path . Go to your SDK Path and install it .

2. Virtualization is disabled in your BIOS setting .
Solution : If you get the same error after solution 1.  Go to BIOS menu and enable Hardware Virtualization .

3. Microsoft-Hyper-V is enabled 
Solution : You need to disble Microsoft-Hyper-V if it is enabled .

Monday, July 25, 2016

org.hibernate.exception.SQLGrammarException

Following are reasons of SQLGrammarException:

1. if the  type of id is different than the type of object passed as a parameter to session.get method .

Sunday, July 24, 2016

415 Unsupported Media Type

Hi Guys,

You might face this error while hitting a rest service which consumes request in JSON format.
Developers this might face this error when they are testing a spring based rest service.
Even if you have the dependent jars in place and spring application is successfully deployed you may still face this issue. The solution to this is include the following dependency in your pom.ml if you are using maven project.

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.8.1</version>
</dependency>

This is actually required when your spring controller is using @RequestBody.Eventhough the spring documentation site mentions this in their site you will not be prompted for a compilation error or runtime error even if you do not include the above dependency.

Error getting reflective information for class org.springframework.web.servlet.DispatcherServlet

Hi Guys ,
You might experience Error getting reflective information for class org.springframework.web.servlet.DispatcherServlet error while deploying any spring MVC project to wildfly.

Full stack trace is as below:


12:37:48,987 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.deployment.unit."org.myProject.question.model.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."org.myProject.question.model.war".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of deployment "org.myProject.question.model.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:127) [jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_91]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_91]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_91]
Caused by: java.lang.RuntimeException: JBAS018757: Error getting reflective information for class org.springframework.web.servlet.DispatcherServlet with ClassLoader ModuleClassLoader for Module "deployment.org.myProject.question.model.war:main" from Service Module Loader
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:72) [jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:58)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:107)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:92)
at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:77)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:120) [jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
... 5 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/web/context/request/async/CallableProcessingInterceptor
at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.8.0_91]
at java.lang.Class.privateGetDeclaredFields(Class.java:2583) [rt.jar:1.8.0_91]
at java.lang.Class.getDeclaredFields(Class.java:1916) [rt.jar:1.8.0_91]
at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57) [jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:68) [jboss-as-server-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]
... 10 more
Caused by: java.lang.ClassNotFoundException: org.springframework.web.context.request.async.CallableProcessingInterceptor from [Module "deployment.org.myProject.question.model.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:443) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:431) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:373) [jboss-modules.jar:1.3.0.Final-redhat-2]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:118) [jboss-modules.jar:1.3.0.Final-redhat-2]
... 15 more

12:37:49,000 ERROR [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "org.myProject.question.model.war" was rolled back with the following failure message: 
{"JBAS014671: Failed services" => {"jboss.deployment.unit.\"org.myProject.question.model.war\".POST_MODULE" => "org.jboss.msc.service.StartException in service jboss.deployment.unit.\"org.myProject.question.model.war\".POST_MODULE: JBAS018733: Failed to process phase POST_MODULE of deployment \"org.myProject.question.model.war\"
    Caused by: java.lang.RuntimeException: JBAS018757: Error getting reflective information for class org.springframework.web.servlet.DispatcherServlet with ClassLoader ModuleClassLoader for Module \"deployment.org.myProject.question.model.war:main\" from Service Module Loader
    Caused by: java.lang.NoClassDefFoundError: org/springframework/web/context/request/async/CallableProcessingInterceptor
    Caused by: java.lang.ClassNotFoundException: org.springframework.web.context.request.async.CallableProcessingInterceptor from [Module \"deployment.org.myProject.question.model.war:main\" from Service Module Loader]"}}
12:37:49,065 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015877: Stopped deployment org.myProject.question.model.war (runtime-name: org.myProject.question.model.war) in 65ms


You might have notices the  root cause is java.lang.NoClassDefFoundError: org/springframework/web/context/request/async/CallableProcessingInterceptor

If you have the same root cause , you can try the following solutions that worked for me:
1. If you are using maven delete all the repositories , do a fresh clean install and deploy the war file again.
2. If you are using eclipse to add the project to wildfly , use wildfly admin console.

References :
SO



Friday, July 22, 2016

Spring Transactions

Hello Guys ,
Let us explore spring transactions API.
Transaction Management is a part of Data Access.
Let us understand through an example.We will use Hibernate framework in this example for data access. To make spring aware of our this we have to define the bean in spring configuration xml as below:

<bean id="myTxnManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>

<tx:annotation-driver transaction-manager="myTxnManager" >

The use of transaction manager is maintain data consistency.


Wednesday, June 15, 2016

Maven

Maven is a building tool.
Features of maven :
pom.xml  : an XML for project as well as a module . You can specify the build related information in pom.xml  and maven takes care of build , packaging etc.
Unit Testing : You can run your junit as part of the build , maven also generates report for the test result.
Repository : maven has its own repository with almost all major library jars available.
Local repository : its a directory in users PC which has the jars downloaded from the server repository.
Resources: maven automatically takes care of moving your xmls,property files appropriate places. You can add the xmls,property files to resources folder.

Set up Maven :
Repository :
You can set the location of maven repository in file setting.xml  at path MAVEN_HOME/conf




Saturday, June 11, 2016

spring mvc simple example


Hadoop Simple Example


Three friends went on trip , each paying bills which needs to be split among them.

We need to write a MapReduce Job

References

Hadoop


Hadoop is a programming framework used to process Big Data over a network. First we need to understand big data.The definition of Big data is as follows:

extremely large data sets that may be analysed computationally to reveal patterns, trends, and associations, especially relating to human behaviour and interactions.

Let us classify Big data into 3 types:
  • Structured Data
  • Semi Structured Data
  • Unstructured Data

Structured data is like the data stored in the SQL tables of Relational database.

Semi Structured data is like the data stored in the XMLs.

Unstructured Data is the data stored in word document or pdf .

To process big data over a network google has developed an algorithm known as MapReduce which Hadoop has made use of.

Let's try a Simple Example to understand

References

Agile Methodology

The definition of agile is
Agile software development is a set of principles for software development in which requirements and solutions evolve through collaboration between self-organizing, cross-functional teams

The methods of Agile are :

Scrum : A product owner lists down the requirements which are called as backlogs. Cross functional teams lead by the Scrum Master picks up the backlog according to the priority and deliver it in successive sprints .

Lean : it focusses on
eliminations of waste.
Deciding as late as possible , delivering as early as possible.
Amplifying learning , building integrity in and seeing the whole.

Kanban : principle of kanban are :
Visualize what you have done today.
Limit the amount of work in progress.
Enhance flow.

Extreme Programming :The supporting practices of this methodology are:
Planning Game
Small Releases
Customer Acceptance Tests
Simple Design
Pair Programming
Test-Driven Development
Refactoring
Continuous Integration
Collective Code Ownership
Coding Standards
Metaphor
Sustainable Pace

References

https://www.versionone.com/agile-101/agile-methodologies/

Spring Mvc Testing

Testing Spring MVC is used to test MVC applications developed in spring.To remove the dependency of the application server and few object we need to  Mock it.The web application dependency includes servlet handler , resource handler , exception handler , view handler.
This tutorial requires minimum of Junit 4.9 , javax-servlet-api 3.0.2. You might face Spring4TestRunner exception and NoClassDefFound javax.servlet.SessionCookieConfig
If there any autowired beans in your controller class you might face an exception like IllegalState Failed to load ApplicationContext
Reference:
http://blog.zenika.com/2013/01/15/spring-mvc-test-framework/
http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers-configuration/

Sunday, May 22, 2016

Hosting a SOAP Web Service Java


Step 1
Create a dynamic web project in eclipse
Create an endpoint interface
package org.myProject.passwordManager;
 import javax.jws.WebMethod;
 import javax.jws.WebService;
 @WebService public interface PasswordManagerWS {
 @WebMethod public abstract String getPassword(String appId);
 }
Create an implementation of Web Service
package org.myProject.passwordManager;
 import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding; @WebService(endpointInterface="org.myProject.passwordManager.PasswordManagerWS", serviceName="PasswordManagerWS")
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT)
 public class PasswordManagerWSImpl implements PasswordManagerWS{
 @WebMethod public String getPassword(@WebParam(name="appId")String appId) { System.out.println("test ws"); return "test";
 }
 }

SOAP Web Services Java


Web Services are generally used for machine to machine communication.SOAP is a protocol for communication.

Topics

Hosting a SOAP Web Service

Monday, January 18, 2016

Proxy Class in java


What is a Proxy Class?

Proxy is a class in java which is used to create a dynamic class.

Why do we use proxy class?

links

description

Web Services Interview Questions


Web services is vast topic , lets start with creating a simple web service.I have tried explaining the concepts using a sample code ,In any point if you are unable to understand please go through the documentation links .
  • Create a sample web service as below
package org.myProject;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface TestWS {
@WebMethod
public abstract String getMethod(String param);
}
TestWS is a web service
  • Implement the web service
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
@WebService(endpointInterface="org.myProject.TestWS",serviceName="TestWS")
@SOAPBinding(style=SOAPBinding.Style.DOCUMENT)
public class TestWSImpl implements TestWS{
@WebMethod
public String getMethod(@WebParam(name="param")String param) {
System.out.println("test ws");
return "test";
}
}
In addition to implementing the method getMethod , a service name is also specified for the web service.
We have linked TestWSImpl class to TestWS using annotation param endpointInterface="org.myProject.TestWS" . Now,as we know, web service is a communication between two machines via xml messages , so an endpoint is reference to which messages are addressed.
  • Host the web service
There are several ways to host your web service.I choose to host it through jboss EAP 6.The web service need to be packaged in war file and deployed to jboss .
Service name is to be mapped in web.xml as below:
<servlet>
<servlet-name>PasswordManagerWSImpl</servlet-name>
<servlet-class>org.myProject.passwordManager.PasswordManagerWSImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PasswordManagerWSImpl</servlet-name>
<url-pattern>/TestWS</url-pattern>
</servlet-mapping>

Once the server is up and running , you can verify whether the web service is hosted properly
Go the following url
http://localhost:8089/TestWebService/TestWS?wsdl
Replace TestWebService with the name of WAR file deployed.
If on hitting the link you are able to get the WSDL then the web service is successfully hosted.
WSDL has the details of the web service which is used by the client to communicate to the web service.
  • Client Interaction with the web service
QName qName=new QName("http://myProject.org/","TestWS");
URL url=new URL("http://localhost:8089/TestWebService/TestWS?wsdl");
Service service=Service.create(url,qName);
TestWS webSer=service.getPort(TestWS.class);
String test=webSer.getMethod("test");
A QName object is created by passing namespaceURI as targetNamespace and localPost as service name from WSDL.
URL object is created by passing url of WSDL.
References:

Struts 1 Interview Question

ec2-user@ec2 Permission denied