Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 14, 2016
0 parents commit abaf6d8
Show file tree
Hide file tree
Showing 267 changed files with 80,970 additions and 0 deletions.
Binary file added 9781590599983.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,27 @@
Freeware License, some rights reserved

Copyright (c) 2009 Dennis McCarthy and Chris Crane

Permission is hereby granted, free of charge, to anyone obtaining a copy
of this software and associated documentation files (the "Software"),
to work with the Software within the limits of freeware distribution and fair use.
This includes the rights to use, copy, and modify the Software for personal use.
Users are also allowed and encouraged to submit corrections and modifications
to the Software for the benefit of other users.

It is not allowed to reuse, modify, or redistribute the Software for
commercial use in any way, or for a user�s educational materials such as books
or blog articles without prior permission from the copyright holder.

The above copyright notice and this permission notice need to be included
in all copies or substantial portions of the software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


15 changes: 15 additions & 0 deletions README.md
@@ -0,0 +1,15 @@
#Apress Source Code

This repository accompanies [*Comet and Reverse Ajax*](http://www.apress.com/9781590599983) by Dennis McCarthy and Chris Crane (Apress, 2009).

![Cover image](9781590599983.jpg)

Download the files as a zip using the green button, or clone the repository to your machine using Git.

##Releases

Release v1.0 corresponds to the code in the published book, without corrections or updates.

##Contributions

See the file Contributing.md for more information on how you can contribute to this repository.
23 changes: 23 additions & 0 deletions README.txt
@@ -0,0 +1,23 @@
EXAMPLE CODE FOR "Comet & Reverse Ajax" by Crane & McCarthy, FirstPress 2008

GENERAL SETUP
The examples presented here use Groovy on Grails, a Java-based web technology stack. More details at http://grails.org. To get up and running:
0. Install Java on tyour machine if you need to. You'll need the JDK, not just the runtime (JRE).
1. download and install Grails for your platform. The most recent version of Grails at time of writing is 1.0.3, which uses Jetty 6.1.7 internally. The Jetty cometd examples require Jetty 6.1.11 or higher, so...
2. Download a recent version of Jetty (e.g. 6.1.11) and replace the Jetty jar files in your grails installation. The files that I modified were:
- jetty-6.1.x.jar
- jetty-naming-6.1.x.jar
- jetty-plus-6.1.x.jar
- jetty-util-6.1.x.jar
3. Unzip the source folder into a directory. There are two Grails projects in here:

CHAPTERS 1-3
are covered by the Grails application 'magpoetry1'. Go into that directory in a command prompt, and issue the command 'grails run-app' to get started, then navigate to http://localhost:8080/magpoetry1/ to view the application. Javascripts, GSPs and Groovy controller code can all be edited live while the server is running.

CHAPTERS 6-7
are covered by the Grails application 'cometd', which can be run in a similar fashion.


Happy coding!

Dave Crane
85 changes: 85 additions & 0 deletions cometd/.classpath
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/java"/>
<classpathentry kind="src" path="src/groovy"/>
<classpathentry kind="src" path="grails-app/conf"/>
<classpathentry kind="src" path="grails-app/controllers"/>
<classpathentry kind="src" path="grails-app/domain"/>
<classpathentry kind="src" path="grails-app/services"/>
<classpathentry kind="src" path="grails-app/taglib"/>
<classpathentry kind="src" path="test/integration"/>
<classpathentry kind="src" path="test/unit"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="web-app/WEB-INF/classes"/>
<classpathentry kind="var" path="GRAILS_HOME/ant/lib/ant.jar"/>
<classpathentry kind="var" path="GRAILS_HOME/lib/ehcache-1.3.0.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/commons-fileupload-1.1.1.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/ant-nodeps.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/ant-trax.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/dom4j-1.6.1.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/spring-binding-2.0-m1.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/commons-logging-1.1.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/junit-3.8.2.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/spring-2.5.4.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/ejb3-persistence.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/xercesImpl.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jstl-2.3.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/ant.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jaxen-1.1-beta-11.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/ant-launcher.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jta.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/spring-webflow-2.0-m1.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/standard-2.4.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jsp-api-2.0.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/commons-pool-1.2.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/commons-dbcp-1.2.1.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/antlr-2.7.6.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/spring-test.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jetty-util-6.1.4.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/hibernate3.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jstl-2.4.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jasper-compiler-jdt-5.5.15.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jetty-naming-6.1.4.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/standard-2.3.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/commons-lang-2.1.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/bsf-2.3.0.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/commons-el-1.0.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/cglib-nodep-2.1_3.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/hibernate-annotations.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/commons-io-1.4.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/svnkit.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/commons-beanutils-1.7.0.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/spring-webmvc.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/ognl-2.6.9.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/serializer.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/xstream-1.2.1.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/hibernate-commons-annotations.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/xalan.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/start.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/log4j-1.2.15.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/sitemesh-2.3.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jdbc2_0-stdext.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jetty-6.1.4.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/oro-2.0.8.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jline-0.9.91.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jasper-runtime-5.5.15.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/commons-collections-3.2.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jetty-plus-6.1.4.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/xpp3_min-1.1.3.4.O.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/commons-cli-1.0.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/ant-junit.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/servlet-api-2.5-6.1.4.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/oscache-2.4.1.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/jasper-compiler-5.5.15.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/commons-validator-1.3.0.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/groovy-all-1.5.6.jar" />
<classpathentry kind="var" path="GRAILS_HOME/lib/hsqldb-1.8.0.5.jar" />
<classpathentry kind="var" path="GRAILS_HOME/dist/grails-spring-1.0.3.jar" />
<classpathentry kind="var" path="GRAILS_HOME/dist/grails-webflow-1.0.3.jar" />
<classpathentry kind="var" path="GRAILS_HOME/dist/grails-cli-1.0.3.jar" />
<classpathentry kind="var" path="GRAILS_HOME/dist/grails-crud-1.0.3.jar" />
<classpathentry kind="var" path="GRAILS_HOME/dist/grails-web-1.0.3.jar" />
<classpathentry kind="var" path="GRAILS_HOME/dist/grails-core-1.0.3.jar" />
<classpathentry kind="var" path="GRAILS_HOME/dist/grails-gorm-1.0.3.jar" />
<classpathentry kind="var" path="GRAILS_HOME/dist/grails-test-1.0.3.jar" />
</classpath>
23 changes: 23 additions & 0 deletions cometd/.project
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cometd</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.codehaus.groovy.eclipse.groovyBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.codehaus.groovy.eclipse.groovyNature</nature>
</natures>
</projectDescription>
47 changes: 47 additions & 0 deletions cometd/CometdGrailsPlugin.groovy
@@ -0,0 +1,47 @@

class CometdGrailsPlugin {
def version = 0.1
def dependsOn = [:]

def doWithSpring = {
// TODO Implement runtime spring config (optional)
}

def doWithApplicationContext = { applicationContext ->
// TODO Implement post initialization spring config (optional)
}

def doWithWebDescriptor = { xml ->
// add the comet servlet to the web.xml file, mapped to the /comet/ url
def servletElement = xml.'servlet'
servletElement[0] + {
'servlet' {
'servlet-name'("cometd")
'servlet-class'("org.mortbay.cometd.continuation.ContinuationCometdServlet")
'load-on-startup'("1")
}
}

def mappingElement = xml.'servlet-mapping'
mappingElement[0] + {
'servlet-mapping' {
'servlet-name'("cometd")
'url-pattern'("/cometd/*")
}
}
}

def doWithDynamicMethods = { ctx ->
// TODO Implement registering dynamic methods to classes (optional)
}

def onChange = { event ->
// TODO Implement code that is executed when this class plugin class is changed
// the event contains: event.application and event.applicationContext objects
}

def onApplicationChange = { event ->
// TODO Implement code that is executed when any class in a GrailsApplication changes
// the event contain: event.source, event.application and event.applicationContext objects
}
}
4 changes: 4 additions & 0 deletions cometd/application.properties
@@ -0,0 +1,4 @@
#Do not edit app.grails.* properties, they may change automatically. DO NOT put application configuration in here, it is not the right place!
#Mon Aug 18 20:07:19 BST 2008
app.grails.version=1.0.3
app.name=cometd
41 changes: 41 additions & 0 deletions cometd/build.xml
@@ -0,0 +1,41 @@
<project name="cometd" default="test">

<condition property="grails" value="grails.bat">
<os family="windows"/>
</condition>
<property name="grails" value="grails" />

<!-- =================================
target: clean
================================= -->
<target name="clean" description="--> Cleans a Grails application">
<exec executable="${grails}" failonerror="true">
<arg value="clean"/>
</exec>
</target>

<!-- =================================
target: war
================================= -->
<target name="war" description="--> Creates a WAR of a Grails application">
<exec executable="${grails}" failonerror="true">
<arg value="war"/>
</exec>
</target>

<!-- =================================
target: test
================================= -->
<target name="test" description="--> Run a Grails applications unit tests">
<exec executable="${grails}" failonerror="true">
<arg value="test-app"/>
</exec>
</target>

<!-- =================================
target: deploy
================================= -->
<target name="deploy" depends="war" description="--> The deploy target (initially empty)">
<!-- TODO -->
</target>
</project>
20 changes: 20 additions & 0 deletions cometd/cometd.launch
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="grails.util.GrailsMain"/>
<booleanAttribute key="org.eclipse.jdt.debug.ui.INCLUDE_EXTERNAL_JARS" value="true"/>
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot; javaProject=&quot;cometd&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#10;&lt;memento exportedEntriesOnly=&quot;false&quot; project=&quot;cometd&quot;/&gt;&#10;&lt;/runtimeClasspathEntry&gt;&#10;"/>
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/cometd&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#10;"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="cometd"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dbase.dir=${project_loc} -Dserver.port=8080 -Dgrails.env=development"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/cometd"/>
</listAttribute>
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
</launchConfiguration>
73 changes: 73 additions & 0 deletions cometd/cometd.tmproj
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>documents</key>
<array>
<dict>
<key>filename</key>
<string>cometd.launch</string>
</dict>
<dict>
<key>filename</key>
<string>build.xml</string>
</dict>
<dict>
<key>name</key>
<string>grails-app</string>
<key>regexFolderFilter</key>
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
<key>sourceDirectory</key>
<string>grails-app</string>
</dict>
<dict>
<key>name</key>
<string>test</string>
<key>regexFolderFilter</key>
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
<key>sourceDirectory</key>
<string>test</string>
</dict>
<dict>
<key>name</key>
<string>lib</string>
<key>regexFolderFilter</key>
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
<key>sourceDirectory</key>
<string>lib</string>
</dict>
<dict>
<key>name</key>
<string>scripts</string>
<key>regexFolderFilter</key>
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
<key>sourceDirectory</key>
<string>scripts</string>
</dict>
<dict>
<key>name</key>
<string>src</string>
<key>regexFolderFilter</key>
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
<key>sourceDirectory</key>
<string>src</string>
</dict>
<dict>
<key>name</key>
<string>web-app</string>
<key>regexFolderFilter</key>
<string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
<key>sourceDirectory</key>
<string>web-app</string>
</dict>
</array>
<key>fileHierarchyDrawerWidth</key>
<integer>200</integer>
<key>metaData</key>
<dict/>
<key>showFileHierarchyDrawer</key>
<true/>
<key>windowFrame</key>
<string>{{237, 127}, {742, 553}}</string>
</dict>
</plist>
15 changes: 15 additions & 0 deletions cometd/grails-app/conf/BootStrap.groovy
@@ -0,0 +1,15 @@
class BootStrap {

def init = { servletContext ->
new Word(text:"Magnetic",color:'#ff0',x:150,y:180).save()
new Word(text:"Poetry",color:'#fff',x:220,y:185).save()
new Word(text:"version",color:'#f8f',x:180,y:220).save()
new Word(text:"one",color:'#faa',x:245,y:205).save()

def blackList=["class","metaClass"].toArray(new String[1])
def convertor=new org.mortbay.util.ajax.JSONObjectConvertor(true,blackList)
org.mortbay.util.ajax.JSON.registerConvertor(Word.class,convertor)
}
def destroy = {
}
}

0 comments on commit abaf6d8

Please sign in to comment.