Skip to content
This repository was archived by the owner on Jan 12, 2018. It is now read-only.

Commit 09cd516

Browse files
committed
Hey ho, let's go
0 parents  commit 09cd516

17 files changed

+757
-0
lines changed

LICENSE.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2011 Mårten Gustafson
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

pom.xml

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.gitub.chids.java</groupId>
6+
<artifactId>rest-versioning</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>war</packaging>
9+
<scm>
10+
<connection>scm:git:git://github.com/chids/java-rest-versioning.git</connection>
11+
<developerConnection>scm:git:git@github.com:chids/java-rest-versioning.git</developerConnection>
12+
<url>http://github.com/chids/java-rest-versioning</url>
13+
</scm>
14+
<properties>
15+
<jersey.version>1.9</jersey.version>
16+
</properties>
17+
<dependencies>
18+
<dependency>
19+
<groupId>javax.servlet</groupId>
20+
<artifactId>javax.servlet-api</artifactId>
21+
<version>3.0.1</version>
22+
<type>jar</type>
23+
<scope>provided</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.google.inject</groupId>
27+
<artifactId>guice</artifactId>
28+
<version>3.0</version>
29+
<type>jar</type>
30+
<scope>compile</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.sun.jersey</groupId>
34+
<artifactId>jersey-core</artifactId>
35+
<version>${jersey.version}</version>
36+
<scope>compile</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.sun.jersey</groupId>
40+
<artifactId>jersey-server</artifactId>
41+
<version>${jersey.version}</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>com.sun.jersey.contribs</groupId>
45+
<artifactId>jersey-guice</artifactId>
46+
<version>${jersey.version}</version>
47+
<type>jar</type>
48+
<scope>compile</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.codehaus.jackson</groupId>
52+
<artifactId>jackson-core-asl</artifactId>
53+
<version>1.9.0</version>
54+
<type>jar</type>
55+
<scope>compile</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.codehaus.woodstox</groupId>
59+
<artifactId>woodstox-core-asl</artifactId>
60+
<version>4.1.2</version>
61+
<type>jar</type>
62+
<scope>compile</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>junit</groupId>
66+
<artifactId>junit</artifactId>
67+
<version>4.9</version>
68+
<type>jar</type>
69+
<scope>test</scope>
70+
</dependency>
71+
</dependencies>
72+
<build>
73+
<plugins>
74+
<plugin>
75+
<groupId>org.apache.maven.plugins</groupId>
76+
<artifactId>maven-compiler-plugin</artifactId>
77+
<version>2.3.2</version>
78+
<configuration>
79+
<source>1.6</source>
80+
<target>1.6</target>
81+
<encoding>UTF-8</encoding>
82+
</configuration>
83+
</plugin>
84+
<plugin>
85+
<groupId>org.mortbay.jetty</groupId>
86+
<artifactId>jetty-maven-plugin</artifactId>
87+
<version>8.0.0.M2</version>
88+
<configuration>
89+
<scanIntervalSeconds>1</scanIntervalSeconds>
90+
<contextPath>/</contextPath>
91+
<useTestClasspath>false</useTestClasspath>
92+
<reload>automatic</reload>
93+
</configuration>
94+
</plugin>
95+
<plugin>
96+
<groupId>org.apache.maven.plugins</groupId>
97+
<artifactId>maven-war-plugin</artifactId>
98+
<version>2.1.1</version>
99+
<configuration>
100+
<failOnMissingWebXml>false</failOnMissingWebXml>
101+
</configuration>
102+
</plugin>
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-eclipse-plugin</artifactId>
106+
<version>2.8</version>
107+
<configuration>
108+
<useProjectReferences>false</useProjectReferences>
109+
<packaging>war</packaging>
110+
<wtpversion>2.0</wtpversion>
111+
</configuration>
112+
</plugin>
113+
</plugins>
114+
</build>
115+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.github.chids.restversioning;
2+
3+
import javax.ws.rs.GET;
4+
import javax.ws.rs.Path;
5+
6+
import com.github.chids.restversioning.model.Group;
7+
import com.github.chids.restversioning.model.Person;
8+
9+
@Path("")
10+
public class Service
11+
{
12+
@GET
13+
@Path("person")
14+
public Person getPerson()
15+
{
16+
return new Person("mårten", "gustafson");
17+
}
18+
19+
@GET
20+
@Path("group")
21+
public Group getGroup()
22+
{
23+
return new Group("authors", getPerson(), getPerson());
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.github.chids.restversioning.configuration;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import javax.servlet.annotation.WebListener;
7+
8+
import com.github.chids.restversioning.Service;
9+
import com.github.chids.restversioning.serialize.group.GroupVersion1Provider;
10+
import com.github.chids.restversioning.serialize.person.PersonVersion1Provider;
11+
import com.google.inject.Guice;
12+
import com.google.inject.Injector;
13+
import com.google.inject.servlet.GuiceServletContextListener;
14+
import com.google.inject.servlet.ServletModule;
15+
import com.sun.jersey.api.container.filter.GZIPContentEncodingFilter;
16+
import com.sun.jersey.api.core.PackagesResourceConfig;
17+
import com.sun.jersey.api.core.ResourceConfig;
18+
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
19+
20+
@WebListener
21+
public final class Configuration extends GuiceServletContextListener
22+
{
23+
@Override
24+
protected Injector getInjector()
25+
{
26+
return Guice.createInjector(
27+
new ServletModule()
28+
{
29+
@Override
30+
protected void configureServlets()
31+
{
32+
serve("/*").with(GuiceContainer.class, createServletParams());
33+
}
34+
});
35+
}
36+
37+
@SuppressWarnings("serial")
38+
static Map<String, String> createServletParams()
39+
{
40+
return new HashMap<String, String>()
41+
{
42+
{
43+
put(PackagesResourceConfig.PROPERTY_PACKAGES, joinPackageNames(Service.class, PersonVersion1Provider.class, GroupVersion1Provider.class));
44+
put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, GZIPContentEncodingFilter.class.getName());
45+
put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, GZIPContentEncodingFilter.class.getName());
46+
put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.toString(false));
47+
}
48+
};
49+
}
50+
51+
static String joinPackageNames(final Class<?>... classes)
52+
{
53+
final StringBuilder sb = new StringBuilder();
54+
for(final Class<?> clazz : classes)
55+
{
56+
sb.append(clazz.getPackage().getName()).append(';');
57+
}
58+
return sb.toString();
59+
}
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.github.chids.restversioning.configuration;
2+
3+
import javax.servlet.annotation.WebFilter;
4+
5+
import com.google.inject.servlet.GuiceFilter;
6+
7+
/**
8+
* This appears to be required in order for servlet 3 annotations to work properly with Guice and Jersey.
9+
* TODO: Figure out why and if really needed
10+
*/
11+
@WebFilter("/*")
12+
public class Filter extends GuiceFilter
13+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.chids.restversioning.model;
2+
3+
import java.util.Arrays;
4+
5+
public final class Group
6+
{
7+
public final String name;
8+
public final Iterable<Person> members;
9+
10+
public Group(final String name, final Person... members)
11+
{
12+
this.name = name;
13+
this.members = Arrays.asList(members);
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.github.chids.restversioning.model;
2+
3+
public final class Person
4+
{
5+
public final String surname;
6+
public final String givenName;
7+
8+
public Person(final String givenName, final String surname)
9+
{
10+
this.givenName = givenName.trim();
11+
this.surname = surname.trim();
12+
}
13+
}

0 commit comments

Comments
 (0)