rollback scalatra template

This commit is contained in:
wing328 2015-06-09 12:57:31 +08:00
parent b636d2a2c9
commit f2ee63da3b
9 changed files with 148 additions and 146 deletions

View File

@ -5,16 +5,16 @@ import javax.servlet.ServletContext
import org.scalatra.LifeCycle
class ScalatraBootstrap extends LifeCycle {
implicit val swagger = new SwaggerApp
implicit val swagger = new SwaggerApp
override def init(context: ServletContext) {
implicit val system = ActorSystem("appActorSystem")
try {
{{#apiInfo}}{{#apis}}context mount (new {{classname}}, "/{{baseName}}/*")
{{/apis}}{{/apiInfo}}
context mount (new ResourcesApp, "/api-docs/*")
} catch {
case e: Throwable => e.printStackTrace()
}
}
override def init(context: ServletContext) {
implicit val system = ActorSystem("appActorSystem")
try {
{{#apiInfo}}{{#apis}}context mount (new {{classname}}, "/{{baseName}}/*")
{{/apis}}{{/apiInfo}}
context mount (new ResourcesApp, "/api-docs/*")
} catch {
case e: Throwable => e.printStackTrace()
}
}
}

View File

@ -1,7 +1,17 @@
import org.eclipse.jetty.server._
import org.eclipse.jetty.webapp.WebAppContext
import org.scalatra.servlet.ScalatraListener
object JettyMain {
object conf {
val port = sys.env.get("PORT") map (_.toInt) getOrElse (8080)
val stopTimeout = sys.env.get("STOP_TIMEOUT") map (_.toInt) getOrElse (5000)
val connectorIdleTimeout = sys.env.get("CONNECTOR_IDLE_TIMEOUT") map (_.toInt) getOrElse (90000)
val webapp = sys.env.get("PUBLIC") getOrElse "webapp"
val contextPath = sys.env.get("CONTEXT_PATH") getOrElse "/"
}
def main(args: Array[String]) = {
val server: Server = new Server
println("starting jetty")
@ -30,12 +40,4 @@ object JettyMain {
server.start()
}
object conf {
val port = sys.env.get("PORT") map (_.toInt) getOrElse (8080)
val stopTimeout = sys.env.get("STOP_TIMEOUT") map (_.toInt) getOrElse (5000)
val connectorIdleTimeout = sys.env.get("CONNECTOR_IDLE_TIMEOUT") map (_.toInt) getOrElse (90000)
val webapp = sys.env.get("PUBLIC") getOrElse "webapp"
val contextPath = sys.env.get("CONTEXT_PATH") getOrElse "/"
}
}

View File

@ -1,5 +1,7 @@
package json
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.core.JsonGenerator.Feature
import com.fasterxml.jackson.databind._
object JsonUtil {

View File

@ -8,32 +8,32 @@ import org.scalatra.ScalatraServlet
import org.json4s.{DefaultFormats, Formats}
class ResourcesApp(implicit protected val system: ActorSystem, val swagger: SwaggerApp)
extends ScalatraServlet with JacksonSwaggerBase {
before() {
response.headers += ("Access-Control-Allow-Origin" -> "*")
}
extends ScalatraServlet with JacksonSwaggerBase {
before() {
response.headers += ("Access-Control-Allow-Origin" -> "*")
}
protected def buildFullUrl(path: String) = if (path.startsWith("http")) path else {
val port = request.getServerPort
val h = request.getServerName
val prot = if (port == 443) "https" else "http"
val (proto, host) = if (port != 80 && port != 443) ("http", h+":"+port.toString) else (prot, h)
"%s://%s%s%s".format(
proto,
host,
request.getContextPath,
path)
}
protected def buildFullUrl(path: String) = if (path.startsWith("http")) path else {
val port = request.getServerPort
val h = request.getServerName
val prot = if (port == 443) "https" else "http"
val (proto, host) = if (port != 80 && port != 443) ("http", h+":"+port.toString) else (prot, h)
"%s://%s%s%s".format(
proto,
host,
request.getContextPath,
path)
}
}
class SwaggerApp extends Swagger(apiInfo = ApiSwagger.apiInfo, apiVersion = "1.0", swaggerVersion = "1.2")
object ApiSwagger {
val apiInfo = ApiInfo(
"""{{{appName}}}""",
"""{{{appDescription}}}""",
"""{{{infoUrl}}}""",
"""{{{infoEmail}}}""",
"""{{{licenseInfo}}}""",
"""{{{licenseUrl}}}""")
val apiInfo = ApiInfo(
"""{{{appName}}}""",
"""{{{appDescription}}}""",
"""{{{infoUrl}}}""",
"""{{{infoEmail}}}""",
"""{{{licenseInfo}}}""",
"""{{{licenseUrl}}}""")
}

View File

@ -15,20 +15,20 @@ import org.scalatra.servlet.{FileUploadSupport, MultipartConfig, SizeConstraintE
import scala.collection.JavaConverters._
class {{classname}} (implicit val swagger: Swagger) extends ScalatraServlet
with FileUploadSupport
with JacksonJsonSupport
with SwaggerSupport {
protected implicit val jsonFormats: Formats = DefaultFormats
with FileUploadSupport
with JacksonJsonSupport
with SwaggerSupport {
protected implicit val jsonFormats: Formats = DefaultFormats
protected val applicationDescription: String = "{{classname}}"
override protected val applicationName: Option[String] = Some("{{baseName}}")
protected val applicationDescription: String = "{{classname}}"
override protected val applicationName: Option[String] = Some("{{baseName}}")
before() {
contentType = formats("json")
response.headers += ("Access-Control-Allow-Origin" -> "*")
}
before() {
contentType = formats("json")
response.headers += ("Access-Control-Allow-Origin" -> "*")
}
{{#operations}}
{{#operation}}
{{#operation}}
{{newline}}
val {{nickname}}Operation = (apiOperation[{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}]("{{nickname}}")
@ -89,6 +89,6 @@ response.headers += ("Access-Control-Allow-Origin" -> "*")
{{/allParams}}
}
{{/operation}}
{{/operation}}
{{/operations}}
}

View File

@ -1,6 +1,4 @@
// put this at the top of the file
import AssemblyKeys._ // put this at the top of the file
import NativePackagerKeys._
@ -12,7 +10,7 @@ scalariformSettings
organization := "io.swagger"
seq(webSettings: _*)
seq(webSettings :_*)
mainClass in assembly := Some("JettyMain")
@ -44,7 +42,7 @@ libraryDependencies ++= Seq(
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;compile;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar"))
)
resolvers += "Local Maven Repository" at "file://" + Path.userHome.absolutePath + "/.m2/repository"
resolvers += "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
resolvers += "Sonatype OSS Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
@ -53,8 +51,8 @@ resolvers += "Sonatype OSS Releases" at "http://oss.sonatype.org/content/reposit
ivyXML := <dependencies>
<exclude module="slf4j-log4j12"/>
<exclude module="grizzled-slf4j_2.9.1"/>
<exclude module="jsr311-api"/>
</dependencies>
<exclude module="jsr311-api" />
</dependencies>
mergeStrategy in assembly <<= (mergeStrategy in assembly) {
(old) => {

View File

@ -5,11 +5,11 @@ package {{package}}
{{#models}}
{{#model}}
case class {{classname}} (
{{#model}}
case class {{classname}} (
{{#vars}}{{name}}: {{#isNotRequired}}Option[{{/isNotRequired}}{{datatype}}{{#isNotRequired}}] {{#description}} // {{description}}{{/description}}
{{/isNotRequired}}{{#hasMore}},
{{/hasMore}}{{/vars}}
)
{{/model}}
)
{{/model}}
{{/models}}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<listener>