Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Alternative to getPathTranslated?

 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet filter that uses getPathTranslated like this:



On some servers this works just fine, but on one I just tried (Sun's Java App Server Standard Edition...the Platform Edition works BTW), the url is null!

So, is there another way to get this same information? In short, what I need to do is find out where the user is trying to get to (what JSP).

Thanks!
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that getPathInfo should give me what I need.

It looks like although Sun's Java System Applicaiton Server Platform Edition expands the WAR file, the Standard Edition does not, so that is why the getPathTranslated was returning null. The getPathInfo should (I think ) get around this problem and return what I need.
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Darrin Smith:
I think that getPathInfo should give me what I need.

It looks like although Sun's Java System Applicaiton Server Platform Edition expands the WAR file, the Standard Edition does not, so that is why the getPathTranslated was returning null. The getPathInfo should (I think ) get around this problem and return what I need.



Well, that doesn't work as getPathInfo returns null too.

So, besides expanding the WAR, how else can I get around this? In other words, how can I get the name of the JSP that is currently being requested without using getPathTranslated?

Thanks!
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could it be that the URL used to access your page didn't include the welcome page?

I.E: http://localhost:8080 will render the index.html or index.jsp page.
Because it was not in the URL, getPathTranslated will return null.
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
Could it be that the URL used to access your page didn't include the welcome page?

I.E: http://localhost:8080 will render the index.html or index.jsp page.
Because it was not in the URL, getPathTranslated will return null.


Hi Ben,

Well, if you run the exact same code on the Platform Edition you see Login.jsp being returned at the end of the getPathTranslated string. If you then run it using the Standard Edition, then it is null.

I've dug around quite a bit and I'm fairly sure that the reason is due to the fact that the WAR file doesn't get expanded in the Standard Edition.

I was hoping that there would be another mechanism to get this same information (the value has to be somewhere!) that would work even if the WAR stays compacted.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since path info has nothing to do with the file system, it should not matter whether your war file is expanded or not. Any container that does not correctly return the value should be considered broken.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if one version is using sendRedirect to get to your welcome file and the other is using a server side forward.

With the redirect, you would have a completely new request, complete with the filename of the welcome file.
With the server side forward the URL would remain the same.

On the version that returns null, have you tried typing the entire URL into your browser's address window?
I.E. http://localhost/yourContextPath/Welcome.jsp
instead of just http://localhost/yourContextPath
?

This will also be easy to see if you hit it from FireFox with the LiveHttpHeaders installed.
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you run snoop.jsp on both servers and provide result? I couldn't find a clear spec (so appreciated any help pointing to) what should be returned for getPathInfo when jsp page requested. I decided to return jsp page name, like /welcome.jsp. However some other server return null in getPathInfo, but return /welcome.jsp for getServletName().
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by dema rogatkin:
I couldn't find a clear spec (so appreciated any help pointing to) what should be returned for getPathInfo when jsp page requested. I decided to return jsp page name, like /welcome.jsp. However some other server return null in getPathInfo, but return /welcome.jsp for getServletName().


The following link describes the cgi PATH_TRANSLATED, and PATH_INFO variables and thus their servlet conterparts with examples:
http://cgi-spec.golux.com/draft-coar-cgi-v11-03-clean.html#6.1.6
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An excellent reference. So we should just clarify what's script name in case of JSP. Is it JSP page name? So in this case empty result for path info is excepted. Is it JSP servlet name? In this case you may expect a return as jsp page name. So, move this topic to JSP forum. I hope those guys will help us.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I would say that this forum is the most appropriate location for this question.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe there is a better way to accomplish your goal.
What, exactly, are you trying to do?
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off thanks to everyone for helping out.

Now let me explain a little better exactly what it is that needs to be done and why it isn't working.

What I have is a filter that inspects all incoming requests to see what page is being requested. All I want to do is to get the name of the requested page.

Now, there is no doubt as to what the page is when the application first starts up as the welcome is Login.jsp:




Running on either Tomcat or Sun Java Application Server Platform Edition (which I think uses Tomcat) I was able to retrieve the page names in my filter like this:



When I try to run this same code (same WAR file) on Sun's Standard Edition the url was null (in other words, getPathTranslated was returning null).

I poked around and found that the reason it is null is because the Standard Edition does not expand the WAR file while the Platform Edition does, and according to the specification, the application server is allowed to return null in that instance (I verified this with Craig M...it is the way it is allowed to be).

So, my question is, what can I use in place of getPathTranslated that will work even if the WAR file is not expanded?
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you just get entire URI and then analyze parts you may need? Here is my snoop.jsp:
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[/qb]<hr></blockquote>

If I could get the entire URI, then that is what I would do, but I can't seem to be able to do that on the Standard Edition App Server:

[#|2006-01-17T12:00:42.552-0600|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=23;|
URL from getPathTranslated: C:\Documents and Settings\dsmith\My Documents\Creator\Projects\MyApp\build\web\Login.jsp|#]

[#|2006-01-17T12:00:42.552-0600|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=23;|
URL from getPathInfo: /Login.jsp|#]

[#|2006-01-17T12:00:42.552-0600|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=23;|
URL from getRequestURI: /MyApp/|#]

[#|2006-01-17T12:00:42.552-0600|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=23;|
URL from getServletPath: /faces|#]

[#|2006-01-17T12:00:42.552-0600|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=23;|
URL from getServletContext().getRealPath(hreq.getServletPath(): C:\Documents and Settings\dsmith\My Documents\Creator\Projects\MyApp\build\web\faces|#]


Here is a run from the EXACT same WAR deployed onto a Standard Edition app server:

[#|2006-01-17T12:56:39.806-0600|INFO|sun-appserver-ee8.1|javax.enterprise.system.stream.out|_ThreadID=14;|
URL from getPathTranslated: null|#]

[#|2006-01-17T12:56:39.806-0600|INFO|sun-appserver-ee8.1|javax.enterprise.system.stream.out|_ThreadID=14;|
URL from getPathInfo: null|#]

[#|2006-01-17T12:56:39.806-0600|INFO|sun-appserver-ee8.1|javax.enterprise.system.stream.out|_ThreadID=14;|
URL from getRequestURI: /MyApp/faces|#]

[#|2006-01-17T12:56:39.806-0600|INFO|sun-appserver-ee8.1|javax.enterprise.system.stream.out|_ThreadID=14;|
URL from getServletPath: /faces|#]

[#|2006-01-17T12:56:39.806-0600|INFO|sun-appserver-ee8.1|javax.enterprise.system.stream.out|_ThreadID=14;|
URL from getServletContext().getRealPath(hreq.getServletPath(): E:\Sun\ApplicationServer\domains\domain1\applications\j2ee-modules\MyApp\faces|#]


Notice that there are different return values for getPathTranslated, getPathInfo, and getRequestURI (which I think that you were suggesing). On the Standard Edition, I never was able to get Login.jsp back either by itself or as part of the larger URI!

So, if I could get the URI, then I could use it, but there doesn't seem to be a way to do that on the Standard Edition!
[ January 17, 2006: Message edited by: Darrin Smith ]
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wild guess, can your filter be already filtered by some other filter? I guess Sun's app server is open source, so you can look inside to figure.
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like this is a bug. Sun will be putting in a fix.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic