Skip to content

Instantly share code, notes, and snippets.

Avatar

Eugen eugenp

View GitHub Profile
@eugenp
eugenp / HTTPLinkHeaderUtil.java
Created Jan 5, 2014
Extracting Link rel values
View HTTPLinkHeaderUtil.java
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 Mar 11, 2012
Project configuration with Spring - Spring XML config
View SpringConfig.xml
<?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 Mar 5, 2012
Interview Question:
View Q1.java
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 Feb 25, 2012
RestTemplate with Authentication in Spring 3.1 - Maven dependencies
View pom.xml
<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 Feb 25, 2012
RestTemplate with Authentication in Spring 3.1
View RestTemplateFactory.java
@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 Feb 6, 2012
Properties with Spring - Injecting Properties via Environment
View PropertyEnvironment.java
@Autowired
private Environment env;
...
dataSource.setUrl(env.getProperty("jdbc.url"));
@eugenp
eugenp / PropertyUsageInXML.xml
Created Feb 6, 2012
Properties with Spring - Injecting Properties in XML
View PropertyUsageInXML.xml
<bean id="dataSource">
<property name="url" value="${jdbc.url}" />
</bean>
@eugenp
eugenp / PropertyValueAnnotation.java
Created Feb 6, 2012
Properties with Spring - Injecting Properties with @value
View PropertyValueAnnotation.java
@Value( "${jdbc.url}" )
private String jdbcUrl;
@eugenp
eugenp / PropertyManualXML_3.1.xml
Created Feb 6, 2012
Properties with Spring - Register Property manually in XML with Spring 3.1
View PropertyManualXML_3.1.xml
<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 Feb 6, 2012
Properties with Spring - Register Property manually in Java with Spring 3.1
View PropertyManualJava_3.1.java
@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;
}