Unable to store cookies in war deployed from Tomcat7 - java

I am using/trying to deploy grails war app to the tomcat7 virtual host configured in server.xml. I have modified etc/hosts to redirect www.mytest.com to localhost (referred from ramkitech). There seems no problem in the code as it works in development(By this, I mean I run my code from grails run-app and access http://localhost:8080/app/). The problem is when I deploy it to independent tomcat7 and put it as ROOT.war in the webapps folder and run the tomcat service, I can access the war based app at http://www.mytest.com:8080/ and when I try to set cookies, they do not seem to be stored and hence, I can't access the cookies set. By the way, the war was generated by the grails dev war. What could be going wrong here?
Server.xml
<Host name="www.mytest.com" appBase="webapps"
unpackWARs="true" autoDeploy="true" >
<Alias>mytest.com</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
I referred this from http://www.ramkitech.com/2012/02/understanding-virtual-host-concept-in.html and I am using grails cookie plugin 1.4 and basically call savePreference() with ajax providing sample cookie from the the view.
def savePreference(Map cleanParams=[:]) {
cleanParams.each{key,val->
cookieService.setCookie(key, val)
}
return "OK"
}
and here is sample cookie key value pairs I store:
prod_type:A
prod_categoryId:2
prod_id:3

Related

Tomcat and vHost fails on specific subdirectory

i try to set my domain as vhost.
My config looks like this:
<Host name="example.de" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Alias>www.example.de</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="example_access" suffix=".log"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="/opt/tomcat/webapps/app1" debug="0" reloadable="true" />
</Host>
This config works with every subdir in the webapps-directory, except for the directory I want. If I try to open the Domain, there is an empty browsertab. (Error 404) But if I call it like www.example.de/app1, the app still works and everything ist fine :/
I don't have any idea :/
PS: It's a clean setup of Tomcat, just extracted and edited the server.xml for the vHost-settings
Remember to deploy every application you'd like to appear in a virtual host, including the ROOT application. If you don't have a ROOT application, there is no "default" application that Tomcat can fall-back to, and your clients will get 404 responses when requesting /.

webapp deployed twice and quartz job running twice

I'm running a quartz job in my web application which is deployed in tomcat. But the problem is the job is executed twice.
After some internet research I've found that adding a new Host with autoDeploy in tomcat's server.xml may cause twice deployment. Which I guess is causing my quartz scheduler executed twice.
I tried with autoDeploy = "false". But the problem continues.
Here is the host config in my server.xml:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="false">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<Host name="demo.example.com" appBase="webapps/demo" unpackWARs="true" autoDeploy="false">
<Context path="/" docBase="." reloadable="true" />
</Host>
Edit (FYI):
my cron expression: 0 50 12 * * ? which is scheduled to run everyday at 12:50 pm.
Is this configuration will deploy my application twice? What can I do to avoid that? Thanks is advance.
If your observation is indeed correct then there could be multiple problems here -
In addition to custom location that you specified in server.xml, your app might be present in tomcat/webapps folder as well.
You might be using hot deployment from within some IDE and saving a file within IDE might be reloading the context, thus having quartz reinitialized again, which might be giving your wrong impression.
You indeed have some code problem.
It hard to say what's going on w/o looking at the code snippet but this should be fairly simple problem.

Unable to access tomcat deployed java web application using godaddy domain name

We have VPS and domain name by go daddy . We have deployed java web application in tomcat installed on VPS. I am able to acccess appplication by ip address
for example : xxxx.xxxx:xxx:xxxx:8080/mysampleweb but i want to acccess the same application by my registered domain name i.e www.mysampleweb.com
what i did
1) I have added host entry in tomcat server.xml
2) map domain name with IP in DNS in godaddy account
3) Changed port from 8080 to 80 but no luck
Can any one share me details step to map/access tomcat deployed web application on VPS by registered domain name
Open the server.xml file
<Alias>www.test.local</Alias>
<Context path="" docBase="ExtractedWARName" debug="0" privileged="true" />
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false" />
where ExtractedWARName is the war extracted folder name.

How to map tomcat 7 webapp to my domain

I know this has been touched upon in several ways already, but i'm still having issues - I have a webapp in:
/var/lib/tomcat7/webapps/abc.war
I have a domain at say, my.domain.com
I've added this to my conf/server.xml (which i believe is set correctly?)
Docbase points to the war folder?
<Host name="my.domain.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context path="" docBase="/abc" debug="0" privileged="true" />
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false" />
</Host>
My domain ip is in the /etc/hosts along w/ the local host ip:
127.0.0.1 localhost
123.123.123.33 HostName.my.domaing.com HostName
$ /etc/hostnames
HostName
With my current settings above i'm am not getting any results in seeing my webapp online. Any thoughts would be very grateful!
My domain already is mapped to my /var/www/html directory too. I can see my temp index.html file online. My tomcat webapp works fine through ip:8080/abc
I'm working on Ubuntu Server 14.04 - Apache2
This is my first time working w/ tomcat and it's a bit confusing.
Thank You!
Your /etc/hosts should contain an entry like this:
123.123.123.33 my.domain.com
or
123.123.123.33 HostName.my.domaing.com HostName my.domain.com
Otherwise you won't be able to resolve the name my.domain.com to connect to your Tomcat.
If you already configured your firewall earlier, to redirect ports you type
sudo firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080 --permanent
and reboot it.

How to map domain to web application deployed on Tomcat 7 in Ubuntu?

I have a Java based web application which is deployed on Ubuntu machine. I can access the web application at localhost:8080 and it is working as expected.
Now I have domain name for the web application and I want to access web application through the browser using the domain name(http://www.xyz.com).
I want to know the steps which are required to achieve it. Before posting this question, I search over the google.
I have already added the host details in the conf/server.xml.
<Host name="xyz.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Alias>www.xyz.com</Alias>
<Context path="" docBase="" debug="0" privileged="true" />
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false" />
</Host>
Also, I made changes in the /etc/hostname and added following
<IP Address> www.xyz.com xyz
What else do I need to do?

Categories