Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Commit

Permalink
0.9.6 Final
Browse files Browse the repository at this point in the history
  • Loading branch information
javaConductor committed Feb 13, 2015
2 parents 4e6be2d + 9508505 commit 730ce01
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 65 deletions.
63 changes: 14 additions & 49 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,53 +91,7 @@ task integration(type: Test) {
groovydoc {

}
/*
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
pom.project {
name 'gServ'
packaging 'jar'
// optionally artifactId can be defined here
description "Framework for REST based services and SPAs in Groovy"
url 'http://github.com/javaconductor/gservExamples'
scm {
connection 'scm:git:[email protected]:javaconductor/gserv.git'
developerConnection 'scm:git:[email protected]:javaconductor/gserv.git'
url '[email protected]:javaconductor/gserv.git'
}
licenses {
license {
name 'The MIT License (MIT)'
url 'http://opensource.org/licenses/MIT'
}
}
developers {
developer {
id 'javaConductor'
name 'Lee Collins'
email '[email protected]'
}
}
}
}
}
}
*/

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
Expand All @@ -148,6 +102,18 @@ task groovydocJar(type: Jar, dependsOn: groovydoc) {
from groovydoc.destinationDir
}

jar {
manifest {
attributes(["Main-Class": "io.github.javaconductor.gserv.Main"])
attributes(["Specification-Title": "gServ"])
attributes(["Specification-Version": "$version"])
attributes(["Specification-Vendor": "Lee Collins"])
attributes(["Implementation-Title": "gServ"])
attributes(["Implementation-Version": "$version"])
attributes(["Implementation-Vendor": "Lee Collins"])
}
}

task standaloneJar(type: Jar, dependsOn: classes) {
from sourceSets.main.output.classesDir
from {
Expand All @@ -169,13 +135,12 @@ task standaloneJar(type: Jar, dependsOn: classes) {
attributes(["Specification-Version": "$version"])
attributes(["Specification-Vendor": "Lee Collins"])
attributes(["Implementation-Title": "gServ"])
attributes(["Implementation-Version": "$version"])
attributes(["Implementation-Version": "$version-${new Date().time}"])
attributes(["Implementation-Vendor": "Lee Collins"])
}
archiveName = "gservApp-${version}.jar"
}


task createDist(type: Copy, dependsOn: standaloneJar) {

from('build/libs') {
Expand Down
Binary file modified dist/gserv.jar
Binary file not shown.
Binary file removed gservInstaller-0.9.5.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions run.exe.stackdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Stack trace:
Frame Function Args
00284BC8 610304E2 (00000138, 0000EA60, 000000A4, 00284C18)
00284CD8 610DA8AD (00000000, 00640000, 00284D18, 0028CE64)
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class InputStreamTypeConverter {
def typeConverters

def InputStreamTypeConverter() {
converters = ["text": readText, "json": readJson, "xml": readXml, "type": typeConverter]
to = converters = ["text": readText, "json": readJson, "xml": readXml, "type": typeConverter]
typeConverters = [:]
}

Expand Down Expand Up @@ -118,6 +118,7 @@ class InputStreamTypeConverter {
/**
* Invokes converter 'name' on input stream 'istream'
*/
def to = { name, istream -> converters[name](istream) }
// def to = { name, istream -> converters[name](istream) }
def to

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import io.github.javaconductor.gserv.delegates.functions.ResourceHandlerFn
import io.github.javaconductor.gserv.events.EventManager
import io.github.javaconductor.gserv.requesthandler.RequestContext
import io.github.javaconductor.gserv.templating.TemplateManager
import io.github.javaconductor.gserv.utils.StaticFileHandler

/**
* This is the delegate for any HTTP Method handler closure
*/
@Mixin(StaticFileHandler)
class HttpMethodDelegate extends DelegateFunctions implements ResourceHandlerFn {
RequestContext requestContext
def serverConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package io.github.javaconductor.gserv.delegates.functions
import groovy.text.Template
import groovy.text.TemplateEngine
import io.github.javaconductor.gserv.exceptions.TemplateException
import io.github.javaconductor.gserv.utils.StaticFileHandler

/**
*
Expand Down Expand Up @@ -232,8 +233,9 @@ trait ResourceHandlerFn {
* @param fname
* @return InputStream
*/
StaticFileHandler fh = new StaticFileHandler()
def getFile(String fname) {
getFile(value("staticRoots"), fname)
fh.getFile(value("staticRoots"), fname)
}

def to = (value("to")) //serverConfig.inputStreamTypeConverter.converters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class Matcher {
// it matches if pathPattern is regExpr and the uriValue matches
// it matches if pathPattern is var and the uriValue is not empty NOW
// else it returns false NOW
//TODO If segment specifies type, Check for Type -
def actionPathText = actionPathPattern.text()
if ('*' == actionPathText)
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class CorsPlugin extends AbstractPlugin {
}

/**
* TODO
*
* @param delegateType
* @param delegateMetaClass
* @return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.github.javaconductor.gserv.requesthandler

import groovy.util.logging.Log4j
import groovy.util.slurpersupport.GPathResult
import io.github.javaconductor.gserv.GServ
import io.github.javaconductor.gserv.actions.ResourceAction
import io.github.javaconductor.gserv.pathmatching.PathMatchingUtils
import io.github.javaconductor.gserv.configuration.GServConfig
import io.github.javaconductor.gserv.delegates.HttpMethodDelegate
import io.github.javaconductor.gserv.events.EventManager
import io.github.javaconductor.gserv.events.Events
import io.github.javaconductor.gserv.exceptions.ConversionException
import io.github.javaconductor.gserv.pathmatching.PathMatchingUtils

import java.util.concurrent.atomic.AtomicLong

Expand All @@ -16,7 +18,8 @@ import java.util.concurrent.atomic.AtomicLong
*/
@Log4j
class ActionRunner {
def _cfg
GServConfig _cfg
private AtomicLong reqId = new AtomicLong(0L)

ActionRunner(GServConfig cfg) {
_cfg = cfg
Expand All @@ -26,14 +29,44 @@ class ActionRunner {
_cfg.delegateMgr.createHttpMethodDelegate(context, action, _cfg)
}

private def convertStreamToType(InputStream instream, Class type) {
if (type.equals(String.class)) {
return _cfg.converter().to.text(instream)
}

if (type.equals(GPathResult.class)) {
return _cfg.converter().to.xml(instream)
}

if (type.equals((new byte[0]).class)) {
return instream.bytes
}

_cfg.converter().to.type(type, instream)
}

private def prepareArguments(URI uri, InputStream istream, ResourceAction action) {
def args = []
def method = action.method()
if (method == "PUT" || method == "POST") {
// add the data before the other args
// data is a byte[]
args.add(istream)
}
////lets see the Type of the first arg
Class class1stArg = action.requestHandler().parameterTypes[0]
log.trace("PUT/POST firstArg type: ${class1stArg.name}")
if (class1stArg && !class1stArg.name.contains("java.lang.Object")) {
def value
try {
value = convertStreamToType(istream, class1stArg)
} catch (Exception e) {
log.trace("Cannot convert input to class: ${class1stArg.name}", e)
throw new ConversionException("Cannot convert input to class: ${class1stArg.name}")
}
args.add(value)
} else {
// add the data before the other args
// data is a byte[]
args.add(istream)
}
}//PUTorPOST

def pathElements = uri.path.split("/").findAll { !(!it) }
//// loop thru the Patterns getting the corresponding uri path elements
Expand All @@ -52,8 +85,6 @@ class ActionRunner {
action.queryPattern().queryKeys().each { k ->
args.add(qmap[k])
}
//println "AsyncHandler.prepareArguments(): $args"
// log.debug "AsyncHandler.prepareArguments(): $args"
args
}

Expand All @@ -64,7 +95,7 @@ class ActionRunner {
cl.resolveStrategy = Closure.DELEGATE_FIRST
cl
}
AtomicLong reqId = new AtomicLong(0L)

def process(RequestContext context, ResourceAction action) {
def currentReqId = context.getAttribute(GServ.contextAttributes.requestId)
if (!currentReqId) {
Expand All @@ -88,6 +119,15 @@ class ActionRunner {
log.trace "ActionRunner: Running req#${currentReqId} ${context.requestURI.path}"
clozure(*argList)
log.trace "ActionRunner: req#${currentReqId} ${context.requestURI.path} - Finished."
} catch (ConversionException e) {
EventManager.instance().publish(Events.ResourceProcessingError, [
requestId: currentReqId,
uri : context.requestURI.path, msg: e.message, e: e])
if (!context.isClosed()) {
cl.delegate.error(403, e.message)
}
log.error "ActionRunner: Error Running req#${currentReqId} ${context.requestURI.path} : ${e.message}", e
context
} catch (Throwable e) {
EventManager.instance().publish(Events.ResourceProcessingError, [
requestId: currentReqId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class FilterRunner {
} finally {
}
return requestContext

}//switch
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class GServHandler implements HttpHandler {
uri : context.requestURI,
headers : context.requestHeaders])
} catch (Throwable e) {
def msg = "Error req #${currentReqId} ${e.message} "
def msg = "Error req #${currentReqId} ${e.message ?: e.class.name} "
log.error(msg, e)
EventManager.instance().publish(Events.RequestProcessingError, [
requestId: currentReqId,
Expand Down

0 comments on commit 730ce01

Please sign in to comment.