Permalink
Browse files

Merge commit 'refs/pull/3/head' of github.com:tlberglund/Ratpack

Conflicts:
	build.gradle
	gradle-plugin/build.gradle
  • Loading branch information...
2 parents a6b5229 + afc0a90 commit c278690019009de515fc2ac7f6b135f31c673bb6 Tim Berglund committed Sep 17, 2012
View
@@ -5,6 +5,7 @@
.gradle
build/
bin/
+out/
*.iml
*.ipr
*.iws
View
@@ -1,106 +1,114 @@
allprojects {
- group = 'com.augusttechgroup'
- version = '0.5.2'
+ group = 'com.augusttechgroup'
+ version = '0.7-SNAPSHOT'
}
apply from: "idea/idea.gradle"
subprojects {
- apply plugin: 'idea'
- apply plugin: 'eclipse'
- apply plugin: 'groovy'
- apply plugin: 'maven'
- apply plugin: 'signing'
-
- repositories {
- mavenCentral()
- }
-
- configurations {
- provided
- }
-
- dependencies {
- testCompile "org.spockframework:spock-core:0.6-groovy-1.8"
- testCompile "cglib:cglib-nodep:2.2"
- }
-
- sourceSets.main.compileClasspath += configurations.provided
- sourceSets.test.compileClasspath += configurations.provided
- idea.module.scopes.PROVIDED.plus += configurations.provided
- eclipse.classpath.plusConfigurations += configurations.provided
-
- task sourceJar(type: Jar) {
- description 'An archive of the source code for Maven Central'
- classifier 'sources'
- from sourceSets.main.groovy
- }
-
- task groovydocJar(type: Jar) {
- description 'An archive of the GroovyDocs for Maven Central'
- classifier 'javadoc'
- from groovydoc
- }
-
- artifacts {
- archives groovydocJar, sourceJar
- }
-
- signing {
- sign configurations.archives
- required { gradle.taskGraph.hasTask(uploadArchives) }
- }
-
- ext {
- poms = []
- pomModifications = []
- modifyPom = { pomModifications << it }
- applyPomMods = { poms ->
- poms.each { pom -> pomModifications.each { mod -> project.configure(pom, mod) } }
+ apply plugin: 'idea'
+ apply plugin: 'eclipse'
+ apply plugin: 'groovy'
+ apply plugin: 'maven'
+ apply plugin: 'signing'
+
+ repositories {
+ mavenCentral()
+ // For Spock and Groovy 2.0
+ mavenRepo url: 'http://oss.sonatype.org/content/repositories/snapshots/'
}
- }
- install {
- repositories.mavenInstaller {
- poms << pom
+ configurations {
+ provided
}
- }
- uploadArchives { task ->
- repositories.mavenDeployer {
- beforeDeployment { deployment ->
- signing.signPom(deployment)
- }
- name = 'mavenCentralReleaseDeployer'
- gradle.taskGraph.whenReady { taskGraph ->
- if (taskGraph.hasTask(task)) {
- repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
- authentication(userName: mavenCentralUsername, password: mavenCentralPassword)
- releases(updatePolicy: 'always')
- snapshots(updatePolicy: 'never')
- }
+ dependencies {
+ testCompile "cglib:cglib-nodep:2.2"
+ }
+
+ sourceSets.main.compileClasspath += configurations.provided
+ sourceSets.test.compileClasspath += configurations.provided
+ idea.module.scopes.PROVIDED.plus += configurations.provided
+ eclipse.classpath.plusConfigurations += configurations.provided
+
+ task sourceJar(type: Jar) {
+ description 'An archive of the source code for Maven Central'
+ classifier 'sources'
+ from sourceSets.main.groovy
+ }
+
+ task groovydocJar(type: Jar) {
+ description 'An archive of the GroovyDocs for Maven Central'
+ classifier 'javadoc'
+ from groovydoc
+ }
+
+ artifacts {
+ archives groovydocJar, sourceJar
+ }
+
+ signing {
+ sign configurations.archives
+ required { gradle.taskGraph.hasTask(uploadArchives) }
+ }
+
+ ext {
+ poms = []
+ pomModifications = []
+ modifyPom = { pomModifications << it }
+ applyPomMods = { poms ->
+ poms.each { pom -> pomModifications.each { mod -> project.configure(pom, mod) } }
}
- }
- poms << pom
}
- }
- poms*.whenConfigured { applyPomMods(it) }
+ install {
+ repositories.mavenInstaller {
+ poms << pom
+ }
+ }
- modifyPom {
- project {
- licenses {
- license {
- name 'The Apache Software License, Version 2.0'
- url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
- distribution 'repo'
+ uploadArchives { task ->
+ repositories.mavenDeployer {
+ beforeDeployment { deployment ->
+ signing.signPom(deployment)
+ }
+ name = 'mavenCentralReleaseDeployer'
+ gradle.taskGraph.whenReady { taskGraph ->
+ if (taskGraph.hasTask(task)) {
+ repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
+ authentication(userName: mavenCentralUsername, password: mavenCentralPassword)
+ releases(updatePolicy: 'always')
+ snapshots(updatePolicy: 'never')
+ }
+ }
+ }
+ poms << pom
}
- }
- developers {
- developer {
- id 'tlberglund'
- name 'Tim Berglund'
- email 'tlberglund@gmail.com'
+ }
+
+ poms*.whenConfigured { applyPomMods(it) }
+
+ modifyPom {
+ project {
+ licenses {
+ license {
+ name 'The Apache Software License, Version 2.0'
+ url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
+ distribution 'repo'
+ }
+ }
+ developers {
+ developer {
+ id 'tlberglund'
+ name 'Tim Berglund'
+ email 'tlberglund@gmail.com'
+ }
+ }
+ scm {
+ connection 'scm:https://tlberglund@github.com/tlberglund/Ratpack'
+ developerConnection 'scm:git@github.com:tlberglund/Ratpack.git'
+ url 'https://github.com/tlberglund/Ratpack'
+ }
}
}
scm {
@@ -109,9 +117,8 @@ subprojects {
url 'https://github.com/tlberglund/ratpack'
}
}
- }
}
task wrapper(type: Wrapper) {
- gradleVersion = '1.0'
+ gradleVersion = '1.1'
}
View
@@ -5,6 +5,7 @@
.gradle
build/
bin/
+out/
*.iml
*.ipr
*.iws
View
@@ -1,23 +1,23 @@
ext {
- servletApiVersion = "2.5"
+ servletApiVersion = "2.5"
}
dependencies {
- groovy 'org.codehaus.groovy:groovy:1.8.3'
- provided "javax.servlet:servlet-api:$servletApiVersion"
- compile 'org.json:json:20090211'
- compile(group: 'org.mortbay.jetty', name: 'jetty', version: '6.1.26') {
- exclude module: 'servlet-api'
- }
- compile 'org.slf4j:slf4j-api:1.6.3'
- runtime 'org.slf4j:slf4j-simple:1.6.3'
- testCompile 'junit:junit:4.10'
- testCompile "javax.servlet:servlet-api:$servletApiVersion"
+ groovy 'org.codehaus.groovy:groovy-all:2.0.1'
+ provided "javax.servlet:servlet-api:$servletApiVersion"
+ compile(group: 'org.mortbay.jetty', name: 'jetty', version: '6.1.26') {
+ exclude module: 'servlet-api'
+ }
+ compile 'org.slf4j:slf4j-api:1.6.3'
+ runtime 'org.slf4j:slf4j-simple:1.6.3'
+ testCompile 'junit:junit:4.10'
+ testCompile "javax.servlet:servlet-api:$servletApiVersion"
+ testCompile "org.spockframework:spock-core:0.7-groovy-2.0-SNAPSHOT"
}
modifyPom {
- project {
- name "Ratpack Core"
- description "The API code for the Ratpack micro-web-framework."
- }
+ project {
+ name "Ratpack Core"
+ description "The API code for the Ratpack micro-web-framework."
+ }
}
@@ -0,0 +1,6 @@
+package com.bleedingwolf.ratpack
+
+// Augments the list of MIME constants to include application/json (not sure why it doesn't already)
+class MimeTypes extends org.mortbay.jetty.MimeTypes {
+ public final static String APPLICATION_JSON = "application/json"
+}
@@ -1,6 +1,10 @@
package com.bleedingwolf.ratpack
-import org.json.JSONObject
+
+import groovy.json.JsonBuilder
+import groovy.json.JsonSlurper
+import org.mortbay.jetty.HttpHeaders
import org.slf4j.LoggerFactory
+import javax.servlet.http.HttpServletRequest
public class RatpackRequestDelegate {
@@ -10,44 +14,62 @@ public class RatpackRequestDelegate {
def urlparams = [:]
def headers = [:]
+ def json = [:]
+
def request = null
def response = null
def requestParamReader = new RatpackRequestParamReader()
final org.slf4j.Logger logger = LoggerFactory.getLogger(getClass())
+ // Begin public API. Don't break this.
void setHeader(name, value) {
response.setHeader(name.toString(), value.toString())
}
-
- void setRequest(req) {
- request = req
- params.putAll(requestParamReader.readRequestParams(req))
-
- req.headerNames.each { header ->
+
+ void contentType(String contentType) {
+ setHeader(HttpHeaders.CONTENT_TYPE, contentType)
+ }
+
+ void setRequest(requestIn) {
+ request = requestIn
+
+ // Important we don't try and read both request params AND body. You only get one go at the InputStream on the request.
+ if (request.getHeader(HttpHeaders.CONTENT_TYPE)?.contains(MimeTypes.APPLICATION_JSON)) {
+ // :TODO: What if this fails? 500 is sub-optimal.
+ json = new JsonSlurper().parseText(getRequestBody(request))
+ } else {
+ params.putAll(requestParamReader.readRequestParams(request))
+ }
+
+ request.headerNames.each { header ->
def values = []
- req.getHeaders(header).each { values << it }
- if(values.size == 1)
- values = values.get(0)
- headers[header.toLowerCase()] = values
+ values.addAll(request.getHeaders(header))
+ headers[header.toLowerCase()] = (values.size() == 1 ? values[0] : values)
}
}
-
- String render(templateName, context=[:]) {
- if(!response.containsHeader('Content-Type')) {
- setHeader('Content-Type', 'text/html')
+
+ String render(templateName, context = [:]) {
+ if (!response.containsHeader(HttpHeaders.CONTENT_TYPE)) {
+ contentType(MimeTypes.TEXT_HTML)
}
renderer.render(templateName, context)
}
- void contentType(String contentType) {
- setHeader("Content-Type",contentType)
- }
-
String renderJson(o) {
- if (!response.containsHeader("Content-Type")) {
- contentType("application/json")
+ if (!response.containsHeader(HttpHeaders.CONTENT_TYPE)) {
+ contentType(MimeTypes.APPLICATION_JSON)
}
- new JSONObject(o).toString()
+ new JsonBuilder(o).toString()
}
+ // Everything below this is the private API.
+ protected final String getRequestBody(request) {
+ def bufferedResult = new StringBuffer()
+ try {
+ request.getReader().eachLine {line -> bufferedResult << line}
+ } catch (e) {
+ logger.error(e.message, e)
+ }
+ bufferedResult.toString()
+ }
}
Oops, something went wrong.

0 comments on commit c278690

Please sign in to comment.