tomcat 6: accessing web app without war name in the URL and without overwriting ROOT? - url

in my war's META-INF/context.xml I have:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/foobar" docBase="my-long-war-name"/>
I deploy my war to the webapps/ directory and I confirm that my contex.xml is in %CATALINA_HOME%\conf\Catalina\localhost with the name my-long-war-name.xml
Now, instead of accessing my REST service through http:/ /localhost:8080/my-long-war-name/contacts/data tomcat should allow http:/ /localhost:8080/foobar/contacts/data
but I can only access my service through the former URL. It's as if it completely ignores the path given above for my web app. I even tried omitting docBase and that didn't work either.
why doesn't this work?! it's supposed to be so basic!

I don't see why you need the <Context>. I never touch that when deploying to Tomcat, and everything works fine.
Why don't you just make the WAR name foobar, deploy it, and be done with it? You seem to be wedded to this idea in spite of the evidence to the contrary about how basic it is.

Related

how to access grails application on Tomcat

I'm trying to deploy a simple grails application on my test-server which is tomcat. I've built the WAR with grails war command so I've got a war file named: simplgrailsapp-0.1.war
When I deploy this to tomcat I'm getting a lot of errors which I'm going to resolve one-by-one. But the URL for the app from tomcat manager (mytestserver:8080/manager) is http://mytestserver:8080/simplegrailsapp-0.1/ which doesn't seem correct. Because when I run the app locally the url is: localhost:8080/simplegrailsapp
I've also tried to access the app by http://mytestserver:8080/simplegrailsapp but that doesn't work either.
How can I fix this?
By default, when you deploy a WAR to tomcat it will fall under the context of the name of the WAR file. So in your case, the context becomes simplegrailsapp-0.1. You can:
rename your war file to whatever you want the context to be before you deploy it
define a Context for the application in Tomcat
If you go with defining a context this can be added to the WAR file by creating a META-INF folder in the web-app folder of your project and creating the context.xml file there.

How can I remove the application name from a Grails application’s URL?

I have an application running at a URL like this:
http://myapp.mydomain.com/myapp
I don’t want the /myapp part in the URL. So how can I get rid of the application name? I want just
http://myapp.mydomain.com
to be the URL. How can I do this?
bit detailed approach
First Method:
first shutdown your tomcat [from the bin directory (sh shutdown.sh)] then you
must delete all the content of your tomcat webapps folder (rm -fr *) then
rename your WAR file to ROOT.war finally start your tomcat
[from the bin directory (sh startup.sh)]
Second Method:
leave your war file in CATALINA_BASE/webapps, under its original name - turn off
autoDeploy and deployOnStartup in your Host element in the server.xml file.
explicitly define all application Contexts in server.xml, specifying both path
and docBase. You must do this, because you have disabled all the Tomcat
auto-deploy mechanisms, and Tomcat will not deploy your applications anymore
unless it finds their Context in the server.xml.
Note:
that this last method also implies that in order to make any change to any
application, you will have to stop and restart Tomcat.
Third Method:
Place your war file outside of CATALINA_BASE/webapps (it must be outside
to prevent double deployment). - Place a context file named ROOT.xml in
CATALINA_BASE/conf//. The single element in this context file MUST have a
docBase attribute pointing to the location of your war file. The path element
should not be set - it is derived from the name of the .xml file, in this
case ROOT.xml. See the Context Container above for details.
1) Your app server needs to be configured to have your grails application as ROOT application
2) your grails application context path should be "/" or app.context=/
You can make Tomcat serve a webapp as the root context by simply naming it ROOT.war, i.e. take the myapp-0.1.war generated by Grails and copy it to TOMCAT_DIR/webapps/ROOT.war.
If you have a setting for grails.serverURL in your Config.groovy you will need to override this for your production environment to ensure that any absolute links generated by Grails are correct
environments {
production {
grails.serverURL = 'http://myapp.mydomain.com'
}
}
But in Grails 2 it is usually safe to omit grails.serverURL entirely and let the app deduce the right value at runtime. You only need it if you're running behind a reverse proxy that doesn't pass through the correct Host header.

