Skip to content

Instantly share code, notes, and snippets.

@xhanin
xhanin / DirWatcher.groovy
Created April 3, 2014 09:09
Simple groovy script to watch a directory, using RESTX API
#!/bin/groovy
@Grab(group='io.restx', module='restx-common', version='0.31.1')
@Grab(group='io.restx', module='restx-barbarywatch', version='0.31.1') // useful for MacOSX only
import restx.common.MoreFiles
import restx.common.watch.FileWatchEvent
import restx.common.watch.WatcherSettings
import com.google.common.eventbus.EventBus
import com.google.common.eventbus.Subscribe
@xhanin
xhanin / maven-snapshot-repositories-fragment.xml
Created April 5, 2014 12:26
Maven Snapshot repository fragment
<repositories>
<repository>
<id>snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
@xhanin
xhanin / maven-copy-dependencies-fragment.xml
Created April 5, 2014 12:26
maven copy dependencies fragment
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
@xhanin
xhanin / endpoint-fragment.java
Created April 6, 2014 19:57
RESTX java 8 endpoint with lambda capturing local variable
@GET("/helloConcat")
@PermitAll
public Iterable<String> concatMessages(String q) {
String c = q + "test";
return asList(NAMES)
.stream()
.map((s) -> (s + c))
.collect(Collectors.toList());
}
@xhanin
xhanin / README.md
Created April 7, 2014 19:42
Java Annotation Processing Notes

A few notes on java annotation processing, collected when working on RESTX annotation processor.

Don't register multiple annotation processor on same annotation.

It fails silently.

Disable annotation processing in module defining an annotation processor.

Use -proc:none javac option. In restx build you can use this fragment: classpath:///restx/build/fragments/maven/annotation-processing-disable.xml

@xhanin
xhanin / AppModule.java
Last active August 29, 2015 14:00
RESTX JDBC support with BoneCP for connexion pool and Flyway for migration
// In AppModule class, or could be in a dedicated module.
@Provides
public DBI dbi(@Named("datasource") DataSource ds) {
return new DBI(ds);
}
@xhanin
xhanin / JongoModule.java
Created May 20, 2014 14:00
Secured Jongo
@Module(priority = -100)
public class JongoModule {
JacksonMapper.Builder getJacksonMapperBuilder() {
return new JacksonMapper.Builder()
.registerModule(new BsonJodaTimeModule())
.withView(Views.Private.class)
;
}
@xhanin
xhanin / RestxSpringContextLoaderListener.java
Created February 12, 2015 12:55
restx spring integration
package restx.spring;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import javax.servlet.ServletContextEvent;
/**
* User: xavierhanin
@xhanin
xhanin / BsonJSR310Module.java
Created June 10, 2015 09:59
RESTX issue 204 workaround
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import de.undercouch.bson4jackson.BsonGenerator;
import de.undercouch.bson4jackson.serializers.BsonSerializer;
@xhanin
xhanin / JacksonDeserializerTest.java
Created October 23, 2015 15:42
jackson deserializer unwrapping a data field
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DeserializationConfig;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonMappingException;