Tapestry is so advance and configurable, even after using it all this time I still found many gems hidden in it. It started with a problem I found in my production environment. I’m doing some interactive Google Map manipulation with tapestry. Since our Glassfish server sits behind Apache server (using reverse proxy), the link generated by ComponentResources.createEventLink will generate a link that contains the glassfish port (8080), while the browser see the other response is generated from regular http port (80) because of reverse proxying. This would trigger Cross Origin Resource Sharing (CORS) problem. Something that modern web server have to limit a misuse of your URL by another web server. There are few way to fix CORS:
Header set Access-Control-Allow-Origin “*”
To implement the fix wasn’t that hard. All you need to do is go to your AppModule and add this one line : configuration.add(SymbolConstants.HOSTPORT, "80"); But this wasn’t enough. Since in our development environment port 8080 is the right port. So as a hack we usually comment this config, and only uncomment it when we are deploying to our production environment. Which is prone to mistake and a disaster waiting to happen. Thus come Tapestry Module separation Separating Tapestry ModuleIt’s commonly known that you can create multiple module class in tapestry, usually for creating a submodule that later you can extract as a library. But tapestry also provide a way to categorize a module as production, development and QA. This will help when you want to have different configuration for each phases. So what we want is to create a module that will override port 80 to 8080 when we are in our development environment. As usual, the problem with Tapestry is finding where the documentation is located. After lots of digging, I finally found the documentation in the link bellow, in the setting execution mode. Basically what you need to do is:
/** 2. Add a new context param in your web.xml <context-param> 3. Add tapestry.execution-mode VM args with your Development module name (without the module part) to your jetty runner And it work like a charm :) |
|
来自: KyunraWang > 《Tapestry》