You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Leo Donahue - OETX <Le...@mail.maricopa.gov> on 2013/11/22 22:57:54 UTC

parallel deployment question

I experimented with deploying a demo.war and a demo##001.war

When I parallel deploy demo##001.war, in my servlet, when I use:  servletContext.getContextPath();  it prints:  /demo

Why doesn't it print /demo##001 ?

If I do:  servletContext.getRealPath(getServletName());  it prints:  C:\ApacheTomcat\apache-tomcat-7.0.42\webapps\demo##001\servlet-mapping-name

I wanted to grab the demo##001 name and stick in the corner of my web apps running in development, so users can see which version is deployed.  
Can I get demo##001 without parsing the results of getRealPath()?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: parallel deployment question

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Leo Donahue - OETX [mailto:LeoDonahue@mail.maricopa.gov] 
> Subject: RE: parallel deployment question

> > http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming

> "If a version is specified then the context path remains unchanged (the path 
> being demo) and both the **context name** and the base name have the string 
> '##' appended to them followed by the version identifier"

> I thought the context name would be demo##001 after reading this.

Somewhat confusing choice of words in the doc.  The phrase "context name" here does not refer to the getServletContextName() API.  If you read the JavaDoc for that, you'll see that it refers only to an element in web.xml:

"Returns the name of this web application corresponding to this ServletContext as specified in the deployment descriptor for this web application by the display-name element."

 - Chuck 


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: parallel deployment question

Posted by Leo Donahue - OETX <Le...@mail.maricopa.gov>.
>-----Original Message-----
>From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com]
>Subject: RE: parallel deployment question
>
>> From: Leo Donahue - OETX [mailto:LeoDonahue@mail.maricopa.gov]
>> Subject: RE: parallel deployment question
>
>> I guess I thought it would get the path name from the name of the .war file.
>
>Read the doc:
>http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming
>

" If a version is specified then the context path remains unchanged (the path being demo) and both the **context name** and the base name have the string '##' appended to them followed by the version identifier"

I thought the context name would be demo##001 after reading this.  That last line of Java code just prints demo.

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		ServletContext servletContext = getServletContext();
		
		PrintWriter out = response.getWriter();
		out.write("getContextPath(): " + servletContext.getContextPath());
		out.write("\n");
		out.write("getRealPath-getServletName: " + servletContext.getRealPath(getServletName()));
		out.write("\n");
		out.write("getServletContextName: " + servletContext.getServletContextName());
		out.write("\n");
	}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: parallel deployment question

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Leo Donahue - OETX [mailto:LeoDonahue@mail.maricopa.gov] 
> Subject: RE: parallel deployment question

> I guess I thought it would get the path name from the name of the .war file.

Read the doc:
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming

> deploying demo##001.war on Tomcat 6.0.x doesn't even deploy it.

A single hash mark in a .war file name is replaced by a slash for the context path.  The action of a double hash is undefined in Tomcat 6, as far as I can tell.

> I did find this article that talks about web module names being all lowercase 
> ASCII characters.

That's a guideline, not part of the spec.  Lots of people use mixed-case context paths, which usually annoys end users, since the case in the request must match context path.

> So where in the Tomcat source code can I look at how this ## is being 
> implemented?

Start at org/apache/catalina/util/ContextName.java.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: parallel deployment question

Posted by Leo Donahue - OETX <Le...@mail.maricopa.gov>.
>-----Original Message-----
>From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com]
>Subject: RE: parallel deployment question
>
>> From: Leo Donahue - OETX [mailto:LeoDonahue@mail.maricopa.gov]
>> Subject: parallel deployment question
>
>> When I parallel deploy demo##001.war, in my servlet, when I use:
>> servletContext.getContextPath();  it prints:  /demo
>
>> Why doesn't it print /demo##001 ?
>
>Because the context path is the same for all versions - that's the whole point.  If
>the context path were different, the *client* would have to know that to reach
>the new version.
>
> - Chuck

I guess I thought it would get the path name from the name of the .war file.

I have more reading to do.. deploying demo##001.war on Tomcat 6.0.x doesn't even deploy it.  Why not?  The use of ## in the war file name prevents Tomcat 6.0.x from deploying it?  I wasn't trying parallel deployment in Tomcat 6.0.x, just seeing if the demo##001.war would deploy, and it doesn't.

I didn't see anything in the servlet spec that says how not to name .war files.  

I did find this article that talks about web module names being all lowercase ASCII characters.
http://www.oracle.com/technetwork/java/namingconventions-139351.html 

So where in the Tomcat source code can I look at how this ## is being implemented?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: parallel deployment question

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Leo Donahue - OETX [mailto:LeoDonahue@mail.maricopa.gov] 
> Subject: parallel deployment question

> When I parallel deploy demo##001.war, in my servlet, when I use:  
> servletContext.getContextPath();  it prints:  /demo

> Why doesn't it print /demo##001 ?

Because the context path is the same for all versions - that's the whole point.  If the context path were different, the *client* would have to know that to reach the new version.

> If I do:  servletContext.getRealPath(getServletName());  it prints:  
> C:\ApacheTomcat\apache-tomcat-7.0.42\webapps\demo##001\servlet-mapping-name

The getRealPath() API is an abomination and should never be used.  Some servlet deployments are on platforms without file systems, which is why it's allowed to return null.

> I wanted to grab the demo##001 name and stick in the corner of my web 
> apps running in development, so users can see which version is deployed.

Your webapp should have a build or version number included as part of your build mechanism.  That number should not be associated with the deployment mechanism.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org