Skip to content

Instantly share code, notes, and snippets.

View altfatterz's full-sized avatar
👨‍💻
Playing

Zoltan Altfatter altfatterz

👨‍💻
Playing
View GitHub Profile
java -jar target/spring-caching-1.0-SNAPSHOT.jar --spring.profiles.active=ehcache
localhost:~ zoltan$ curl localhost:8080/lookup?name=backbase
{"name":"Backbase","website":"http://www.backbase.com/","lookupTime":90}localhost:~ zoltan$ curl localhost:8080/lookup?name=backbase
{"name":"Backbase","website":"http://www.backbase.com/","lookupTime":62}localhost:~ zoltan$ curl localhost:8080/lookup?name=backbase
{"name":"Backbase","website":"http://www.backbase.com/","lookupTime":65}localhost:~ zoltan$ curl localhost:8080/lookup?name=backbase
{"name":"Backbase","website":"http://www.backbase.com/","lookupTime":70}localhost:~ zoltan$
mvn clean install
java -jar target/spring-caching-1.0-SNAPSHOT.jar
@RequestMapping(method = RequestMethod.GET)
public @ResponseBody Page lookup(@RequestParam String name) {
long start = System.currentTimeMillis();
Page page = facebook.findPage(name);
long elapsed = System.currentTimeMillis() - start;
page.setLookupTime(elapsed);
return page;
}
@Configuration
@EnableCaching
@Profile("redis")
public class RedisConfiguration {
@Bean
JedisConnectionFactory connectionFactory() {
return new JedisConnectionFactory();
}
@Configuration
@EnableCaching
@Profile("hazelcast")
public class HazelcastConfiguration {
@Bean
HazelcastCacheManager hazelcastcacheManager() throws Exception {
return new HazelcastCacheManager(hazelcastInstance());
}
@Configuration
@EnableCaching
@Profile("ehcache")
public class EhCacheConfiguration {
@Bean
EhCacheCacheManager ehCacheCacheManager() {
return new EhCacheCacheManager(ehCacheManagerFactoryBean().getObject());
}
@Service
public class FacebookLookupService {
private static final Logger LOGGER = LoggerFactory.getLogger(FacebookLookupService.class);
private RestTemplate restTemplate;
@Autowired
public FacebookLookupService(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
public class UserDetailsServiceAdapter implements UserDetailsService {
@Autowired
private AccountRepository accountRepository;
@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
Account account = accountRepository.findByEmail(username);
if (account == null) {
throw new UsernameNotFoundException(username);
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/signup", "/static/**").permitAll()
.antMatchers("/code").hasRole("PRE_AUTH_USER")
.antMatchers("/home").hasRole("USER")
.anyRequest().authenticated();
http.formLogin()
.loginPage("/login")