Shaun Abram
Shaun Abram

Reputation: 281

Cloudbees virtual host versus tomcat context path

I have a web app that I run locally in tomcat and which I have also deployed to Cloudbees. However, I am having some problems with cloudbees using a virtual host versus my local tomcat using a context path.

I access my local tomcat app via

In cloudbees, I access it via

So far so good, but the problem is when I try to do a submit. Locally, this submits successfully to

But on cloudbees, it tries (and fails) to submit to

If I manually modify the browser URL to

it all works fine.

I saw a similar problem posted here, but the suggested solution was to

  1. update the web.xml to use the prefix path (e.g. I think /SpringMVC in my case), but this would break my local tomcat version, or
  2. deploy the app as an EAR file with an application.xml - but migrating to an EE container like tomcat EE or JBoss will be a much bigger task.

I had thought the solution might be to use the CloudBees Web Configuration File to somehow configure the app to use (something like) http://springmvc.shaunabram.cloudbees.net/SpringMVC as my base url, but I can't see any examples of that (all CloudBees Web Configuration File examples seem to be used for environment specific DataSources).

Any help greatly appreciated!

Shaun

Upvotes: 0

Views: 698

Answers (2)

nicolas de loof
nicolas de loof

Reputation: 2633

Web application should never use absolute path and always build URL using ServletContext.getContextPath(). I wonder you hit this issue, assuming you use SpringMVC that handles this for you.

Or maybe you hard-coded some resources path, but should use to generate the adequate path, or a scriptlet to append context Path :

<c:url value="/style.css" var="url" />
<link rel="stylesheet" href="${url}" type="text/css">

or

<link rel="stylesheet" href="${pageContext.request.contextPath}/style.css" type="text/css">

see also Spring MVC Request URLs in JSP

Upvotes: 2

swashbuck1r
swashbuck1r

Reputation: 378

CloudBees runs your applications using a ROOT context path [/]. You have at least two options to make your app work in both your local environment and the Cloud environment:

  • Run your app locally using a ROOT context (by deploying the app to webapps/ROOT or webapos/ROOT.war)
  • Change the URL used to generate your form to construct the form's action path using request.getContextPath()

Upvotes: 0

Related Questions