So, I've been developing my first actual site and so far I've been developing it on a local webserver, Apache Tomcat 7.0 along with a MySQL server, and I'm wondering what changes or problems I should be expecting when I go from that testing environment to a live VPN web server which I've been told I'll have to switch over to.
If it makes any difference I'm using struts2 for my action mapping which I've noticed append all my URL's with .action ex: localhost:8080/pm/random.action
However the expected url is, busniessname.com/pm/random
So the tl;dr, what should I be expecting when I switch from a local testing environment to the live website and what should I do to fix the URL's?
You should do nothing, the urls without .action extension should work by default. If you would like to use an empty extension only then you should set the property to the configuration.
<constant name="struts.action.extension" value=",,"/>
Related
I have my application on production on some domain name ABC.com. In my code i am redirecting user to other page based upon on some action
response.sendRedirect(request.getServletContext().getContextPath() + "/time");
But by the above it get redirected to localhost:8080//time
but instead of this i want it to get redirected to ABC.com/time
How can i do this? A simple solution coming to my mind is that i should set some environment variable for production and instead of using
request.getServletContext().getContextPath()
, i will use environment variable value i.e. ABC.com
If you really need the domain under which your server can been reached, then the environment variable way is the only way that works all times (for example even if there is a proxy in front of your server...)
It seems to me that this should work with the domain that you want, provided that the application is operating from said domain. Right now you are probably using a development environment on your localhost, which means the servlet is operating on localhost:8080 and will also pass that back as it's path. When you deploy your application it should work.
If you need to redirect to the production version even though you are running in a development environment, you should hardcore the URL in a configuration variable of sorts. I prefer using .conf files and reading those at runtime since it allows you to alter their contents on the fly easily.
One minor thing that might cause issues is the double slashes. A path or URL will end in a slash so you don't have to append the second one. Simply doing + "time" should be enough.
I need help to run/debug my GWT application on an external server and not using the default jetty server.
I read several related topics to that question, e.g.
Where to write GWT -noserver option to avoid jetty?
How to set up eclipse with GWT and (regular servlet) Jetty backend
Is it possible to debug GWT client code on a REMOTE server using IntelliJ 9 Community Edition?
http://www.gwtproject.org/doc/latest/DevGuideCompilingAndDebugging.html
and the overall-conclusion is to
add parameter -noserver (either directly or using the google plugin for eclipse)
specify the URL of the desired server within the arguments-tab of the run/debug configuration
in run/debug configuration for a webApplication.
But after doing this, for me it seems that still the default jetty server is tried to be invoked by the provided launch URL:
http://127.0.0.1:8888/ApplicationName.html?gwt.codesvr=127.0.0.1:9997
Of course, the server can not be started due to the -noserver flag, but why is it tried to launch at all?
When following the GWT-guide:
Configure your server however you need to; note the URL which contains the host page for your GWT application.
.......
Add the -noserver command line argument. Change the URL at the end of the argument list to match the URL you recorded in step #1.
How do I change the URL at the end of the argument list? In my project, there is no URL at the end of the argument list which looks like:
-noserver -nosuperDevMode -remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -logLevel INFO -codeServerPort 9997 -war C:...\MyWebApp\war com.mycompany.mywebapp.MyWebApp
Which flag do I use to specify the URL of the desired server, -bindAddress, -server, -startupUrl?
Is my assumption correct, that after proper configuration the provided launch URL must not contain any 127.0.0.1, but (only) the URL of the dedicated server?
Any tipps are very welcome - I'm rather confused at the moment.
Best Regards!
First: The URL that is shown after starting the devmode is just for your convenience(the jetty code server was not started).
You can check that by starting the devmode and then opening the URL to your external server, for example http://localhost:8888/your_app_path/index.html, add just add ?gwt.codesvr=127.0.0.1:9997. Usually the devmode should start now anyway.
By setting up the startup url to http://localhost:8888/your_app_path/index.html the plugin will show you the correct URL: http://localhost:8888/your_app_path/index.html?gwt.codesvr=127.0.0.1:9997
I think one of the best options is to run the GWT Development Mode (CodeServer) instead of DevMode with -noServer to debug with an external web server.
Example of Using a WTP runtime configuration with a GWT Development Mode with Codeserver
https://www.youtube.com/watch?v=LtH4KzmguL0&index=7&list=PLBbgqtDgdc_TqzA-qXrjgTFMC_6DKAQyT&ab_channel=BrandonDonnelson
Example of using a Simple external web server with GWT Development Mode (CodeServer)
https://www.youtube.com/watch?v=pOwUpBuVtWE&index=5&list=PLBbgqtDgdc_TqzA-qXrjgTFMC_6DKAQyT&ab_channel=BrandonDonnelson
I am developing a GWT application.
And I would like to know if I am running over a Jboss instance or over a Jetty instance.
This is because if I am running over Jetty it means that I am running the dev mode and I need to redirect to MyModule.html?codeserver... but if I am running over Jboss I need to redirect to MyModule.html
But I can't figure how can I know if I am running over Jetty or over Jboss.
You should not try to find out the webserver on which your application is running, in your application code. Instead you can have a discriminating parameter set in the context of your application with different values for different servers.
E.g.
For JBoss, the server.xml can contain a parameter in the context definition as follows:
<Context ...>
...
<Parameter name="applicationStage" value="prod" />
...
</Context>
and for Jetty, the same context parameter would go into its jetty.xml but the value as "devo".
If you just want to know wether you are running production or development mode, then try
GWT.isProdMode();
Only works client-side of course.
There's not really any simple way to determine what application server you're running on (to my knowledge). You could check some system properties to determine this.
JBoss:
jboss.server.name
Jetty:
jetty.home
Although I do not encourage having logic determined by your environment as Vikdor mentions in his answer. His suggestion would be a better approach.
In a JSP,
Server is <%= application.getServerInfo()%>
or use
Server is ${pageContext.servletContext.serverInfo}
in a Servlet,
String server = getServletContext().getServerInfo();
I have an application with name test.war.
Because of Apache installed on my server I have to use another port number for Tomcat applications so after deployment this application available at domain.com:8080/test/.
I decided to create a subdomain in order to remove that ugly 8080 from url, so I setted up the server like described here. So now test.domain.com reffers to domain.com:8080/test/.
Everything seems fine except of one problem - because my application is not ROOT.war and I am using spring:url function every url in the application is translated to /test/bla-bla. So I removed that function. But still have a problem with spring security because it still translates an urls relative to app name i.e. /test/bla-bla.
How can I solve that problem?
Thank you
UPD: I don't want to deploy it as a ROOT application because I have two or three such applications and I wanted to create a subdomain for each one of them
Spring Security doesn't "translate" URLs. In fact this isn't specific to Spring Security. You'll run into similar issues with any application which does redirects. If you want to hide the context paths of applications which are behind a proxy, then you need to rewrite the URLs at the proxy.
I'd recommend you read the Tomcat Generic Proxy Howto and the section on URL rewriting in particular, as it specifically addresses this issue.
My old way using mod_jk in apache and configure virtual host in tomcat
In the JSP file, I refer to CSS as below
/<%=request.getContextPath()%>/css/styles.css
while the home link is set to
/<%=request.getContextPath()%>/
so this worked fine when I use mod_jk in apache to work with tomcat using ajp;
When I try to configure reverse proxy as below
ProxyPass / http://localhost:800/mywebapp
ProxyPassReverse / http://localhost:800/mywebapp
the home page can be retrieved fine but the css request becomes
http://mydomain.com/mywebapp/mywebapp/css/style.css
so the css file can not be retrieved correctly;
I think one possible way is to always use relative path like ./style.css or ../style.css
a. since header/footer are shared, and the home page is in a different level with detail page, it's inconvenient to use relative path because they're at a different level
b. still, I think the home link will have to be /<%=request.getContextPath()%>/
so I wonder what's the way to set contextroot fine in java web and also work fine with reverse proxy?
thx a lot
As I know your application server (Tomcat) isn't able to be aware of a reverse proxy presence. Generally speaking, it can be contacted through any number of reverse proxies or directly by browsers. A network configuration is usually used to limit this, not HTTP or Java.
So, you must accurately rely on relative URLs to make your application work well.
When I have to deal with reverse proxy presence (almost always due to SSO architectures), I embed a "junction" configuration string item (the portion of the URL used in the proxy to map the application) and use it in the only places where I need to build an absolute URL.