Permalink
Browse files

It's working somehow now

  • Loading branch information...
1 parent 72b0c63 commit 096af28bac3feaf05abd5a0b4d18afe7ffd2590a @kiRach committed Apr 3, 2012
View
@@ -1,4 +1,5 @@
#Grails Metadata file
-#Tue Mar 20 23:02:51 MSK 2012
+#Fri Mar 30 13:54:31 MSK 2012
app.grails.version=2.0.1
app.name=glassfish
+plugins.svn=1.0.1
@@ -2,36 +2,38 @@ grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6
+grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.dependency.resolution = {
- // inherit Grails' default dependencies
- inherits("global") {
- // uncomment to disable ehcache
- // excludes 'ehcache'
- }
- log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
- repositories {
- grailsCentral()
- // uncomment the below to enable remote dependency resolution
- // from public Maven repositories
- //mavenCentral()
- //mavenLocal()
- //mavenRepo "http://snapshots.repository.codehaus.org"
- //mavenRepo "http://repository.codehaus.org"
- //mavenRepo "http://download.java.net/maven/2/"
- //mavenRepo "http://repository.jboss.com/maven2/"
- }
- dependencies {
- // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
+ // inherit Grails' default dependencies
+ inherits("global") {
+ // uncomment to disable ehcache
+ //excludes "grails-logging","grails-plugin-log4j"
+ }
+ log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
+ repositories {
+ grailsCentral()
+ // uncomment the below to enable remote dependency resolution
+ // from public Maven repositories
+ //mavenCentral()
+ //mavenLocal()
+ //mavenRepo "http://snapshots.repository.codehaus.org"
+ //mavenRepo "http://repository.codehaus.org"
+ //mavenRepo "http://download.java.net/maven/2/"
+ //mavenRepo "http://repository.jboss.com/maven2/"
+ }
+ dependencies {
+ // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
- // runtime 'mysql:mysql-connector-java:5.1.5'
- }
+ // runtime 'mysql:mysql-connector-java:5.1.5'
+ build 'org.glassfish.main.extras:glassfish-embedded-all:3.1.2'
+ }
- plugins {
- build(":tomcat:$grailsVersion",
- ":release:1.0.0") {
- export = false
- }
- }
+ plugins {
+ build(":tomcat:$grailsVersion",
+ ":release:1.0.0") {
+ export = false
+ }
+ }
}
@@ -0,0 +1,9 @@
+package glassfish
+
+class TestController {
+
+ def index() {
+ log.error "PARAM!!!"
+ [testParam: "testParam5"]
+ }
+}
View
@@ -0,0 +1,18 @@
+<%@ page contentType="text/html;charset=UTF-8" %>
+<html>
+<head>
+ <title></title>
+</head>
+
+<body>
+
+<h1>Hello, world!!!</h1>
+
+
+
+<h1>2</h1>
+
+<h1>3</h1>
+
+</body>
+</html>
@@ -0,0 +1,15 @@
+<%@ page contentType="text/html;charset=UTF-8" %>
+<html>
+<head>
+ <title>Test Controller</title>
+ <script type="text/javascript" src="/js/application.js"></script>
+</head>
+
+<body>
+
+<h3>TEST</h3>
+
+param:${testParam}
+
+</body>
+</html>
@@ -0,0 +1,116 @@
+import grails.web.container.EmbeddableServer
+import org.glassfish.embeddable.GlassFish
+import org.glassfish.embeddable.GlassFishProperties
+import org.glassfish.embeddable.BootstrapProperties
+import org.glassfish.embeddable.GlassFishRuntime
+import org.glassfish.embeddable.archive.ScatteredArchive
+import org.glassfish.embeddable.web.WebContainer
+import org.glassfish.embeddable.Deployer
+import org.glassfish.embeddable.web.WebListener
+import org.glassfish.embeddable.web.HttpListener
+import org.glassfish.embeddable.web.Context
+import org.glassfish.embeddable.web.VirtualServer
+import org.glassfish.embeddable.web.config.VirtualServerConfig
+import grails.util.BuildSettingsHolder
+import org.glassfish.embeddable.web.config.WebContainerConfig
+import java.util.logging.Level
+
+/**
+ * Glassfish embeddable server for grails use.
+ *
+ * @author kiRach
+ */
+class GlassfishEmbeddableServer implements EmbeddableServer {
+
+ GlassFish glassfish
+ WebContainer embedded
+ String webXml
+ String basedir
+ String contextPath
+ ClassLoader classLoader
+
+ Context context
+
+ /**
+ * Constructor.
+ */
+ GlassfishEmbeddableServer(String basedir, String webXml, String contextPath, ClassLoader classLoader) {
+ //just remember this params for using later
+ this.glassfish = GlassFishRuntime.bootstrap().newGlassFish();
+ this.webXml = webXml
+ this.basedir = basedir
+ this.contextPath = contextPath
+ this.classLoader = classLoader
+ }
+
+ private doStart() {
+ System.out.println("Starting a GlassFish server")
+
+ //start server
+ glassfish.start();
+
+ embedded = glassfish.getService(WebContainer.class);
+
+ WebContainerConfig config = new WebContainerConfig();
+ //here we can configure our web container
+ config.setPort(8080)
+ embedded.setConfiguration(config);
+
+ //let's create scattered archive - representation of our web-application
+ //but we won't use it by the way described in documentation - we need it for creating custom context
+ ScatteredArchive archive = new ScatteredArchive(this.contextPath, ScatteredArchive.Type.WAR, new File(basedir))
+ archive.addMetadata(new File(webXml));
+
+ //let's create context - our web application from scattered war from step before and ClassLoader, provided by grails
+ this.context = embedded.createContext(new File(archive.toURI()), this.contextPath, this.classLoader)
+
+ }
+
+ @Override
+ void start() {
+ doStart()
+ }
+
+ @Override
+ void start(int port) {
+ doStart()
+ }
+
+ @Override
+ void start(String host, int port) {
+ doStart()
+ }
+
+ @Override
+ void startSecure() {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ void startSecure(int port) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ void startSecure(String host, int httpPort, int httpsPort) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ @Override
+ void stop() {
+ System.out.println("Stopping server " + glassfish);
+ if (glassfish != null) {
+ glassfish.stop();
+ glassfish.dispose();
+ glassfish = null;
+ }
+ }
+
+ @Override
+ void restart() {
+ System.out.println("Restarting a GlassFish server")
+ //here it mentioned, that restart doesn't work: http://bit.ly/Hhb9nw
+ glassfish.stop()
+ glassfish.start()
+ }
+}
@@ -0,0 +1,31 @@
+import org.glassfish.embeddable.GlassFishRuntime
+import grails.web.container.EmbeddableServerFactory
+import grails.web.container.EmbeddableServer
+import org.glassfish.embeddable.BootstrapProperties
+import org.glassfish.embeddable.GlassFishProperties
+import org.glassfish.embeddable.GlassFish
+
+/**
+ * Factory for glassfish server. Provides ability to embed
+ * glassfish app server within Grails' run-app command.
+ *
+ * @author kiRach
+ */
+class GlassfishServerFactory implements EmbeddableServerFactory {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ EmbeddableServer createInline(String basedir, String webXml, String contextPath, ClassLoader classLoader) {
+ return new GlassfishEmbeddableServer(basedir, webXml, contextPath, classLoader)
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ EmbeddableServer createForWAR(String warPath, String contextPath) {
+ return null
+ }
+}
@@ -0,0 +1,17 @@
+package glassfish
+
+
+
+import grails.test.mixin.*
+import org.junit.*
+
+/**
+ * See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions
+ */
+@TestFor(TestController)
+class TestControllerTests {
+
+ void testSomething() {
+ fail "Implement me"
+ }
+}
@@ -0,0 +1 @@
+console.log("111111");
View
@@ -0,0 +1,13 @@
+<%@ page contentType="text/html;charset=UTF-8" %>
+<html>
+<head>
+ <title>Test Controller</title>
+ <script type="text/javascript" src="js/application.js"></script>
+</head>
+
+<body>
+
+<h3>TEST</h3>
+
+</body>
+</html>

0 comments on commit 096af28

Please sign in to comment.