This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
I have the need to use one morphia entity in several collections, because I use mongodb as a queue | |
The only solution I have found so far is to create a custom datastore, which maps to a certain db collection. This was my try: In case there is a cleaner solution, feel free to drop me a note | |
Datastore importDatastore = new CustomDatastore(Product.class, mongo, morphia, "import"); | |
Datastore exportDatastore = new CustomDatastore(Product.class, mongo, morphia, "export"); | |
ProductDao importQueueDao = new ProductDao(Product.class, importDatastore); | |
ProductDao exportQueueDao = new ProductDao(Product.class, exportDatastore); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.spinscale.test; | |
import com.yammer.dropwizard.Service; | |
import com.yammer.dropwizard.bundles.BasicBundle; | |
import com.yammer.dropwizard.cli.Cli; | |
import com.yammer.dropwizard.cli.ServerCommand; | |
import com.yammer.dropwizard.config.Bootstrap; | |
import com.yammer.dropwizard.config.Configuration; | |
import org.junit.rules.TestRule; | |
import org.junit.runner.Description; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get "/", { Request request, Response response -> | |
jade "index.jade", [title: 'My page'] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static spark.Spark.*; | |
import spark.*; | |
public class HelloWorld { | |
public static void main(String[] args) { | |
before(new Filter() { // matches all routes | |
@Override | |
public void handle(Request request, Response response) { | |
boolean authenticated; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir groovy-spark | |
cd groovy-spark | |
mkdir -p src/main/groovy | |
mkdir -p src/main/resources | |
mkdir -p src/test/groovy | |
mkdir -p src/test/resources |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'groovy' | |
apply plugin: 'idea' | |
repositories { | |
mavenCentral() | |
maven { url "http://www.sparkjava.com/nexus/content/repositories/spark/" } | |
maven { url "https://raw.github.com/neuland/jade4j/master/releases" } | |
} | |
// avoid groovy/jade asm clashes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import spark.* | |
class WebServer extends SparkGroovy { | |
static void main(String[] args) { | |
new WebServer().init(); | |
} | |
void init() { | |
before { Request req, Response res -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get(String path, Closure closure) { | |
Spark.get(new Route(path) { | |
def handle(Request request, Response response) { | |
closure.delegate = this | |
return closure.call(request, response) | |
} | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get "/foo.json", { Request request, Response response -> | |
json([foo: 'bar']) | |
} | |
get "/jade", { Request request, Response response -> | |
jade "test.jade", [foo: 'bar', pageName: 'My page'] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static JadeConfiguration config = new JadeConfiguration() | |
static { | |
config.setTemplateLoader(new FileTemplateLoader("src/main/resources/views/", "UTF-8")) | |
} | |
def json(Object obj) { | |
return JSON.default.toJSON(obj) | |
} | |
def jade(String template, Object obj) { |
OlderNewer