Skip to content

Commit

Permalink
changes for api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
purplefox committed Apr 17, 2013
1 parent 4e3f0b8 commit f2e2023
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 69 deletions.
16 changes: 15 additions & 1 deletion gradle.properties
@@ -1,8 +1,22 @@
# Your domain name
modowner=io.vertx

# Your module name
modname=mod-formupload

# Your module version
version=2.0.0-SNAPSHOT

# The test timeout
testtimeout=300

nettyVersion=4.0.0.CR1

# Set to true if you want module dependencies to be pulled in and nested inside the module itself
pullInDeps=false

# Set to true if you want the build to output a jar as well as a module zip file
produceJar=false
produceJar=true

gradleVersion=1.4
vertxVersion=2.0.0-SNAPSHOT
Expand Down
46 changes: 34 additions & 12 deletions gradle/vertx.gradle
@@ -1,7 +1,11 @@
import org.vertx.java.core.Handler
import org.vertx.java.core.AsyncResult
import org.vertx.java.core.AsyncResultHandler
import org.vertx.java.platform.PlatformLocator
import org.vertx.java.platform.impl.ModuleClassLoader

import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

/*
* Copyright 2012 the original author or authors.
*
Expand All @@ -23,17 +27,13 @@ apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'eclipse'

// We load some extra properties from vertx.properties
loadProperties("vertx.properties")

// We have to explicitly load props from the user home dir - on CI we set
// GRADLE_USER_HOME to a different dir to avoid problems with concurrent builds corrupting
// a shared Maven local and using Gradle wrapper concurrently
loadProperties("${System.getProperty('user.home')}/.gradle/gradle.properties")

apply from: "gradle/maven.gradle"

version = project.ext.version
group = modowner
archivesBaseName = modname

Expand Down Expand Up @@ -137,20 +137,30 @@ test {
task runMod(dependsOn: copyMod, description: 'Run the module using all the build dependencies (not using installed vertx') << {
ModuleClassLoader.reverseLoadOrder = false
def pm = PlatformLocator.factory.createPlatformManager()
pm.deployModule(moduleName, null, 1, new Handler<String>() {
public void handle(String deploymentID) {
System.out.println("CTRL-C to stop server")
def latch = new CountDownLatch(1)
pm.deployModule(moduleName, null, 1, new AsyncResultHandler<String>() {
public void handle(AsyncResult<String> asyncResult) {
if (asyncResult.succeeded()) {
println "CTRL-C to stop server"
} else {
println "Failed to deploy module"
asyncResult.cause().printStackTrace()
latch.countDown()
}
}
});
Thread.sleep(Long.MAX_VALUE);
latch.await(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}

task pullInDeps(dependsOn: copyMod, description: 'Pull in all the module dependencies for the module into the nested mods directory') << {
if (pullInDeps == 'true') {
def pm = PlatformLocator.factory.createPlatformManager()
System.out.println("Pulling in dependencies for module " + moduleName + " Please wait")
pm.pullInDependencies(moduleName)
System.out.println("Dependencies pulled into mods directory of module")
println "Pulling in dependencies for module $moduleName. Please wait"
if (pm.pullInDependencies(moduleName)) {
println "Dependencies pulled into mods directory of module"
} else {
println "Failed to pull in dependencies"
}
}
}

Expand All @@ -164,3 +174,15 @@ def loadProperties(String sourceFileName) {
}
}
}

// Map the 'provided' dependency configuration to the appropriate IDEA visibility scopes.
plugins.withType(IdeaPlugin) {
idea {
module {
scopes.PROVIDED.plus += configurations.provided
scopes.COMPILE.minus += configurations.provided
scopes.TEST.minus += configurations.provided
scopes.RUNTIME.minus += configurations.provided
}
}
}
20 changes: 10 additions & 10 deletions src/examples/java/simpleform/SimpleFormServer.java
Expand Up @@ -16,7 +16,7 @@


import org.vertx.java.core.Handler;
import org.vertx.java.core.SimpleHandler;
import org.vertx.java.core.VoidHandler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.platform.Verticle;
import org.vertx.mods.formupload.Attribute;
Expand All @@ -27,26 +27,26 @@ public class SimpleFormServer extends Verticle {
public void start() {
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(final HttpServerRequest req) {
if (req.uri.equals("/")) {
if (req.uri().equals("/")) {
// Serve the index page
req.response.sendFile("index.html");
} else if (req.uri.startsWith("/form")) {
req.response.setChunked(true);
req.response().sendFile("index.html");
} else if (req.uri().startsWith("/form")) {
req.response().setChunked(true);
MultipartRequest mpReq = new MultipartRequest(vertx, req);
mpReq.attributeHandler(new Handler<Attribute>() {
@Override
public void handle(Attribute attr) {
req.response.write("Got attr " + attr.name + " : " + attr.value + "\n");
req.response().write("Got attr " + attr.name + " : " + attr.value + "\n");
}
});
req.endHandler(new SimpleHandler() {
req.endHandler(new VoidHandler() {
protected void handle() {
req.response.end();
req.response().end();
}
});
} else {
req.response.statusCode = 404;
req.response.end();
req.response().setStatusCode(404);
req.response().end();
}
}
}).listen(8080);
Expand Down
14 changes: 7 additions & 7 deletions src/examples/java/simpleupload/SimpleUploadServer.java
Expand Up @@ -28,10 +28,10 @@ public class SimpleUploadServer extends Verticle {
public void start() {
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(final HttpServerRequest req) {
if (req.uri.equals("/")) {
if (req.uri().equals("/")) {
// Serve the index page
req.response.sendFile("index.html");
} else if (req.uri.startsWith("/form")) {
req.response().sendFile("index.html");
} else if (req.uri().startsWith("/form")) {
MultipartRequest mpReq = new MultipartRequest(vertx, req);
mpReq.uploadHandler(new Handler<Upload>() {
@Override
Expand All @@ -40,17 +40,17 @@ public void handle(final Upload upload) {
@Override
public void handle(AsyncResult<Void> res) {
if (res.succeeded()) {
req.response.end("Upload successful, you should see the file in the server directory");
req.response().end("Upload successful, you should see the file in the server directory");
} else {
req.response.end("Upload failed");
req.response().end("Upload failed");
}
}
});
}
});
} else {
req.response.statusCode = 404;
req.response.end();
req.response().setStatusCode(404);
req.response().end();
}
}
}).listen(8080);
Expand Down
Expand Up @@ -41,7 +41,7 @@ public MultipartRequest(Vertx vertx, HttpServerRequest req) {
this.vertx = vertx;
this.req = req;
// TODO - this is a bit of a hack
HttpRequest nettyReq = ((DefaultHttpServerRequest)req).getNettyRequest();
HttpRequest nettyReq = ((DefaultHttpServerRequest)req).nettyRequest();
try {
if (nettyReq instanceof HttpContent) {
// This is a work around for a bug in netty. Will remove once upgrade netty
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/org/vertx/mods/formupload/Upload.java
Expand Up @@ -7,6 +7,7 @@
import org.vertx.java.core.buffer.Buffer;
import org.vertx.java.core.file.AsyncFile;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.impl.DefaultFutureResult;
import org.vertx.java.core.streams.Pump;
import org.vertx.java.core.streams.ReadStream;

Expand All @@ -15,7 +16,7 @@
/**
* @author <a href="http://tfox.org">Tim Fox</a>
*/
public class Upload implements ReadStream {
public class Upload implements ReadStream<Upload> {

private Handler<Buffer> dataHandler;
private Handler<Void> endHandler;
Expand Down Expand Up @@ -47,16 +48,18 @@ protected Upload(Vertx vertx, HttpServerRequest req, String name, String filenam
this.size = size;
}

public void dataHandler(Handler<Buffer> handler) {
public Upload dataHandler(Handler<Buffer> handler) {
this.dataHandler = handler;
return this;
}

public void pause() {
public Upload pause() {
req.pause();
paused = true;
return this;
}

public void resume() {
public Upload resume() {
if (paused) {
req.resume();
paused = false;
Expand All @@ -68,13 +71,16 @@ public void resume() {
endHandler.handle(null);
}
}
return this;
}

public void exceptionHandler(Handler<Exception> handler) {
public Upload exceptionHandler(Handler<Exception> handler) {
return this;
}

public void endHandler(Handler<Void> handler) {
public Upload endHandler(Handler<Void> handler) {
this.endHandler = handler;
return this;
}

public void bodyHandler(final Handler<Buffer> handler) {
Expand Down Expand Up @@ -103,16 +109,16 @@ public void streamToDisk(String filename, final AsyncResultHandler<Void> resultH
vertx.fileSystem().open(filename, new AsyncResultHandler<AsyncFile>() {
public void handle(final AsyncResult<AsyncFile> ar) {
if (ar.succeeded()) {
Pump p = Pump.createPump(Upload.this, ar.result.getWriteStream());
Pump p = Pump.createPump(Upload.this, ar.result());
p.start();
endHandler(new Handler<Void>() {
public void handle(Void event) {
ar.result.close(resultHandler);
ar.result().close(resultHandler);
}
});
resume();
} else {
resultHandler.handle(new AsyncResult<Void>().setFailure(ar.exception));
resultHandler.handle(new DefaultFutureResult<Void>().setFailure(ar.cause()));
}
}
});
Expand Down
32 changes: 16 additions & 16 deletions src/test/java/org/vertx/mods/test/integration/FormUploadTest.java
Expand Up @@ -20,7 +20,7 @@

import org.junit.Test;
import org.vertx.java.core.Handler;
import org.vertx.java.core.SimpleHandler;
import org.vertx.java.core.VoidHandler;
import org.vertx.java.core.buffer.Buffer;
import org.vertx.java.core.http.HttpClientRequest;
import org.vertx.java.core.http.HttpClientResponse;
Expand All @@ -44,8 +44,8 @@ public void testFormUploadFile() throws Exception {
final String content = "Vert.x rocks!";
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(final HttpServerRequest req) {
if (req.uri.startsWith("/form")) {
req.response.setChunked(true);
if (req.uri().startsWith("/form")) {
req.response().setChunked(true);
final MultipartRequest mpReq = new MultipartRequest(vertx, req);
mpReq.attributeHandler(new Handler<Attribute>() {
@Override
Expand Down Expand Up @@ -79,9 +79,9 @@ public void handle(Buffer buffer) {
});
}
});
req.endHandler(new SimpleHandler() {
req.endHandler(new VoidHandler() {
protected void handle() {
req.response.end();
req.response().end();
}
});
}
Expand All @@ -93,7 +93,7 @@ public void handle(HttpServer event) {
@Override
public void handle(HttpClientResponse resp) {
// assert the response
assertEquals(200, resp.statusCode);
assertEquals(200, resp.statusCode());
resp.bodyHandler(new Handler<Buffer>() {
public void handle(Buffer body) {
assertEquals(0, body.length());
Expand Down Expand Up @@ -125,8 +125,8 @@ public void handle(Buffer body) {
public void testFormUploadAttributes() throws Exception {
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(final HttpServerRequest req) {
if (req.uri.startsWith("/form")) {
req.response.setChunked(true);
if (req.uri().startsWith("/form")) {
req.response().setChunked(true);
final MultipartRequest mpReq = new MultipartRequest(vertx, req);
mpReq.attributeHandler(new Handler<Attribute>() {
@Override
Expand All @@ -153,9 +153,9 @@ public void handle(Buffer buffer) {
});
}
});
req.endHandler(new SimpleHandler() {
req.endHandler(new VoidHandler() {
protected void handle() {
req.response.end();
req.response().end();
}
});
}
Expand All @@ -168,7 +168,7 @@ public void handle(HttpServer event) {
@Override
public void handle(HttpClientResponse resp) {
// assert the response
assertEquals(200, resp.statusCode);
assertEquals(200, resp.statusCode());
resp.bodyHandler(new Handler<Buffer>() {
public void handle(Buffer body) {
assertEquals(0, body.length());
Expand All @@ -190,8 +190,8 @@ public void handle(Buffer body) {
public void testFormUploadAttributes2() throws Exception {
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(final HttpServerRequest req) {
if (req.uri.startsWith("/form")) {
req.response.setChunked(true);
if (req.uri().startsWith("/form")) {
req.response().setChunked(true);
final MultipartRequest mpReq = new MultipartRequest(vertx, req);
mpReq.attributeHandler(new Handler<Attribute>() {
@Override
Expand Down Expand Up @@ -225,9 +225,9 @@ public void handle(Buffer buffer) {
});
}
});
req.endHandler(new SimpleHandler() {
req.endHandler(new VoidHandler() {
protected void handle() {
req.response.end();
req.response().end();
}
});
}
Expand All @@ -240,7 +240,7 @@ public void handle(HttpServer event) {
@Override
public void handle(HttpClientResponse resp) {
// assert the response
assertEquals(200, resp.statusCode);
assertEquals(200, resp.statusCode());
resp.bodyHandler(new Handler<Buffer>() {
public void handle(Buffer body) {
assertEquals(0, body.length());
Expand Down
13 changes: 0 additions & 13 deletions vertx.properties

This file was deleted.

0 comments on commit f2e2023

Please sign in to comment.