Thursday, 7 July 2016

spring jersey intigration

steps 1 :

in web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name>Archetype Created Web Application</display-name>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>\WEB-INF\ApplicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
<servlet-name>jerseyService</servlet-name>
<servlet-class> com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.spi.spring.container.servlet.SpringServlet</param-name>
<param-value>com.jersey.api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jerseyService</servlet-name>
<url-pattern>/v1/*</url-pattern>
</servlet-mapping>

</web-app>

step 2: application context in web-inf folder.
include namepace for spring module.
ref : http://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/html/xsd-config.html

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
 
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd " >

<context:component-scan base-package="com.jersey.api" />

 
</beans>

step 3: configure pom with spring,spring-jersey depencdency

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.myjersey</groupId>
  <artifactId>Onejersey</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Onejersey Maven Webapp</name>
  <url>http://maven.apache.org</url>

  <properties>
  <jersey.spring>1.9</jersey.spring>
  </properties>
 




  <dependencies>


  <!-- spring  -->
 
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-core</artifactId>
   <version>4.1.4.RELEASE</version>
</dependency>
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-beans</artifactId>
   <version>4.1.3.RELEASE</version>
</dependency>
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context</artifactId>
   <version>4.1.3.RELEASE</version>
</dependency>
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-web</artifactId>
   <version>4.1.3.RELEASE</version>
</dependency>


 

  <!-- spring  -->


  <!-- jersey  -->
  <dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-server</artifactId>
   <version>1.9</version>
</dependency>
<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-json</artifactId>
   <version>1.9</version>
</dependency>
<dependency>
   <groupId>com.sun.jersey.contribs</groupId>
   <artifactId>jersey-multipart</artifactId>
   <version>1.9</version>
</dependency>


  <!-- jersey -->
 
    <!-- spring-jersey  -->
  <dependency>
   <groupId>com.sun.jersey.contribs</groupId>
   <artifactId>jersey-spring</artifactId>
   <version>${jersey.spring}</version>
   <exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
   
   </exclusions>
</dependency>

<!-- jackson -jaxrs  -->
<dependency>
   <groupId>com.fasterxml.jackson.jaxrs</groupId>
   <artifactId>jackson-jaxrs-json-provider</artifactId>
   <version>2.5.5</version>
</dependency>
<!-- jackson -jaxrs  -->


    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>Onejersey</finalName>
  </build>
</project>






step 4 : java application



/**
 *
 */
package com.jersey.api;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;

import org.springframework.stereotype.Service;

/**
 * @author voice
 *
 */
@Service
@Path("/hello")
public class Employee {

@GET
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response helloWorld(){
ResponseBuilder rs = Response.status(Status.OK);
System.out.println("HI this is jagdeesh");
return rs.build();
}

}





ref :
spring-jersey
spring module

Saturday, 2 July 2016

difference betweeh length and length() in java

difference betweeh length and length() in java

description : To find the length of array we use legth.

ex : define and intiger array and find the length of the array.
int[] number =  new int[3];
number[0] = 1;
number[1] = 3;
number[2] = 5;

int secondHighest = number.length;
output : 3

description : To find the length of string we use legth().

String name = "voice";
System.out.println(name.length() + " length");

output : 5

Friday, 1 July 2016

Several ports (8005, 8080, 8009) required by Tomcat Server at localhost are already in use


Several ports (8005, 8080, 8009) required by Tomcat Server at localhost are already in use

do : netstat -a -o -n

kill process id : taskkill /F /PID 6532

ref : stackoverflow

Wednesday, 29 June 2016

RDS in aws.

RDS in aws.

Three steps to launch mysql on RDS.
1.Launch.
2.Connect.
3.Manage and moniter.

step 1. launch
a. create db instance.
b. Select engine :
Select db instance from option ex : here we choose mysql from option. (amazon aurora/mariadb/postgresql/oracle/sqlserver).
c. Production :
DEV/test (mysql/amazon aurora).
d. specify db details.
click on (Only show options that are eligible for RDS Free Tier) its a db.t2.micro instance.
select :
DB Instance Identifier* : mydbname
Master Username* : myusername
Master Password : mypassword
Confirm Password : mypassword

version : 5.6.29

select default security group:
default
give DB name.

Click on launch.

Monday, 27 June 2016

java.lang.IllegalStateException: LifecycleProcessor not initialized

java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: Root WebApplicationContext: startup date


check the configuration in
1. applicationcontext.xml
2.pom.xml

observation :
1. make sure to upgrade dependency to 4.0 release or 3.0 release.




Thursday, 23 June 2016

Unknown provider: $stateProvider

[$injector:unpr] Unknown provider: $stateProvider <- $state <- LoginCtrl

problem :
missing angular-ui-router.js

<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>


steps :
1.
go the project folder and from commandline.

cmd :  bower install angular-ui-router

ref : git

the above command will download package

2. start grunt server

cmd : grunt serve

Wednesday, 22 June 2016

start writing a project in yoman for angular js project

start writing a project in yeoman for angular js project

IN the app folder.

project structure is


1. images.
2. script
2.1 controller folder (all the controller are stored here.)
2.2 app.js (for routing the pages.)
3.style.
4. views. (all the static html stored here.)

create a module address.

1. Create a listItem in index.html in the navigation bar.
ex : <li><a ng-href="#/address">Address</a></li>

2. create a route in app.js

ex :

.when('/address', {
 templateUrl : 'views/address.html',
 controller : 'AdressCtrl',
 controllerAs : 'contact'
 })
3. create address.js in script/controller folder and write adress controller.
ex :
angular.module('scjavaApp')
.controller('AdressCtrl',function(){
console.log("Hhi this from controller");

});

4. In view folder create address.html
<div>
HI this from address page.
</div>

start grunt server and check