In production we run tomcat behind apache, in development bare tomcat.
How can I know inside the Servlet class if it is running behind apache or not?
This depends on how your Apache is talking to Tomcat.
If it's connected via HTTP (mod_proxy), you can check request.getRemoteAddr(). It will be the IP of the Apache, probably your internal IP. You can also check "Via" header to see if Apache is there.
If it's connected via AJP (mod_jk/mod_proxy_ajp), you can check request.getLocalPort() to see if it's the port of your JK connector.
If this is to distinguish between development and production environment, then you will probably be better off by having this completely under your control instead of ad-hoc guessing (which will eventually break).
This could be "Is feature X set in JNDI?" or "Is property foo.bar set in c:/ourproject.properties". You should not rely on artifacts like "is class X loaded from a file or found inside a jar" (since that will break if you change application servers) or "Is http header line X present" since that is out of your control plus it may break if somebody else is using Apache as a frontend accellerator.
So, explicit configuration - it can be done quite easily :)
Related
I've made a script called debug.sh and placed it under the bin directory (start it with ./debug.sh) to start Tomcat 8 in debugging mode:
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket
set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
bash catalina.sh jpda start
But if it started, there is now message which says, that Tomcat is listening on port 8000. Also if I type
netstat -nat
there is no application listening on port 8000.
What exact configuration do I have to set, to remote debug my Tomcat 8 server which is running on a specific IP or do I have just a little problem in my script?
This answer has been updated following the comments, I did not understand the problem in the first place.
I guess you have followed that doc: this is about developing Tomcat itself.
I am not sure you are using the proper way to configure the port (I don't know your specific configuration details). In a standard environment, the ports are configured in the server.xml (note that several different ports are used by Tomcat for the different services).
To remotely monitor your server, you should use a JMX client. As far as I know, Eclipse doesn't include one (or at least not one documented) - you could code one as this is a Java specification (JSR262). You have one in a standard Java environement (JConsole). By default, JMX is not enabled on Tomcat. If you need to enable it, the fine way is to follow the doc.
Tomcat JMX monitoring and JConsole are both available in most versions of Tomcat and the Java runtime.
The following exchange seems to be about your problem.
Follwing the steps as outlined here: Standalone web service
I created a test web service that works great on my local machine. Since this is 'stand alone' I copied the same root folder on to a 'server' that I use and published the service on the server (as if it is my local machine). When I access the wsdl using localhost as the domain name, it works fine on the server. However, when I try the url from a different macihne on the network giving the server's domain name instead of localhost, I get a 'can not be displayed' error in IE.
My question is, should this even be possible? Or is there anything specific that needs to be done. Since this is a 'stand alone' solution, we should not require 'another' container like tomcat correct?
To be honest, until your post, I had no idea there was a builtin, lightweight, HTTP Server in the JDK. I've always used glassfish for my web service needs.
I can't say for sure, but if you look closely at the example code you'll see:
Endpoint endpoint = Endpoint.publish("http://localhost:8080/calculator", calculator);
I suspect that this limits you to "localhost" as opposed to the host machine. Try changing it so that it represents the name of the server and try again from another machine (naturally making sure it can get through the firewall as well). Something like:
Endpoint endpoint = Endpoint.publish("http://myserver:8080/calculator", calculator);
Rebuild it and try again. Other than that, you'd need to create a proper war file and deploy to glassfish, tomcat, etc.
I'm running Weblogic 12.1.2 on Mac OS X and I have a system wide proxy set in Network Configuration.
I wan't Weblogic to ignore the proxy setting and use direct connection to web services. However, the Weblogic seems to ignore any command line http.proxy* parameters.
I modified startup script to add following parameters:
-Dhttp.nonProxyHosts=* -Dava.net.useSystemProxies=false -Dhttp.proxySet=false
but Weblogic still tries to use proxy to connect to web service.
Anyone experiencing similar behavior? Should I use some specific prefix?
EDIT: Weblogic 12.1.1 seems to ignore proxy settings at all.
I forgot that I must re-set http and https proxy.
The best place to do it is in file setDomainEnv.sh by adding following lines to the bottom:
PROXY_SETTINGS="-Djava.net.useSystemProxies=false -Dhttp.proxyHost=\"\" -Dhttps.proxyHost=\"\" -Dhttp.proxyPort=\"\" -Dhttps.proxyPort=\"\""
export PROXY_SETTINGS
you should set in http.nonProxyHosts
http.nonProxyHosts: a list of hosts that should be reached directly, bypassing the proxy. This is a list of patterns separated by '|'. The patterns may start or end with a '*' for wildcards. Any host matching one of these patterns will be reached through a direct connection instead of through a proxy.
java -Dhttp.nonProxyHosts=”localhost|host.example.com” GetURL
I have a few applications hosted on Tomcat running a machine called test-websites throuhg port 8080. So they are accessible like this:
http://test-websites:8080/app1/
http://test-websites:8080/app2/
...
http://test-websites:8080/appN/
What I need to do is make these applications accessible on my local network by:
http://app1.test-websites/
http://app2.test-websites/
...
http://appN.test-websites/
As I add new applications to Tomcat's webapps folder, I want them to be automatically available using the same subdomain pattern.
So I thought using Apache in front of Tomcat to make the URL rewriting would be a good idea, but so far I have not been able to configure the virtual host on Apache to make this redirect. I installed apache2 on port 80 and I see the default "It Works!" apache page when I access http://test-websites/, but I couldn't find how to make the redirects to the apps in the Tomcat following the format above.
I have searched for over 4 hours and didn't get an answer for this use case.. any help us much appreciated!
Thank you!
Eduardo
First you need to add a DNS entry for app1.test-websites, app2.test-websites,.. such that it points to test-websites. Generally CNAME entry works best in this case. If you only need the URLs to resolve on your local machine (for testing purpose), you can just update your /etc/hosts or C:\windows\system32\drivers\etc\hosts file. Otherwise you need to figure out how your company's network is setup and change the DNS entry (if it's a Windows domain network, normally there's a DNS service on the domain controller. On some smaller network you have to configure it on the router).
Next, the quickest way to achieve this is to not use apache2 to front it, bust simply have tomcat listening on port 80. You can setup virtual host on tomcat such that it serves different web-app depending on the URL requested.
My team and I would like to implement "Continuous Deployment" for our website. Continuous Deployment basically means deploying to production very frequently (multiple times a day). Supposedly Etsy does this all the time.
Our environment is Tomcat + Nginx. We already do Continuous deployment of any code change to our snapshot server (ie traditional continuous integration) using Hudson and a Hudson+Cargo plugin that hot deploys.
Surprisingly that works well (albeit over time we have to restart tomcat sometimes).
For production this is not going to work because we can't have the website down.
I have some ideas like having two web apps and redirecting while one is down.
Anybody have any ideas or has done this before in a real production environment?
From http://radar.oreilly.com/2009/03/continuous-deployment-5-eas.html:
Real-time alerting. No matter how good your deployment process, bugs can still get through. The most annoying variety are bugs that don’t manifest until hours or days after the code that caused them is deployed. To catch those nasty bugs, you need a monitoring platform that can let you know when things have gone awry, and get a human being involved in debugging them.
To effectively implement continuous deployment to production, you need good monitoring, otherwise you will not understand what is happening with your application.
I don't know WHY you think this is a good idea, but thats up to you.
I would use a balancer application with two hot systems, which can be found in tomcat itself, and then just stop the server before deployment, deploy, and restart the server. Leave a two minute window for each hot server, and you should be good.
EDIT: I wouldn't deploy EVERYTIME. We also are a small company with noch much QA (tm), but it is still one click in the build system to go live.
We use apache httpd 2.2 and mod_proxy for this
We then have 2 tomcats running, one on port 8080, and one on port 88.
The firewall prevents outside access to those ports, so only port 80 is open
Apache HTTPd is configured to listen on port 80
It is very simple to configure too.
This is a basic configuration (httpd.conf) that will work out of the box:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<Proxy balancer://mycluster>
BalancerMember http://localhost:8080
BalancerMember http://localhost:88 status=+H
</Proxy>
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/
The "+H" means that it is only used as a backup server, so when 8080 is unreachable, it will run on 88 until 8080 comes back online