3

In one of my servlets, I invoke RequestDispatcher.forward() call to a static resource somewhere under WEB-INF folder:

request
    .getRequestDispatcher( "/WEB-INF/some/path/image.gif" )
        .forward( request, response );

Navigating to this servlet works fine under Tomcat, Jetty et al., but does not work in WebSphere 7. The error I get (both in the browser and in the server logs) is

Error 403: SRVE0190E: File not found: /WEB-INF/some/path/image.gif

Initially I assumed that WebSphere may need some specific configuration to allow internal forwarding to resources under WEB-INF, but I failed to google anything useful.

Any ideas why can this happen?

Thanks in advance!

Anton
  • 1,560
  • 18
  • 29
  • 1
    Check your deployment. Is that file actually there? – Sotirios Delimanolis Dec 04 '13 at 14:45
  • @SotiriosDelimanolis Yes. The same WAR works under other servers... – Anton Dec 04 '13 at 14:46
  • Forward to a resource inside WEB-INF is possible. I think it is a spec of Java EE because it is internal call. 403 means the resource exists but it is forbidden, inaccessible. Something wrong with WebSphere. Did you try to deploy application folder only? NOT .WAR file. – LHA Dec 04 '13 at 15:04
  • @Loc I guess something is wrong with the WebSphere, especially if this works in another servers :) Yet, this happens at customer's site and easily reproducible in my lab... Anyway, how do I "deploy application folder only", please? I admit I'm pretty new to WebSphere :( – Anton Dec 04 '13 at 15:09
  • how do I "deploy application folder only"? This is new to me too. I can do it in Tomcat. Please try to put your application into WAS_INSTALL_DIR/runtime/installapps/YOUR APPLICATION. Not tested. – LHA Dec 04 '13 at 15:11
  • So it sounds like WebSphere is taking a more restrictive view of serving up content from WEB-INF than those other servers are. Whether that's something "wrong" or within the realm of interpretation, I have no idea. And whether WebSphere has an override for that behavior, I also have no idea. Did you try the WebSphere forum? https://www.ibm.com/developerworks/community/forums/html/forum?id=11111111-0000-0000-0000-000000000266 – dbreaux Dec 04 '13 at 15:29
  • @dbreaux Thank you for the link, just asked it there also. – Anton Dec 04 '13 at 15:52

2 Answers2

6

It appears that one should set exposeWebInfOnDispatch property to true in order to make WEB-INF accessible for servlets in WebSphere. I got this answer from WebSphere forum.


In WebSphere 7 administration console,

  1. Go to "Servers" => "Server Types" => "WebSphere application servers" on the left
  2. Choose proper server on the list on the main part of the page
  3. Click on "Container Settings" => "Web Container Settings" => "Web container"
  4. Go to "Custom properties" on the right
  5. Add new property:

    • Name: exposeWebInfOnDispatch
    • Value: true
Anton
  • 1,560
  • 18
  • 29
  • Thanks for updating here with what was discovered. Glad the forum produced the solution. – dbreaux Dec 06 '13 at 17:33
  • Where did you set this option? Is it something that can be setup in a deployment descriptor? – Cypher Jul 16 '15 at 17:05
  • @Cypher Just added the detailed steps to the answer. Not sure you can do that in deployment descriptor. I'm in no way WebSphere expert, though... – Anton Jul 19 '15 at 08:19
0

You are getting HTTP 403, which means forbidden. Try moving out image.gif out of WEB-INF. That might work

Sajith Silva
  • 823
  • 1
  • 13
  • 24
  • I guess it will, but it is not the point. I don't want the file to be directly accessible from the net. – Anton Dec 04 '13 at 15:02
  • perhaps you could read this as a resource, and then write the content back to response with correct http content type, rather than trying to do request forwarding – Sajith Silva Dec 04 '13 at 15:06
  • Maybe, and I can think about other workarounds also. However, I'm trying to understand what happens here and why. – Anton Dec 04 '13 at 15:10