configuring the root url for a Heroku Grails app

I'm using the Grails stack on Heroku to deploy an app. I'd like to be able to serve my app with a root of myapp.herokuapp.com/xyz as opposed to myapp.herokuapp.com, in the same way I'm able to serve from root of localhost:8080/xyz in development. I've tried adding a grails.app.context in Config.groovy like so:
environments {
production {
grails.app.context = "/xyz"
}
}
But it doesn't seem to have an effect in deployment. Do I have to configure something with Heroku? Any ideas?
It looks like you have to add a jetty-web.xml file to the WEB-INF directory to set the context path:
<?xml version="1.0" encoding="UTF-8"?>
<!-- File: web-app/WEB-INF/jetty-web.xml -->
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="contextPath">/xyz</Set>
</Configure>
If this helps proper credit goes to this site, which was linked from an article on Grails and Heroku by Tomas Lin.
I don't think you can set context path with the current Grails build pack. If you feel like it, you can fork the build pack and hack it to support setting context (see build pack doc for more info on build packs).
Another option is to build your Grails app locally into a WAR file and deploy the WAR file using WAR deployment. The WAR deployment process will use the webapp-runner utility to run your app with Tomcat and it supports configuring the context path. Here's the help output for webapp-runner 7.0.22.3 (what I happened to have installed, might be slightly out of date):
Tomcat Runner runs a Java web application that is represented as an exploded war in a Tomcat container
Usage: java -jar tomcat-runner.jar [arguments...] path/to/webapp
Arguments:
--session-timeout The number of minutes of inactivity before a user's session is timed out
--port The port that the server will accept http requests on
--context_xml The parth to the context xml to use
--path context path (default is /)
--session_manager session store to use (valid options are 'memcache')
--session_manager_operation_timeoutoperation timeout for the memcached session manager. (default is 5000ms)
--session_manager_locking_modeSession locking mode for use with memcache session store. (default is all)
--session_manager_ignore_patternRequest pattern to not track sessions for. Valid only with memcache session store. (default is '.*\.(png|gif|jpg|css|js)$'
As explained in the WAR deploy doc, you can set webapp-runner options for your webapp using the WEBAPP_RUNNER_OPTS config var.

Using MSDeploy for deploy of console application to a DMZ server

I am trying to deploy a console application to a folder on a DMZ server using autodeploy with MSBuild and Team Foundation Server.
I am already deploying multiple sites to that same server and it works great. I have tried multiple ways but the files are not deployed.
First, I tried to deploy the console app in the same way as i do for my web site, ie:
<MSBuild
Projects="$(SolutionRoot)\MySolution.sln"
Properties="AllowUntrustedCertificate=True;AuthType=Basic;
Configuration=DEBUG;CreatePackageOnPublish=True;
DeployIisAppPath=Default Website/dummy.dev.myapp;
DeployOnBuild=True;DeployTarget=MsDeployPublish;
MSDeployPublishMethod=WMSvc;
MsDeployServiceUrl=https://xxx.xxx.xxx.xxx:8172/MsDeploy.axd;
UserName=userid;Password=password;UseMsdeployExe=True"
/>
Without success.
EDIT: No error message is returned. It all seems to go well.
Then, I also tried to deploy the console app as follows:
<Exec Command=""C:\Program Files\IIS\Microsoft Web Deploy V2\MSDeploy.exe"
-verb:sync
-source:contentpath="$(OutDir)\MyApp.Precompiled"
-dest:contentpath="D:\dev.myapp",computername=xxx.xxx.xxx.xxx,username=userid,password=password"
ContinueOnError="false" />
I actually also tried with computername as https://xxx.xxx.xxx.xxx:8172/MsDeploy.axd.
EDIT: The following is what I got.
EXEC: FileOrFolderNotFound
EXEC: Object of type 'contentPath' and path 'E:\Builds\1...\dev.myapp' cannot be created.
EXEC: The path '\?\E:\Builds\1...\dev.myapp' is not valid.
EXEC: 1.
E:\Builds\1...\BuildType\Targets\Deploy.targets (142): The command ""C:\Program Files\IIS\Microsoft Web Deploy V2\MSDeploy.exe" -verb:sync -source:contentpath="E:\Builds\1...\dev.myapp" -dest:contentpath="D:\dev.myapp",computername=https://xxx.xxx.xxx.xxx:8172/MsDeploy.axd,username=userid,password=password" exited with code -1.
I realize I haven't read all of the error, Do I really need an UNC path?
Does anyone know how to do this?
I finally found out how to make it work.
<Exec Command=""C:\Program Files\IIS\Microsoft Web Deploy V2\MSDeploy.exe"
-verb:sync
-source:contentpath="$(OutDir)\MyApp.Precompiled"
-dest:contentpath="D:\dev.myapp",computername=https://xxx.xxx.xxx.xxx:8172/MsDeploy.axd,username=userid,password=password,authtype=Basic
-allowUntrusted=True"
ContinueOnError="false" />
I changed computername to computername=https://xxx.xxx.xxx.xxx:8172/MsDeploy.axd, added authtype=Basic and allowUntrusted=True and voila it worked.
It was quite frustrating not having any kind of feedback of what went wrong with the first option. But when I was using the second alternative I got feedback to work with.
If anyone know how to make this work using the MSBuild task, please feel free to enlighten me.
Try dirPath provider instead of contentPath, it'll behave more like a folder sync rather than IIS web site deployment.
Considering the sync worked using the EXEC task, did you make sure you have the Microsoft.WebApplication.targets in your csproj (or vbproj) file? I could see it just ignoring that msbuild task without the correct targets file included.
For example in my web service project files, I have this towards the bottom of my csproj file
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

Grails Config: include another config file

I have in my main config something like:
grails.config.locations = ["file:grails-app/config/Jawr.groovy"].
When running the application with grails run-app, everything is OK.
But, on deployment (creating the war archive) this does not work anymore, as the file "Jawr.groovy" is not kept anymore on the filesystem (it should be only in the war).
Do you have a solution for that? Hw do you include external files into the grails main configuration file?
Thanks.
Okay, a few things here.
First, because you don't have a leading slash on your config path, that is a path relative to who knows where. I played with this in Tomcat, and that path ends up being relative to the working directory you were in when starting the Tomcat server. If you start Tomcat, shut it down, change directories, then start it again, you are going to get two different config paths.
Second, the grails-app directory only exists within the source tree of your Grails project. The structure of an unpacked WAR file is more like the web-app folder of your Grails source tree, with folders like WEB-INF, META-INF, js, images, etc.
Third, you probably want to avoid putting your externalized config file inside the folder of your webapp. The next time you deploy your app, that configuration is going to get wiped away with the old version of the app. One of the points of the externalized config is so that you can redeploy without having to reconfigure.
A simple, but less than ideal, solution would be to use a static, fully qualified path, like /etc/yourApp/conf.groovy, then put that in the documentation. There is also a plug-in that handles this.
http://www.grails.org/plugin/external-config
I haven't used it, but the description makes it sound like it does sensible things.
see this: https://stackoverflow.com/questions/6341117/is-it-possible-that-grails-xxconfig-groovy-as-a-script-no-compile
Then I put it into /shared, and
modify:
//Config.groovy
grails.config.locations =
["file:shared/TZLibConfig.groovy"]
//BuildConfig.groovy
grails.war.resources = { stagingDir, args ->
copy(todir: "${stagingDir}/WEB-INF/shared"){
fileset(dir:"shared",includes:"**")
}
}
In my work, our team often use a system properties to save the path to the config file (often in home folder of the user running the app - for privilege sake). Then we manually copy the config file into that path
To identify that it's the production environment, we use the following code in Config.groovy:
if (System.properties["${appName}.config.location"]) {
grails.config.locations = ["file:" + System.properties["${appName}.config.location"]]
}
This article suggests allowing the user to specify the location of the config file as an environment variable or as a java property --- meaning you can simply specify it with -D on the command-line. This can be used in addition to all the other methods.

Resources