Skip to content

Instantly share code, notes, and snippets.

View eugenp's full-sized avatar

Eugen eugenp

View GitHub Profile
@eugenp
eugenp / PropertyManualXML_3.0.xml
Created February 6, 2012 14:25
Properties with Spring - Register Property manually in XML and Spring 3.0
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<list>
<value>classpath:foo.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>
@eugenp
eugenp / PropertyManualJava.java
Created February 6, 2012 14:19
Properties with Spring - Register Property manually in Java
@Bean
public static PropertyPlaceholderConfigurer properties(){
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
Resource[] resources = new ClassPathResource[ ]
{ new ClassPathResource( "foo.properties" ) };
ppc.setLocations( resources );
ppc.setIgnoreUnresolvablePlaceholders( true );
return ppc;
}
@eugenp
eugenp / PropertyJava.java
Created February 6, 2012 14:18
Properties with Spring - Register Property in Java
@PropertySource("classpath:/com/foo/foo.properties")
@eugenp
eugenp / PropertyXML.xml
Created February 6, 2012 14:16
Properties with Spring - Register Property in XML
<context:property-placeholder location="com/foo/foo.properties"/>
@eugenp
eugenp / FooDAO.java
Created January 31, 2012 11:43
The persistence layer with Spring 3.1 and JPA - an example DAO
@Repository
public class FooDAO extends AbstractJPADAO< Foo > implements IFooDAO{
public FooDAO(){
setClazz(Foo.class );
}
}
@eugenp
eugenp / securityConfig.xml
Created January 29, 2012 22:07
InfoQ - Building REST with Spring - security configigration xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<http create-session="stateless" entry-point-ref="digestEntryPoint">
<intercept-url pattern="/api/admin/**" access="ROLE_ADMIN" />
@eugenp
eugenp / FooController.java
Created January 29, 2012 21:40
InfoQ - Building REST with Spring - the Web/Controller layer
@Controller
public class FooController{
@Autowired
IFooService service;
// API
@RequestMapping( value = "admin/foo",params = { "page", "size" },method = GET )
@ResponseBody
@eugenp
eugenp / web.xml
Created January 29, 2012 14:49
InfoQ - Building REST with Spring - web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>rest</display-name>
<!-- Spring security -->
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
@eugenp
eugenp / pom.xml
Created January 29, 2012 14:45
InfoQ - Building REST with Spring - pom.xml
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org</groupId>
<artifactId>rest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
@eugenp
eugenp / PaginationTest.java
Created January 17, 2012 21:17
Pagination with REST - testing Discoverability - Pagination testing
@Test
public void whenResourcesAreRetrievedPaged_then200IsReceived(){
Response response = givenAuth().get( paths.getFooURL() + "?page=1&size=10" );
assertThat( response.getStatusCode(), is( 200 ) );
}
@Test
public void
whenPageOfResourcesAreRetrievedOutOfBounds_then404IsReceived(){
Response response = givenAuth().get(