Re: Regarding Tomcat url redirection
Lavanya, On 5/9/24 13:48, lavanya tech wrote: Thank you so much for your explanation. I will try these options. Do server and example both resolve to the same IP? -yes Good, that significantly reduces the complexity required, since you can do it will a single process (Tomcat) in a single environment. So I need follow both 4a/b and 5a/b steps here or any of them ? If I setup exactly by using below steps , then I should access both the urls right ? https://server.lbg.com:8443/towl and https://example.lbg.com If you visit either hostname with /towl, you will be redirected to example.lbg.com/ with no port number. example:8443 will still work and no redirect will take place... unless you specifically make arrangements for that. We can do that later if you really want to. Let's get the other things working, first. -chris On Thursday, May 9, 2024, Christopher Schultz wrote: Lavanya, On 5/9/24 02:58, lavanya tech wrote: Just giving background again of this topic again. 1) The application team who is working they wanted to access the url https://server.lbg.com:8443/towl —> which should redirect or point to https://example.lbg.com Is that a typo? You want specifically https://server.lbg.com/towl and https://example.lbg.com/ to point to your application? — It’s not the Typo the requirements are still the same. Okay. Do server and example both resolve to the same IP? 2) Hence I added firewall rule to redirect port 443 to 8443. And the url https://example.lbg.com started working but its pointing to https://server.lbg.com:8443 indeed and not https://server.lbg.com:8443/to wl But then they wanted the point 1 to have it. If I understood correctly. So basically to achieve this we wanted a reverse proxy setup ? I didnot define any additional host in server.xml file on just left to default to local host. Here's what you have to do in order to support this odd configuration. 1. Configure your firewall to route port 443 -> 8443. I suspect this is already done. 2. Deploy Tomcat on server.lbg.com with a on port 8443. This is the default, so there shouldn't be anything to do. I suspect this is already done. You should set proxyPort="443" and proxyName=" example.lbg.com" in your . This will ensure that any URLs generated by Tomcat or your application will point to https://example.lbg.com/ and not to server.lbg.com or have a port number or whatever. 3. Re-name your application directory or WAR file from towl -> ROOT (upper case is important). So if you have tomcat/webapps/towl re-name that to tomcat/webapps/ROOT or if you have tomcat/webapps/towl.war re-name that to tomcat/webapps/ROOT.war. The last thing to do is get /towl to re-direct to /. There are a few ways of doing that. 4a. Configure your application (now called ROOT and deployed on / and not /towl anymore) to handle the /towl URL and specifically redirect this back to /. This is oddly specific and has the application trying to redirect to itself which is weird. 4b. Create a new application called towl or towl.war which will be deployed on /towl and have THAT redirect to /. I think this is cleaner because you can call the application anything you'd like and it will still work. You don't have to match URL patterns yourself, you just re-name the WAR file if you suddenly want to use /towl2 instead of /towl. There are several ways to redirect. 5a. Use the rewrite valve and map /(*) to (global redirect) /\1. A few notes: (1) the (*) means "capture this string" and \1 means "put the string back. This allows you to redirect /towl/foo/bar to /foo/bar instead of losing the /foo/bar. This syntax may not be perfect, adapt it to your needs. (2) Remember that the towl application is deployed on /towl so you don't want to redirect /towl/foo/bar you only want redirect /foo/bar since the URL will be relative to the current context (/towl). Got that? Finally, (3) you need to use a global redirect that does *NOT* redirect back to the /towl application. Normally, if you redirect to /foo you'll get an application-relative redirect from something like a rewrite valve/filter/whatever. Take care to redirect relative to the SERVER and not to the application. 5b. Write your own servlet to do a specific redirect. I hope that helps, -chris On Wednesday, May 8, 2024, Christopher Schultz < ch...@christopherschultz.net> wrote: Lavanya, On 5/8/24 06:48, lavanya tech wrote: I figured out how I can it make it work with 443. Now the URls are working. I added iptables route 443 to 8443 and it started working. nslookup example.lbg.com Non-authoritative answer: Name:server.lbg.com Address: 192.168.200.105 Aliases: example.lbg.com I have some application towl running with apache tomcat. I have the below URLs working. https://server.lbg.com:8443/towl https://server.lbg.com https://example.lbg.com https://example.lbg.com/towl Now i wanted to disable the url https://example.lbg.com/towl and https://server.lbg.com and
Re: Regarding Tomcat url redirection
Hi Chris, Thank you so much for your explanation. I will try these options. Do server and example both resolve to the same IP? -yes So I need follow both 4a/b and 5a/b steps here or any of them ? If I setup exactly by using below steps , then I should access both the urls right ? https://server.lbg.com:8443/towl and https://example.lbg.com I will configure and if I face any issues I will write to you. Thanks, Lavanya On Thursday, May 9, 2024, Christopher Schultz wrote: > Lavanya, > > On 5/9/24 02:58, lavanya tech wrote: > >> Just giving background again of this topic again. >> >> 1) The application team who is working they wanted to access the url >> https://server.lbg.com:8443/towl —> which should redirect or point to >> https://example.lbg.com >> >> Is that a typo? You want specifically https://server.lbg.com/towl and >> https://example.lbg.com/ to point to your application? >>— It’s not the Typo the requirements are still the same. >> > > Okay. > > Do server and example both resolve to the same IP? > > 2) Hence I added firewall rule to redirect port 443 to 8443. And the url >> https://example.lbg.com started working but its pointing to >> https://server.lbg.com:8443 indeed and not https://server.lbg.com:8443/to >> wl >> >> But then they wanted the point 1 to have it. If I understood correctly. So >> basically to achieve this we wanted a reverse proxy setup ? >> >> I didnot define any additional host in server.xml file on just left to >> default to local host. >> > > Here's what you have to do in order to support this odd configuration. > > 1. Configure your firewall to route port 443 -> 8443. I suspect this is > already done. > > 2. Deploy Tomcat on server.lbg.com with a on port 8443. This > is the default, so there shouldn't be anything to do. I suspect this is > already done. You should set proxyPort="443" and proxyName=" > example.lbg.com" in your . This will ensure that any URLs > generated by Tomcat or your application will point to > https://example.lbg.com/ and not to server.lbg.com or have a port number > or whatever. > > 3. Re-name your application directory or WAR file from towl -> ROOT (upper > case is important). So if you have tomcat/webapps/towl re-name that to > tomcat/webapps/ROOT or if you have tomcat/webapps/towl.war re-name that to > tomcat/webapps/ROOT.war. > > The last thing to do is get /towl to re-direct to /. There are a few ways > of doing that. > > 4a. Configure your application (now called ROOT and deployed on / and not > /towl anymore) to handle the /towl URL and specifically redirect this back > to /. This is oddly specific and has the application trying to redirect to > itself which is weird. > > 4b. Create a new application called towl or towl.war which will be > deployed on /towl and have THAT redirect to /. I think this is cleaner > because you can call the application anything you'd like and it will still > work. You don't have to match URL patterns yourself, you just re-name the > WAR file if you suddenly want to use /towl2 instead of /towl. > > There are several ways to redirect. > > 5a. Use the rewrite valve and map /(*) to (global redirect) /\1. A few > notes: (1) the (*) means "capture this string" and \1 means "put the string > back. This allows you to redirect /towl/foo/bar to /foo/bar instead of > losing the /foo/bar. This syntax may not be perfect, adapt it to your > needs. (2) Remember that the towl application is deployed on /towl so you > don't want to redirect /towl/foo/bar you only want redirect /foo/bar since > the URL will be relative to the current context (/towl). Got that? Finally, > (3) you need to use a global redirect that does *NOT* redirect back to the > /towl application. Normally, if you redirect to /foo you'll get an > application-relative redirect from something like a rewrite > valve/filter/whatever. Take care to redirect relative to the SERVER and not > to the application. > > 5b. Write your own servlet to do a specific redirect. > > I hope that helps, > -chris > > On Wednesday, May 8, 2024, Christopher Schultz < >> ch...@christopherschultz.net> >> wrote: >> >> Lavanya, >>> >>> On 5/8/24 06:48, lavanya tech wrote: >>> >>> I figured out how I can it make it work with 443. Now the URls are working. I added iptables route 443 to 8443 and it started working. nslookup example.lbg.com Non-authoritative answer: Name:server.lbg.com Address: 192.168.200.105 Aliases: example.lbg.com I have some application towl running with apache tomcat. I have the below URLs working. https://server.lbg.com:8443/towl https://server.lbg.com https://example.lbg.com https://example.lbg.com/towl Now i wanted to disable the url https://example.lbg.com/towl and https://server.lbg.com and access only the other remaining two. >>> >> >> >>> I would *highly* recommend that you pick either /towl or / and not try
Re: FileUpload class not working with Tomcat 10.1
Mark and Chuck, On 5/9/24 09:35, Chuck Caldarale wrote: You need the web.xml entries because you have extra configuration items (the settings) that aren’t part of the default JSP servlet definition. +1 If you didn't need to upload files to your JSP, you wouldn't have needed any of this in your web.xml file. It's very weird to do this kind of logic in a JSP. I *highly* recommend that you split your JSP into at least two pieces: 1. A servlet that handles the upload, produces no output, and handles error conditions gracefully. It then forwards or redirects (as appropriate) to the page you want to display post-upload. You will need to map this servlet in web.xml, but it's less-stupid than mapping a JSP to a servlet-name and then mapping that same servlet-name back to a URL pattern which is the same as the JSP's path. I can see why you were saying "I have no idea why this is necessary": it seems useless but you must attach the file-upload metadata to something, and this is how you do it. Note that you didn't have to do it that way. You could have done this: uploadfile /schDistImports.jsp ... uploadfile /schDistImports NOTE: no .jsp extension In your case, the generic name "uploadfile" for a very specific type of upload (schDistImports) might be a mistake, since you might want to upload all kinds of files, such as 1099 forms or whatnot. One called "uploadfile" seems generic when it's not really generic: it's specific to that one workflow. You can use any name you like. You can use any URL pattern you like as well, such as /sch/dist/imports. You don't have to be tied to your filesystem layout. 2. A page template (JSP is fine) that only generates page content. No mapping in web.xml is necessary for this, which is probably what you are used to. -chris - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Regarding Tomcat url redirection
Lavanya, On 5/9/24 02:58, lavanya tech wrote: Just giving background again of this topic again. 1) The application team who is working they wanted to access the url https://server.lbg.com:8443/towl —> which should redirect or point to https://example.lbg.com Is that a typo? You want specifically https://server.lbg.com/towl and https://example.lbg.com/ to point to your application? — It’s not the Typo the requirements are still the same. Okay. Do server and example both resolve to the same IP? 2) Hence I added firewall rule to redirect port 443 to 8443. And the url https://example.lbg.com started working but its pointing to https://server.lbg.com:8443 indeed and not https://server.lbg.com:8443/towl But then they wanted the point 1 to have it. If I understood correctly. So basically to achieve this we wanted a reverse proxy setup ? I didnot define any additional host in server.xml file on just left to default to local host. Here's what you have to do in order to support this odd configuration. 1. Configure your firewall to route port 443 -> 8443. I suspect this is already done. 2. Deploy Tomcat on server.lbg.com with a on port 8443. This is the default, so there shouldn't be anything to do. I suspect this is already done. You should set proxyPort="443" and proxyName="example.lbg.com" in your . This will ensure that any URLs generated by Tomcat or your application will point to https://example.lbg.com/ and not to server.lbg.com or have a port number or whatever. 3. Re-name your application directory or WAR file from towl -> ROOT (upper case is important). So if you have tomcat/webapps/towl re-name that to tomcat/webapps/ROOT or if you have tomcat/webapps/towl.war re-name that to tomcat/webapps/ROOT.war. The last thing to do is get /towl to re-direct to /. There are a few ways of doing that. 4a. Configure your application (now called ROOT and deployed on / and not /towl anymore) to handle the /towl URL and specifically redirect this back to /. This is oddly specific and has the application trying to redirect to itself which is weird. 4b. Create a new application called towl or towl.war which will be deployed on /towl and have THAT redirect to /. I think this is cleaner because you can call the application anything you'd like and it will still work. You don't have to match URL patterns yourself, you just re-name the WAR file if you suddenly want to use /towl2 instead of /towl. There are several ways to redirect. 5a. Use the rewrite valve and map /(*) to (global redirect) /\1. A few notes: (1) the (*) means "capture this string" and \1 means "put the string back. This allows you to redirect /towl/foo/bar to /foo/bar instead of losing the /foo/bar. This syntax may not be perfect, adapt it to your needs. (2) Remember that the towl application is deployed on /towl so you don't want to redirect /towl/foo/bar you only want redirect /foo/bar since the URL will be relative to the current context (/towl). Got that? Finally, (3) you need to use a global redirect that does *NOT* redirect back to the /towl application. Normally, if you redirect to /foo you'll get an application-relative redirect from something like a rewrite valve/filter/whatever. Take care to redirect relative to the SERVER and not to the application. 5b. Write your own servlet to do a specific redirect. I hope that helps, -chris On Wednesday, May 8, 2024, Christopher Schultz wrote: Lavanya, On 5/8/24 06:48, lavanya tech wrote: I figured out how I can it make it work with 443. Now the URls are working. I added iptables route 443 to 8443 and it started working. nslookup example.lbg.com Non-authoritative answer: Name:server.lbg.com Address: 192.168.200.105 Aliases: example.lbg.com I have some application towl running with apache tomcat. I have the below URLs working. https://server.lbg.com:8443/towl https://server.lbg.com https://example.lbg.com https://example.lbg.com/towl Now i wanted to disable the url https://example.lbg.com/towl and https://server.lbg.com and access only the other remaining two. I would *highly* recommend that you pick either /towl or / and not try to do both, unless you want to deploy the application twice (which is fine, just deploy towl.war and ROOT.war as copies of each other). If you try to re-write /towl to / or / to /towl, you'll find you spend the rest of your days tracking-down edge-cases and "fixing" them -- likely making things confusing and, probably, worse. In the end our goal to makesure that the links are not always dead as soon as the towl is moved to a new machine. Can you pelase assit me how to do that? The goal should be that "moving" the application only means changing DNS and everything else works as expected. If you: 1. Deploy the application with a single context (e.g. /towl, which I recommend) 2. Re-direct / to /towl (this requires a reverse-proxy or a ROOT application that does nothing but
Re: FileUpload class not working with Tomcat 10.1
> On May 9, 2024, at 01:25, Mark Foley wrote: > >> Does the JSP need to reference the "program" (servlet?) at all? > The program, as shown above didn'twork at all until I put that servlet > definition on WEB-INF/web.xml, so I suppose the answer is "yes". As to why, I > have not a clue. A reading of the servlet spec might be in order here. Servlets (including JSPs) are selected based on the mapping of the to the . >> When you make a request, Tomcat determines which servlet in your application >> will service the request. If that's a JSP, then the JSP is invoked. A JSP >> just compiles to a servlet, just as if you had written a .java file with a >> class that "extends HttpServlet" or similar. >> >> It's not clear what "the program" is: JSP or servlet? Or something else? > The programs are written in Java/JSP and, yes, Tomcat "compiles" them to > .class -- probably servlets. No probably about it - JSPs are always compiled into servlets. “Program” is too generic a term to be used here - you need to be specific with what you’re talking about: servlets you coded and compiled, or JSPs that Tomcat turns into servlets. It’s hard to figure out exactly what you’re really talking about. > I think I may have figured this out. Here are my two servlet definitions in > WEB-INF/web.xml: > > > uploadfile > /schDistImportResults.jsp > > /tmp > 20848820 > 418018841 > 1048576 > > > >uploadfile > /schDistImportResults.jsp > > > > *upload1099* I presume the asterisks are not actually present in your config. > /1099R-Etrans.jsp > > /tmp > 20848820 > 418018841 > 1048576 > > > >*upload1099* > /1099R-Etrans.jsp > > > In the 2nd definition, Taking Chuck's hint, I changed the servlet-name to > "upload1099". That seemed to work for the 1099R-Etrans.jsp program, but I > haven't been able to test the schDistImportResults.jsp program yet to see if > I broke that one. Why these definitions are needed in web.xml and how all > that works under the hood is, as Chuck said, "magic”. It’s not magic at all - it’s how servlet selection works, as defined in the servlet spec. The “magic” was your expectation that servlets with the same name could co-exist. You need the web.xml entries because you have extra configuration items (the settings) that aren’t part of the default JSP servlet definition. - Chuck
Re: Regarding Tomcat url redirection
Hi Chris, Thanks. Just giving background again of this topic again. 1) The application team who is working they wanted to access the url https://server.lbg.com:8443/towl —> which should redirect or point to https://example.lbg.com Is that a typo? You want specifically https://server.lbg.com/towl and https://example.lbg.com/ to point to your application? — It’s not the Typo the requirements are still the same. 2) Hence I added firewall rule to redirect port 443 to 8443. And the url https://example.lbg.com started working but its pointing to https://server.lbg.com:8443 indeed and not https://server.lbg.com:8443/towl But then they wanted the point 1 to have it. If I understood correctly. So basically to achieve this we wanted a reverse proxy setup ? I didnot define any additional host in server.xml file on just left to default to local host. Thanks, Lavanya On Wednesday, May 8, 2024, Christopher Schultz wrote: > Lavanya, > > On 5/8/24 06:48, lavanya tech wrote: > >> I figured out how I can it make it work with 443. Now the URls are >> working. >> I added iptables route 443 to 8443 and it started working. >> >> nslookup example.lbg.com >> >> Non-authoritative answer: >> Name:server.lbg.com >> Address: 192.168.200.105 >> Aliases: example.lbg.com >> >> >> I have some application towl running with apache tomcat. I have the below >> URLs working. >> >> https://server.lbg.com:8443/towl >> https://server.lbg.com >> https://example.lbg.com >> https://example.lbg.com/towl >> >> >> Now i wanted to disable the url https://example.lbg.com/towl and >> https://server.lbg.com and access only the other remaining two. >> > > > I would *highly* recommend that you pick either /towl or / and not try to > do both, unless you want to deploy the application twice (which is fine, > just deploy towl.war and ROOT.war as copies of each other). If you try to > re-write /towl to / or / to /towl, you'll find you spend the rest of your > days tracking-down edge-cases and "fixing" them -- likely making things > confusing and, probably, worse. > > In the end our goal to makesure that the links are not always dead as soon >> as the towl is moved to a new machine. Can you pelase assit me how to do >> that? >> > > The goal should be that "moving" the application only means changing DNS > and everything else works as expected. > > If you: > > 1. Deploy the application with a single context (e.g. /towl, which I > recommend) > > 2. Re-direct / to /towl (this requires a reverse-proxy or a ROOT > application that does nothing but redirect ; my personal preference) > > 3. Do not define any other than "localhost" and make it the > default. Do not bother with any elements since they are not > necessary. > > Moving the application should only require that you: > > 4. Deploy the same application with the same configuration in the new > location > > 5. Change DNS to point example.lbg.com and server.lbg.com to the new > location of the service > > Hope that helps, > -chris > > On Tue, Apr 30, 2024 at 5:44 PM Christopher Schultz < > ch...@christopherschultz.net> wrote: > > Lavanya, > > On 4/30/24 07:10, lavanya tech wrote: > > Can you tell me how to do the below ? How should I setup Tomcat in > server.xml ? > > > If you want to use port 443 (the default port for HTTPS) then you will > need to change Tomcat to bind to port 443 (if that's allowed on your OS) > or arrange to have port 443 routed to port 8443. You may need additional > configuration in Tomcat (specifically: proxyPort) to avoid having Tomcat > generate URLs with ":8443" in them. > > Looking forward to your reply. > > > If Tomcat is listening on port 8443 then you will need to include that > in your URL, period. If you want to allow URLs without a port number, > you will have to arrange to have something listening on port 443. > > On Windows, Tomcat can listen directly on port 443. On UNIX and > UNIX-like systems, you won't be able to do this without running Tomcat > as root WHICH YOU ABSOLUTELY SHOULD NOT DO. > > There are other ways to get port 443 working, but I'll need to know more > about your environment. The port issue is "easier" than figuring out > whatever is going on with your DNS, aliases, etc. so I would recommend > we fix one thing at a time. > > -chris > > On Mon, Apr 29, 2024 at 2:03 PM lavanya tech > wrote: > > Hi Chris, > > There is no issues with browser, because I tested with different > > browsers > > and it all works fine. I am sure that there is no issue with the > certificate. >Because I was able to establish successful connections with port > > 8443, it > > just doesnot work with out port > >curl https://example.lbg.com/towl > curl: (56) Received HTTP code 504 from proxy after CONNECT > curl: (56) Received HTTP code 504 from proxy after CONNECT > > > If you want to use port 443 (the default port for HTTPS) then you will > need to change Tomcat to bind to port 443 (if that's allowed on your OS) > or arrange to have port
Re: FileUpload class not working with Tomcat 10.1
On 5/7/2024 4:52 PM, Christopher Schultz wrote: Mark, On 5/3/24 12:16, Mark Foley wrote: On 4/23/24 18:44, Chuck Caldarale wrote: uploadfile uploadfile /schDistImportResults.jsp The first servlet is named “uploadfile”. On Apr 23, 2024, at 12:42, Mark Foley wrote: Now I need to add another program to the system that does file uploads. I created another definition in WEB-INF/web.xml following the original: uploadfile uploadfile /1099R-Etrans.jsp This second servlet is also named “uploadfile”. That didn't work so well. Now, any and all programs using the fileupload function launches this 2nd program 1099R-Etrans.jsp. It appears that this second definition replaces the first. You gave them the same names, so the second one wins... What magic were you expecting to differentiate between the two? - Chuck I can easily change the name of the second servlet, but how would the respective jsp programs (schDistImportResults.jsp, 1099R-Etrans.jsp) specify one or the other? The programs do: String contentType = request.getContentType(); if (contentType.startsWith("multipart/form-data;")) { Part fileUpload = request.getPart("taxResults"); // for schDistImportResults.jsp // or Part fileUpload = request.getPart("vendor1099-MISC"); // for 1099R-Etrans.jsp InputStream inFile = fileUpload.getInputStream(); : } That's it. There is nothing in the program that specifies a servlet name. My initial servlet definition (for schDistImportResults.jsp) was based on the XML suggestion from Christopher Schultz back in November, 2023. Since only the one jsp program was involved, there was no discussion of how to specify more than one program in web.xml. So, I can (and will) give the servlets different names in web.xml, but how does the jsp program select the one for its use? Does the JSP need to reference the "program" (servlet?) at all? The program, as shown above didn'twork at all until I put that servlet definition on WEB-INF/web.xml, so I suppose the answer is "yes". As to why, I have not a clue. When you make a request, Tomcat determines which servlet in your application will service the request. If that's a JSP, then the JSP is invoked. A JSP just compiles to a servlet, just as if you had written a .java file with a class that "extends HttpServlet" or similar. It's not clear what "the program" is: JSP or servlet? Or something else? The programs are written in Java/JSP and, yes, Tomcat "compiles" them to .class -- probably servlets. It's also not clear how "the program" would or should reference a servlet name. Maybe you can explain (again)? -chris I think I may have figured this out. Here are my two servlet definitions in WEB-INF/web.xml: uploadfile /schDistImportResults.jsp /tmp 20848820 418018841 1048576 uploadfile /schDistImportResults.jsp *upload1099* /1099R-Etrans.jsp /tmp 20848820 418018841 1048576 *upload1099* /1099R-Etrans.jsp In the 2nd definition, Taking Chuck's hint, I changed the servlet-name to "upload1099". That seemed to work for the 1099R-Etrans.jsp program, but I haven't been able to test the schDistImportResults.jsp program yet to see if I broke that one. Why these definitions are needed in web.xml and how all that works under the hood is, as Chuck said, "magic".