Setting up gedit for groovy and grails
I use CentOS5 and Ubuntu 8.04.
Save groovy-mime.xml to your home directory.
Save groovy.lang to your home directory.
Save gsp-mime.xml to your home directory.
Save gsp.lang to your home directory.
The above 4 files are not under any restrictive license. They are for anyone who may want them for any use they may wish to put them to.
Log-in as root or you can also log-in as a non-root user with sudo permissions.
If you do login as a non-root user then you should make the appropriate changes to the commands below i.e. by adding sudo before each of the commands. Open a command line terminal and do:
mv ~/groovy-mime.xml /usr/share/mime/packages/
mv ~/groovy.lang /usr/share/gtksourceview-2.0/language-specs/
mv ~/gsp-mime.xml /usr/share/mime/packages/
mv ~/gsp.lang /usr/share/gtksourceview-2.0/language-specs/
update-mime-database /usr/share/mime
Launch gedit and open a groovy file or a gsp file. You should now have syntax highlighting.
Wednesday, July 30, 2008
REST with Grails
Development Environment:
Java: 1.5.0_16; Java HotSpot(TM) Client VM 1.5.0_16-b02
System: Linux version 2.6.18-53.el5 running on i386; UTF-8; en_US (nb)
NetBeans IDE Dev (Build 200807040101) + Groovy and Grails plugin
- created a grails project
- created a domain class with name Game
class Game {
String title
String publisher
}
- used generate all to generate the view and controller
- modifed Bootstrap.groovy to add sample data
class BootStrap {
def init = { servletContext ->
new Game(title:"game1",publisher:"pub1").save()
new Game(title:"game2",publisher:"pub1").save()
new Game(title:"game3",publisher:"pub2").save()
new Game(title:"game4",publisher:"pub2").save()
}
def destroy = {
}
}
- run the app and test it
- modify URLMappings.groovy
class UrlMappings {
static mappings = {\
"/ws/game/$id?"(controller:"game"){
action = [GET:"show", PUT:"update", DELETE:"delete", POST:"save"]
}
}
}
- modify GameController.groovy show method
def show = {
if(params.id && Game.exists(params.id)) {
def g = Game.get(params.id)
render g as XML
}
else {
def all = Game.list()
render all as XML
}
}
- the method can be tested with this client
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
def url = "http://localhost:8080/GameTrax/ws/game/${args[0]}"
def method = new GetMethod(url)
def client = new HttpClient()
def statusCode = client.executeMethod(method)
println "STATUS CODE:$statusCode"
def stream = method.getResponseBodyAsStream()
println "--- START RESPONSE BODY --- "
System.out << stream
println "\n--- END RESPONSE BODY ---"
stream.close()
method.releaseConnection()
- modify GameController.groovy save method
def save = {
def game = new Game(params['game'])
if(game.save())
render game as XML
else{
def myerrors = game.errors.allErrors.collect { g.message(error:it) }
render(contentType:"text/xml") {
errors {
for(err in myerrors) {
error(err)
}
}
}
}
}
- you can test the method with the client below:
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
def url = "http://localhost:8080/GameTrax/ws/game"
def method = new PostMethod(url)
def client = new HttpClient()
def payload = """
<game>
<title>newgame</title>
<publisher>newpublisher</publisher>
</game>
"""
method.addRequestHeader("Content-Type","text/xml")
method.addRequestHeader("Accept","text/xml,application/xml;q=0.9")
method.setRequestEntity(new StringRequestEntity(payload))
def statusCode = client.executeMethod(method)
println "STATUS CODE:$statusCode"
def stream = method.getResponseBodyAsStream()
println "--- START RESPONSE BODY --- "
System.out << stream
println "\n--- END RESPONSE BODY ---"
stream.close()
method.releaseConnection()
Monday, May 19, 2008
VPS hunting
I finally decided to get a VPS for my projects. I narrowed the list down to the following providers:
Slicehost and Linode
I decided to go with slicehost because of their focus on developers so I went to their site, chose a 256mb slice and proceeded to enter my details and credit card information. I gleefully submitted the purchase form thoroughly expecting that in a few minutes, I'd be configuring my very own VPS but lo and behold, I got an error message regarding my card failing verification. I've been using my credit card for online purchases since I got it and this is the first time I was denied. Anyways, I used their contact form to report the incident and in fairness to them, they gave an immediate reply which didn't help.
This situation leaves me with only one choice at the moment and that is to try Linode. It might have been a blessing in disguise as it was then that I realized that Linode offered a much better deal i.e. more memory for the same price. The purchase went smoothly and my server was up in a few minutes. I chose to use the Ubuntu 8.0.4 LTS Hardy Heron Server build. Hopefully I'll have all the services running soon.
Trac on Ubuntu 8.04 LTS
I just got a VPS and decided to go with Ubuntu 8.04 LTS. Here's how I installed trac on the box. The commands below were executed after logging in as root
apt-get install trac apache2 libapache2-svn subversion
mkdir /var/tracs
cd /vat/tracs
trac-admin foobar initenv
chown -R www-data:www-data /var/tracs
nano /etc/apache2/sites-available/foobar
<VirtualHost *>
ServerAdmin webmaster@foobar.com
ServerName projects.foobar.com
DocumentRoot /var/tracs
ScriptAlias /tracs /usr/share/trac/cgi-bin/trac.cgi
<Location /tracs>
SetEnv TRAC_ENV_PARENT_DIR "/var/tracs"
</Location>
<LocationMatch "/tracs/[^/]">
AuthType Basic
AuthName "trac"
AuthUserFile /var/tracs/projects.htpasswd
Require valid-user
</LocationMatch>
ErrorLog /var/log/apache2/error.trac.log
CustomLog /var/log/apache2/access.trac.log combined
AddHandler cgi-script .cgi
</VirtualHost>
a2ensite tracs
htpasswd -c /var/tracs/projects.htpasswd myusername mypassword
mkdir /var/repo
cd /var/repo
svnadmin create foobar
chown -R www-data:www-data /var/repo
apache2ctl restart
Wednesday, May 14, 2008
Fixing "CHM can not be displayed errors" due to a Microsoft security patch
Because of a security patch for Windows, CHM files located on a remote folder accessed via UNC path will fail to open. The security setting can be relaxed by modifying the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\HTMLHelp\1.x\ItssRestrictions setting MaxAllowedZone to dword:00000002
or if you trust me enough, download this file to your windows xp desktop and double click it.
Subscribe to:
Posts (Atom)