Skip to content

Instantly share code, notes, and snippets.

View eugenp's full-sized avatar

Eugen eugenp

View GitHub Profile
@eugenp
eugenp / HTTPLinkHeaderUtil.java
Created January 5, 2014 15:58
Extracting Link rel values
public static String extractURIByRel(final String linkHeader, final String rel) {
if (linkHeader == null) {
return null;
}
String uriWithSpecifiedRel = null;
final String[] links = linkHeader.split(", ");
String linkRelation = null;
for (final String link : links) {
final int positionOfSeparator = link.indexOf(';');
@eugenp
eugenp / SpringConfig.xml
Created March 11, 2012 15:26
Project configuration with Spring - Spring XML config
<?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-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
@eugenp
eugenp / Q1.java
Created March 5, 2012 11:30
Interview Question:
package com.macys.rest.common;
import java.util.HashSet;
import java.util.Set;
/**
* - link: http://thenoisychannel.com/2011/08/08/retiring-a-great-interview-problem/ <br>
* Given an input string and a dictionary of words, segment the input string into a space-separated sequence of dictionary words if possible.
* For example, if the input string is "applepie" and dictionary contains a
* standard set of English words, then we would return the string "apple pie" as output.
@eugenp
eugenp / pom.xml
Created February 25, 2012 23:00
RestTemplate with Authentication in Spring 3.1 - Maven dependencies
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.1.4</version>
@eugenp
eugenp / RestTemplateFactory.java
Created February 25, 2012 22:20
RestTemplate with Authentication in Spring 3.1
@Component
public class RestTemplateFactory implements
FactoryBean< RestTemplate >, InitializingBean{
private RestTemplate restTemplate;
public RestTemplate getObject(){
return restTemplate;
}
public Class< RestTemplate > getObjectType(){
return RestTemplate.class;
@eugenp
eugenp / PropertyEnvironment.java
Created February 6, 2012 14:36
Properties with Spring - Injecting Properties via Environment
@Autowired
private Environment env;
...
dataSource.setUrl(env.getProperty("jdbc.url"));
@eugenp
eugenp / PropertyUsageInXML.xml
Created February 6, 2012 14:35
Properties with Spring - Injecting Properties in XML
<bean id="dataSource">
<property name="url" value="${jdbc.url}" />
</bean>
@eugenp
eugenp / PropertyValueAnnotation.java
Created February 6, 2012 14:32
Properties with Spring - Injecting Properties with @value
@Value( "${jdbc.url}" )
private String jdbcUrl;
@eugenp
eugenp / PropertyManualXML_3.1.xml
Created February 6, 2012 14:31
Properties with Spring - Register Property manually in XML with Spring 3.1
<bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
<property name="location">
<list>
<value>classpath:foo.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
@eugenp
eugenp / PropertyManualJava_3.1.java
Created February 6, 2012 14:28
Properties with Spring - Register Property manually in Java with Spring 3.1
@Bean
public static PropertySourcesPlaceholderConfigurer properties(){
PropertySourcesPlaceholderConfigurer pspc =
new PropertySourcesPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[ ]
{ new ClassPathResource( "foo.properties" ) };
pspc.setLocations( resources );
pspc.setIgnoreUnresolvablePlaceholders( true );
return pspc;
}