Setting up a URL resource on WebSphere Application Server 7.0?
Asked Answered
G

1

6

I need to setup a URL resource in WebSphere and is following this tutorial. However, the tutorial requires the modification of WebSphere's web.xml and ibm-web-bnd.xml using WebSphere Studio. I don't have a WebSphere Studio so I need to modify those files manually using a text editor. I tried to "search" for the 2 files but the "search results" are so many that I don't know which one is the right file.

Where can I find the 2 files? Also what value do I need to set for the resource-ref's id? I notice that WebSphere Studio doesn't have any text field for setting the resource-ref's but it has a value on its code view.

Thank you!

Gaskin answered 6/12, 2012 at 6:56 Comment(0)
M
17

web.xml is a standard JavaEE file and its structure is well-documented in the Servlet specification. In web.xml, you declare the URL as it is known within your local JNDI namespace (java:comp/env).

web.xml should be located inside WEB-INF, underneath your WAR project structure. If you are using an IDE (such as Eclipse) to create Web projects, this file should already be created for you (unless you use Servlet Specification 2.5 and up - Servlet Specification 2.5 is included with JavaEE 5.0 - where deployment descriptors are optional).

ibm-web-bnd.xml is a WebSphere-specific file. It contains the binding of declared artifacts (such as a URL definition) into a real artifacts. You should refer to IBM's documentation in order to figure out the format of that file.

The ibm-web-bnd.xml file should be located in the same directory as web.xml.

The id attribute of resource-ref can be set to any value you like, as long as it is cross-referenced by a matching id attribute inside ibm-web-bnd.xml. That's how WebSphere can correlate definitions in ibm-web-bnd.xml to definitions in web.xml. The random string you see in the tutorial are created by RAD or WSAD; you can place any identifier there.

EDIT (added instructions)

In a nutshell, the process is this:

  1. In web.xml, you define the local JNDI name. That would be the name by which your Java code is referring to the URL. For example, myWebsiteUrl. Your code will have to perform a JNDI lookup on java:comp/env/myWebsiteUrl. The definition is along these lines:

    <resource-env-ref>
        <resource-env-ref-name>myWebsiteUrl</resource-env-ref-name>
        <resource-env-ref-type>java.net.URL</resource-env-ref-type>
    </resource-env-ref>
    
  2. In WebSphere itself, add a URL definition. The key there is the JNDI name in WebSphere's JNDI tree by which the URL will be known. You can set any value there, although it is recommended (by convention) that you prefix it with url/. For example: url/test.

  3. In ibm-web-bnd.xml, you need to bind myWebsiteUrl (looked-up by your application) to url/test (which is the JNDI name by which WebSphere knows the URL). The definition will be along the lines of:

    <resource-env-ref name="myWebsiteUrl" binding-name="url/test"/>
    

Step 3 is not required. If ibm-web-bnd.xml doesn't exist at deployment time, then the GUI-based deployment flow (used when you deploy applications through the WAS administration console) will prompt you for the binding values. (If you are deploying using scripting, you can still omit the ibm-web-bnd.xml file as long as you specify the bindings in a different way, but that's beyond the scope of this answer. Read the IBM documentation about strategy files and AdminApp.installApplication)

Note: as long as you use JavaEE 5.0 and up, you don't need the id attribute in the definitions. The article you're reading, by the way, is extremely outdated.

Mangosteen answered 6/12, 2012 at 7:27 Comment(8)
Hi, Isaac. Thanks for your reply! Can you teach me on how to setup WebSphere for JNDI use? I have no background to JNDI and this is my first time creating a URL resource so I think I misunderstood something.Gaskin
Based from my understanding, to use JNDI, I need to setup a URL resource on WebSphere wherein I need to declare a URL in key value pair (for example, url1 = website.com/url1). The key will be use in the web application wherein it can be reference in java:comp/env/key format. From what I understood in the tutorial, I need to set WebSphere's web.xml and ibm-web-bnd.xml and not the WAR's web.xml and ibm-web-bnd.xml. Or does the tutorial refers to the XML of my WAR file? If so, then where can I set the value of my URLs on WebSphere?Gaskin
Hi! Thanks again! Will test it out. :D Also thanks for pointing out that it was extremely outdated. I didn't notice that it was for WAS v5 but I have no choice since it was the most decent tutorial I found. Is there any difference with how JNDI is setup for WAS v5 vs WAS v7?Gaskin
If you're asking about whether there's a difference in how URL's are defined within the WAS administration console, then no. It's very similar, you should be able to figure out quickly.Mangosteen
One minor inaccuracy - deployment descriptor-less web applications are only possible since Java EE 6.Mucin
Step 3 is not required. You don't have to include an ibm-web-bnd.xml file at all in your WAR, and if you don't, you can just map the web.xml resource to the WAS-defined one at deployment time.Packard
@JacekLaskowski - I'm pretty sure that Servlet Specification 2.5 is included with JavaEE 5.0. Servlet Spec 2.5 introduced annotations.Mangosteen
Thanks, guys! :D Yes, I don't think the ibm-web-bnd.xml is necessary. My friend was able to run his web application even without the ibm-web-bnd.xml. The only difference is he's accessing a JDBC resource instead of URL. But he's using Spring so I don't if that makes a difference.Gaskin

© 2022 - 2024 — McMap. All rights reserved.