aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-01-04 17:33:40 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-01-04 17:33:40 +0100
commit8cce8890eca34fead35ad19a0db6d95dd047b3a6 (patch)
tree1843c791ab50c96c650ddd70a7ac8ec815dde267 /src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
parent4a6c9c52d006ecb717bae7d9b502d9b661a08ccd (diff)
downloadesper-testing-8cce8890eca34fead35ad19a0db6d95dd047b3a6.tar.gz
esper-testing-8cce8890eca34fead35ad19a0db6d95dd047b3a6.tar.bz2
esper-testing-8cce8890eca34fead35ad19a0db6d95dd047b3a6.tar.xz
esper-testing-8cce8890eca34fead35ad19a0db6d95dd047b3a6.zip
o Trying out a custom UUID type for prettier formatting.
Diffstat (limited to 'src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java')
-rwxr-xr-xsrc/main/java/io/trygvis/esper/testing/web/JerseyApplication.java34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java b/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
index a02bb5c..8f66548 100755
--- a/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
+++ b/src/main/java/io/trygvis/esper/testing/web/JerseyApplication.java
@@ -34,7 +34,7 @@ public class JerseyApplication extends Application {
}
public Set<Class<?>> getClasses() {
- return new HashSet<>(Arrays.<Class<?>>asList(ResourceParamInjector.class));
+ return new HashSet<>(Arrays.<Class<?>>asList(ResourceParamInjector.class, MyObjectMapper.class));
}
public Set<Object> getSingletons() {
@@ -97,6 +97,38 @@ public class JerseyApplication extends Application {
}
}
};
+ } else if (Uuid.class.equals(type)) {
+
+ return new AbstractHttpContextInjectable() {
+ public Object getValue(HttpContext hc) {
+
+ if (a.query().length() > 0) {
+ return parse(hc.getRequest().getQueryParameters().getFirst(a.query()));
+ } else {
+ MultivaluedMap<String, String> pathParameters = hc.getUriInfo().getPathParameters();
+
+ for (Map.Entry<String, List<String>> entry : pathParameters.entrySet()) {
+ if ("uuid".equals(entry.getKey())) {
+ return parse(entry.getValue().get(0));
+ }
+ }
+ }
+
+ throw new RuntimeException("@MagicParam used with Uuid argument with no {uuid} path variable.");
+ }
+
+ private Uuid parse(String s) {
+ if(s == null) {
+ return null;
+ }
+
+ try {
+ return Uuid.fromString(s);
+ } catch (IllegalArgumentException e) {
+ throw new WebApplicationException(400);
+ }
+ }
+ };
}
return null;