Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TestWS-persistence/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand Down
2 changes: 0 additions & 2 deletions TestWS-persistence/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
26 changes: 18 additions & 8 deletions TestWS-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,15 @@
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
Expand All @@ -78,6 +76,12 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<exclusions>
<exclusion>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
Expand All @@ -88,6 +92,12 @@
<artifactId>hibernate-validator</artifactId>
</dependency>

<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
</dependency>


<!-- Apache BDCP Connection Pool Dependency -->
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
*
*/
@Configuration
@ComponentScan(basePackages = { "com.imt.test" })
@ComponentScan(basePackages = { "com.imt.test.persistence" })
@EnableTransactionManagement
@EnableJpaRepositories("com.imt.test.persistence.repo")
@EnableJpaRepositories(basePackages = { "com.imt.test.persistence.repo" })
public class PersistenceContextConfig {

@Autowired
Expand Down
1 change: 1 addition & 0 deletions TestWS-service/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
Expand Down
3 changes: 0 additions & 3 deletions TestWS-service/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
*
*/
package com.imt.test.service.base;

import java.util.Locale;

import org.springframework.context.MessageSource;

/**
* @author imteyaza
*
*/
public interface MessageSourceService extends MessageSource {
Locale defaultLocale = Locale.US;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
*/
package com.imt.test.service.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

/**
* @author imteyaza
Expand All @@ -14,4 +16,12 @@
@ComponentScan(basePackages = { "com.imt.test", "com.imt.test.persistence" })
public class ServiceContextConfig {

@Bean(name = "messageSource")
public ReloadableResourceBundleMessageSource resourceBundleMessageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasenames("classpath:messages");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
*
*/
package com.imt.test.service.impl;

import java.util.Locale;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.stereotype.Component;

import com.imt.test.service.base.MessageSourceService;

/**
* @author imteyaza
*
*/
@Component
public class MessageSourceServiceImpl implements MessageSourceService {

@Autowired
@Resource(name="messageSource")
private MessageSource messageSource;

/*
* (non-Javadoc)
*
* @see
* org.springframework.context.MessageSource#getMessage(java.lang.String,
* java.lang.Object[], java.lang.String, java.util.Locale)
*/
@Override
public String getMessage(String code, Object[] args, String defaultMessage,
Locale locale) {
return messageSource.getMessage(code, args, defaultMessage, locale);
}

/*
* (non-Javadoc)
*
* @see
* org.springframework.context.MessageSource#getMessage(java.lang.String,
* java.lang.Object[], java.util.Locale)
*/
@Override
public String getMessage(String code, Object[] args, Locale locale)
throws NoSuchMessageException {
// TODO Auto-generated method stub
return messageSource.getMessage(code, args, locale);
}

/*
* (non-Javadoc)
*
* @see
* org.springframework.context.MessageSource#getMessage(org.springframework
* .context.MessageSourceResolvable, java.util.Locale)
*/
@Override
public String getMessage(MessageSourceResolvable resolvable, Locale locale)
throws NoSuchMessageException {
// TODO Auto-generated method stub
return messageSource.getMessage(resolvable, locale);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
*
*/
package com.imt.test.service.util;

/**
* @author imteyaza
*
*/
public interface ErrorMessageKey {

String FIRST_NAME = "label.firstName";
}
4 changes: 4 additions & 0 deletions TestWS-service/src/main/resources/messages_en_US.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
label.title=Spring Mvc I18N Example
label.heading=Spring MVC Internationalization (i18n) Example
label.firstName=First Name
label.lastName=Last Name
4 changes: 4 additions & 0 deletions TestWS-service/src/main/resources/messages_es.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
label.title=Spring Mvc I18N Example
label.heading=Spring MVC Internationalization (i18n) Example
label.firstName=Nombre
label.lastName=apellido
4 changes: 4 additions & 0 deletions TestWS-service/src/main/resources/messages_pt.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
label.title=Spring Mvc I18N Example
label.heading=Spring MVC Internationalization (i18n) Example
label.firstName=primeiro nome
label.lastName=Sobrenome
2 changes: 1 addition & 1 deletion TestWS-web/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry including="**/*.java" kind="src" path="src/main/resources"/>
<classpathentry kind="src" path="src/main/webapp"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
Expand Down
2 changes: 0 additions & 2 deletions TestWS-web/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
40 changes: 38 additions & 2 deletions TestWS-web/src/main/java/com/imt/test/web/config/WebMvcConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,28 @@
*/
package com.imt.test.web.config;

import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

Expand All @@ -28,7 +36,7 @@
@Configuration
@ComponentScan(basePackages = { "com.imt.test" })
@PropertySource(value = { "classpath:application.properties" })
public class WebMvcConfig extends WebMvcConfigurerAdapter {
public class WebMvcConfig extends WebMvcConfigurationSupport {

@Autowired
private Environment environment;
Expand Down Expand Up @@ -64,4 +72,32 @@ public PropertySourcesPlaceholderConfigurer configurer() {
return propertySourcesPlaceholderConfigurer;

}

@Bean
public SessionLocaleResolver sessionLocaleResolver() {
SessionLocaleResolver resolver = new SessionLocaleResolver();
resolver.setDefaultLocale(new Locale("en"));
return resolver;
}

@Bean
public HandlerInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
localeChangeInterceptor.setParamName("lang");
return localeChangeInterceptor;
}

@Bean
RequestMappingHandlerMapping handlerMapping() {
RequestMappingHandlerMapping mapping = new RequestMappingHandlerMapping();
mapping = super.requestMappingHandlerMapping();
mapping.setInterceptors(getInterceptors());
return mapping;
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
// TODO Auto-generated method stub
registry.addInterceptor(localeChangeInterceptor());
}
}
34 changes: 25 additions & 9 deletions TestWS-web/src/main/webapp/WEB-INF/views/home.jsp
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<%@ page contentType="text/html;charset=UTF-8" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<html>
<head>
<title>Spittr</title>
<link rel="stylesheet"
type="text/css"
href="<c:url value="/resources/style.css" />" >
<title>Spring MVC Hello World</title>
</head>

<body>
<h1>Welcome to TestWS</h1>
<a href="<c:url value="/spittles" />">Spittles</a> |
<a href="<c:url value="/spitter/register" />">Register</a>
<h2><spring:message code="lbl.page" text="All Employees in System" /></h2>

<table border="1">
<tr>
<th><spring:message code="lbl.Id" text="Employee Id" /></th>
<th><spring:message code="lbl.firstName" text="First Name" /></th>
<th><spring:message code="lbl.lastName" text="Last Name" /></th>
</tr>
<c:forEach items="${employees}" var="employee">
<tr>
<td>${employee.id}</td>
<td>${employee.firstName}</td>
<td>${employee.lastName}</td>
</tr>
</c:forEach>
</table>

</body>
</html>
8 changes: 7 additions & 1 deletion TestWS-web/src/main/webapp/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
db.url=jdbc:mysql://localhost:3306/imti
#Database Related Configurations
db.url=jdbc:mysql://localhost:3306/imti
db.driver=com.mysql.jdbc.Driver
db.username=root
db.password=root
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
1 change: 1 addition & 0 deletions TestWS-webservice/.project
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
Expand Down
3 changes: 0 additions & 3 deletions TestWS-webservice/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
Loading