blog.alfonsorv.com - Fotografía y desarrollo web

Fotografía y desarrollo web

Configuring Embedded Tomcat in Grails Development Environment

Deja tu comentario

While you are developing a grails app, by default you are using an embedded Tomcat instance.

Sometimes you’ll need to do some configuration, in my case I had to proxy my tomcat instance with an Apache web server through mod_proxy_ajp .

When you have a standalone server running, you can easily change your server.xml file to add an AJP conector which listens for the Apache connections.

To do this within your grails app simply create a _Events.groovy file in your scripts folder of the grails project, and add the configurations needed by your app to the tomcat instance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import grails.util.GrailsUtil
import org.apache.catalina.connector.Connector
import org.apache.coyote.http11.Http11AprProtocol
 
eventConfigureTomcat = {tomcat ->
if (GrailsUtil.environment == 'development')
{
def ajpConnector = new Connector("org.apache.coyote.ajp.AjpProtocol")
ajpConnector.port = 8009
ajpConnector.protocol = "AJP/1.3"
ajpConnector.redirectPort = 8443
ajpConnector.enableLookups = false
ajpConnector.setProperty("redirectPort", "8443")
ajpConnector.setProperty("protocol", "AJP/1.3")
ajpConnector.setProperty("enableLookups", "false")
tomcat.service.addConnector ajpConnector
println "Configured Tomcat ajp connector on port 8009"
}
}

You can also add other tomcat configuration such as Tomcat users and roles: link

 

 

 

Escrito por alfonsorv

14 abril 2013 a las 12:46 pm

Escrito en grails,tomcat

Etiquetado como , , ,

Instruct Groovy HTTPBuilder to handle a JSON response with wrong content type

2 comentarios

While developing a utility script to monitor my mobile data consumed, I found a problem with

the response I was getting from the server. It content-type was set to ‘text/json’ instead of ‘application/json’, ‘application/javascript’ or ‘text/javascript’ wich are the content types used by HTTPBuilder to parse a response as JSON.

To solve this problem, one must add a new content type to the ParserRegistry and parse the response.

There are two ways to do it:

1
2
3
4
5
6
def httpBuilder = new HTTPBuilder(baseUrl)
 
httpBuilder.parser.'text/json' = { resp ->
   def bufferedText = resp.entity.content.getText( ParserRegistry.getCharset( resp ) ).trim()
   return new JsonSlurper().parseText( bufferedText )
}

The second ( reuse default )

1
2
def httpBuilder = new HTTPBuilder(baseUrl)
httpBuilder.parser.'text/json' = httpBuilder.parser.'application/json'

Now everything works again.

See you

Escrito por alfonsorv

20 febrero 2013 a las 8:08 pm

Escrito en codigo,groovy

Etiquetado como , ,

Navidad {52-52}

Deja tu comentario

Navidad
navidad

La última foto del proyecto, CONSEGUIDO!!

Escrito por alfonsorv

28 diciembre 2012 a las 2:43 pm

Escrito en 52 project,foto

Etiquetado como

Libros {50-52}

Un comentario

Libros
libros

Escrito por alfonsorv

28 diciembre 2012 a las 2:41 pm

Escrito en 52 project,foto

Etiquetado como

Negro {48-52}

Un comentario

Negro
Negro

Escrito por alfonsorv

28 diciembre 2012 a las 2:09 pm

Escrito en 52 project,foto

Etiquetado como

Viejo {51-52}

Deja tu comentario

Viejo

 

viejo

Escrito por alfonsorv

28 diciembre 2012 a las 1:34 pm

Escrito en 52 project,foto

Etiquetado como

Luz {49-52}

Deja tu comentario

Luz

 

Luz

Escrito por alfonsorv

28 diciembre 2012 a las 1:33 pm

Escrito en 52 project,foto

Etiquetado como

Textura {47-52}

2 comentarios

Textura
textura

Escrito por alfonsorv

28 diciembre 2012 a las 1:31 pm

Escrito en 52 project,foto

Etiquetado como

No {31-52}

Deja tu comentario

No

NO

Escrito por alfonsorv

28 diciembre 2012 a las 1:29 pm

Escrito en 52 project,foto

Etiquetado como

Límites {29-52}

Un comentario

Límites

 
limites

Escrito por alfonsorv

28 diciembre 2012 a las 1:27 pm

Escrito en 52 project,foto

Etiquetado como