Grails Mapping http://localhost:8080 - grails

Is it possible to map http://localhost:8080/controller/action to something like http://myApp/controller/action with Grails mappings?

You need to either specify a local domain in /etc/hosts(or equivalent for your OS) or buy a domain from a provider. It has nothing to do with Grails. With URL mappings you only control what's after your application URL.

Related

Runtime port generation in grails framework

I am using grails framework to develop a web application. I need to generate the runtime server URL as follows: http:hostname:port/application/. In grails configuration we have an option to provide the serverURL using grails.serverURL.
My question is: Can we get the port number of server which the application is running at runtime? Is this possible?
Try this..
System.getProperty("server.port", "8080")
Enjoy...
If you have different profiles(config blocks) per environment, you can likely set the grails.server.port.http property in there.

How to use groovy domain classes in my Java Project?

I have some domain classes in grails application. My middle ware is called as servic
The domain classes would be shared between grails-app and services.
If we use annotation – would services be able to detect them?
How do you share the classes with services ?. Can you do a jar on them?.
Can any one please help me out
Thanks Siva.
You may access your grails domain classes with hql query. See How to execute HQL query in Java for reference.

Grails redirect with reverse proxy

We've developed a Grails application that uses redirects.
Beacuse of external reasons, we are just recently using reverse-proxy, to split some traffic to domains:
From:
demo1.company.local (the server itself)
To:
tomcat.company.local (for all java applications, including our grails app)
lotus.company.local (for all Domino applications)
Since tomcat is only configured in the hosts file on the demo1 server, the redirects do not work when I access the application from anywhere else then the demo1 server itself.
I've tried to solve this using "absolute" and/or "base" parameter in Grails' redirect(), but if I understand correctly, this is Grails 2+ only and we're using Grails 1.3.4.
Are there other ways to redirect to a specified host?
Am I misusing things?
Thanks,
Bram
If you define grails.serverURL in Config.groovy, redirects with absolute:true will use that value for the URL.

How to create an alias path on local IIS?

Unfortunately searching the web didn't make me any smarter. I have a web application running under my local IIS 7.5: http://localhost/myWebpage/
Now I'd like to create an alias path pointing to the same application, something like http://localhost/myWebpageAlias/ (the application will change it's layout according to the different address).
How can I achieve this?
Thx for any tipps
sl3dg3
Try creating a new virtual directory under "Default Web Site" (or whatever site is serving 'localhost'), then point it to the same directory:
Though it is the too late answer. But to alias path, you can use the IIS URL Rewrite module to create a rule which maps one URL to another. Visit here for details description.

grails 2.0 - correct use of serverURL for production?

Grails 2.0 changed with the way it uses grails.serverURL for development and test environments (as described in the manual). However, I've had several problems with serverURL in regard to production deployment on Tomcat. There seem to be several options for serverURL (production mode):
(Added) this setting is just "smoke and mirrors", because Tomcat and Jetty have methods to control how the URL is handled for the App, down to the "App" level.
Use it to specify the server (as is pointed out as a "TODO" in Config.groovy)
Don't use it as indicated here by one of the Grails contributors, i.e. "It should always be safe to remove the serverURL property and let Grails generate urls relative to the current running app." It's not clear if this extends to production or not (when not generating emails).
Use another method instead, namely grails.app.context, which is not documented in Grails 2.0 manual, but is described in certain references, here and here.
Can you please clarify the correct use of serverURL and app.context, both for Jetty and Tomcat (production mode)?
Thanks
Good question! I was just looking for the correct way to get the actual serverURL without explicitly needing to configure it in Config.groovy (in a Grails 2.1 application).
Since Grails 2.0, there is a super-useful class called LinkGenerator that you can use virtually anywhere, for example in a Service:
import org.codehaus.groovy.grails.web.mapping.LinkGenerator
Class MyService {
LinkGenerator grailsLinkGenerator
String serverUrl() {
// Generate: http://localhost:8080/link-generator
grailsLinkGenerator.serverBaseURL
}
}
Thanks to Mr. Haki for blogging about this!
So the basic idea of the grails.serverURL configuration parameter is to allow the createLink method to know what URL you want when creating absolute links. If no grails.serverURL configuration parameter is specified, it will default to http://localhost:8080 (unless server.port is specified, then 8080 will be whatever) ...
The application context tells Jetty/Tomcat to run the application in a different root. For example, specifying
grails.app.context="/myApp"
will set your application root to "/myApp". In production mode, the application context is handled by the web container and this directive is ignored. The choice to configure your production jetty or tomcat instances to run your application in a different context is entirely dependent on what your technical requirements are.
So the real thing to consider is, in your application are you creating a lot of absolute links in your GSPs where you need to define a "production" serverURL? If not, then you don't need to specify it; if you are, then you'll need to specify it.
As a personal preference, the first thing that I always do after creating a new grails project is go into the config and change the grails.app.context to "/" ... It makes mirroring a production environment much easier for me.
Hope this clears things up!

Resources