⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch07s22.html

📁 详细介绍了jboss3.0的配置等
💻 HTML
字号:
<html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
   <title>Web container configuration : use of jboss-web.xml</title><link rel="stylesheet" href="styles.css" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/styles.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets Vimages/callouts/"><link rel="home" href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html" title="JBoss 3.0 Documentation"><link rel="up" href="ch07.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07.html" title="Chapter 7. Advanced container configuration : use of jboss.xml"><link rel="previous" href="ch07s16.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07s16.html" title="Container configuration"><link rel="next" href="ch08.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch08.html" title="Chapter 8. JBoss and JMS"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="jboss.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/jboss.gif" border="0"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch07.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch07s16.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07s16.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch08.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch08.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table><div class="section"><a name="web-container.config"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="web-container.config"></a>Web container configuration : use of jboss-web.xml</h2></div></div><p>Author:<span class="author">Scott Stark</span>
		<tt>&lt;<a href="mailto:Scott.Stark@jboss.org">Scott.Stark@jboss.org</a>&gt;</tt>
	</p><div class="section"><a name="d0e2872"></a><div class="titlepage"><div><h3 class="title"><a name="d0e2872"></a>What is jboss-web.xml?</h3></div></div><p>To deploy your web application, you have to specify (nearly) everything about its
setup using the standard web.xml descriptor. This file is bundled in the war
archive in the WEB-INF directory.
The content and syntax of this file in specified in the servlet2.2 specification.</p><p>An important point is that the specification does not allow you to add 
vendor-specific configuration 
in this file. While the web.xml is sufficient for most applications, there 
may be cases where
you want to add JBoss-specific information in your deployment descriptor. This 
can be done by providing another file named jboss-web.xml in the WEB-INF directory.</p><p>The following sections will cover most common uses of the jboss-web.xml file.
If you want to know all the details, you can get the DTD for jboss-web.dtd in the
<a href="javascript:if(confirm('http://www.jboss.org/doco_files/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.jboss.org/doco_files/'" tppabs="http://www.jboss.org/doco_files/" target="_top">file section</a> of the manual. A graphical
view of the DTD is given in <a href="ch07s22.html#jboss-web.dtd" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07s22.html#jboss-web.dtd" title="Figure 7.2. The jboss-web.xml DTD">Figure 7.2</a>
		</p><div class="figure"><p><a name="jboss-web.dtd"></a><b>Figure 7.2. The jboss-web.xml DTD</b></p><div class="mediaobject"><img src="jboss_web_dtd.jpg" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/jboss_web_dtd.jpg"></div></div></div><div class="section"><a name="d0e2892"></a><div class="titlepage"><div><h3 class="title"><a name="d0e2892"></a>Declaring Resource References</h3></div></div><p>Resource references are links to resource factory bindings. They
allow a servlet/JSP page developer to define a name relative to the ENC that
does not depend on the deployment time binding of the resource. The jboss-web.xml
descriptor maps from the developer defined resource name to the actual JNDI
binding of the resource factory as it was configured in the deployment environment.
An example web.xml descriptor that references JDBC, Mail and JMS resources and the
corresponding jboss-web.xml descriptor is:
		</p><pre class="programlisting">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"&gt;

&lt;web-app&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;AServlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;AServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;

    &lt;!-- JDBC DataSources (java:comp/env/jdbc) --&gt;
    &lt;resource-ref&gt;
        &lt;description&gt;The default DS&lt;/description&gt;
        &lt;res-ref-name&gt;jdbc/DefaultDS&lt;/res-ref-name&gt;
        &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
        &lt;res-auth&gt;Container&lt;/res-auth&gt;
    &lt;/resource-ref&gt;
    &lt;!-- JavaMail Connection Factories (java:comp/env/mail) --&gt;
    &lt;resource-ref&gt;
        &lt;description&gt;Default Mail&lt;/description&gt;
        &lt;res-ref-name&gt;mail/DefaultMail&lt;/res-ref-name&gt;
        &lt;res-type&gt;javax.mail.Session&lt;/res-type&gt;
        &lt;res-auth&gt;Container&lt;/res-auth&gt;
    &lt;/resource-ref&gt;
    &lt;!-- JMS Connection Factories (java:comp/env/jms) --&gt;
    &lt;resource-ref&gt;
        &lt;description&gt;Default QueueFactory&lt;/description&gt;
        &lt;res-ref-name&gt;jms/QueFactory&lt;/res-ref-name&gt;
        &lt;res-type&gt;javax.jms.QueueConnectionFactory&lt;/res-type&gt;
        &lt;res-auth&gt;Container&lt;/res-auth&gt;
    &lt;/resource-ref&gt;

&lt;/web-app&gt;

</pre><pre class="programlisting">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;jboss-web&gt;
    &lt;resource-ref&gt;
        &lt;res-ref-name&gt;jdbc/DefaultDS&lt;/res-ref-name&gt;
        &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
        &lt;jndi-name&gt;java:/DefaultDS&lt;/jndi-name&gt;
    &lt;/resource-ref&gt;
    &lt;resource-ref&gt;
        &lt;res-ref-name&gt;mail/DefaultMail&lt;/res-ref-name&gt;
        &lt;res-type&gt;javax.mail.Session&lt;/res-type&gt;
        &lt;jndi-name&gt;java:/Mail&lt;/jndi-name&gt;
    &lt;/resource-ref&gt;
    &lt;resource-ref&gt;
        &lt;res-ref-name&gt;jms/QueFactory&lt;/res-ref-name&gt;
        &lt;res-type&gt;javax.jms.QueueConnectionFactory&lt;/res-type&gt;
        &lt;jndi-name&gt;QueueConnectionFactory&lt;/jndi-name&gt;
    &lt;/resource-ref&gt;
&lt;/jboss-web&gt;
</pre></div><div class="section"><a name="d0e2901"></a><div class="titlepage"><div><h3 class="title"><a name="d0e2901"></a>Declaring an EJB reference</h3></div></div><p>An EJB reference (see servlet2.2 specification, 9.9, p45) is when a servlet 
wants to call methods on a bean B. This call will look like this:.</p><pre class="programlisting">
public class AServlet extends HttpServlet
{
   ...
   protected void service(HttpServletRequest req, HttpServletResponse res)
      throws ServletException, IOException
   {
      ...
      InitialContext ctx = new InitialContext();  
      BHome home = (BHome) ctx.lookup("java:comp/env/ejb/myBean");
      B bean = home.create(pk);
      ...
    }
}</pre><p>To be allowed this call, the servlet must declare a reference to
the ejb its using in the its deployment descriptor. This is done by an &lt;ejb-ref&gt;
tag in the web.xml file. Two types of references exist; internal and external.
</p><div class="section"><a name="d0e2910"></a><div class="titlepage"><div><h4 class="title"><a name="d0e2910"></a>Internal EJB reference</h4></div></div><p>An EJB reference is called internal when the servlet is in the same
application unit as the bean B. This means that the servlet and ejb is 
physically packaged in the same ear. In this case, you must provide the &lt;ejb-link&gt; tag, and its value must 
match the &lt;ejb-name&gt; of bean B. You don't have to provide anything 
in the jboss-web.xml file. Your web.xml 
file will look like this: 
</p><pre class="programlisting">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;AServlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;AServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;

    &lt;ejb-ref&gt;
        &lt;ejb-ref-name&gt;ejb/BHome&lt;/ejb-ref-name&gt;
        &lt;ejb-ref-type&gt;Session&lt;/ejb-ref-type&gt;
        &lt;home&gt;BHome&lt;/home&gt;
        &lt;remote&gt;B&lt;/remote&gt;
        &lt;ejb-link&gt;Bean B&lt;/ejb-link&gt;
    &lt;/ejb-ref&gt;

&lt;/web-app&gt;

</pre><p>Note that this only works if the ejb is using the default binding
of its BHome interface which means the ejb-jar in which B is deployed does not use
a jboss.xml descriptor to change the default binding. If B does change the default
location of its JNDI binding, then the bean needs to be treated as an external bean
as described in the next section.
               </p></div><div class="section"><a name="d0e2919"></a><div class="titlepage"><div><h4 class="title"><a name="d0e2919"></a>External EJB reference</h4></div></div><p>An EJB reference is called external when the bean B comes from another
application unit, which may even be deployed on another server. It also refers to
non-standard bindings of EJBs into JNDI in the same application unit.
In this case, you cannot rely on the 
standard &lt;ejb-link&gt; tag in web.xml since there the beans are 
not covered in the same file. Instead, you must
provide the full JNDI name of the bean B in jboss-web.xml. A full 
name is of the form:
</p><p>protocol://host:1234/name/in/other/server
Note that the &lt;ejb-ref-name&gt; tags in the 2 xml files must match. 
</p><p>Here is an example web.xml and jboss-web.xml with external EJB
references:</p><pre class="programlisting">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;web-app&gt;
    &lt;servlet&gt;
        &lt;servlet-name&gt;AServlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;AServlet&lt;/servlet-class&gt;
    &lt;/servlet&gt;

    &lt;ejb-ref&gt;
        &lt;ejb-ref-name&gt;ejb/BHome&lt;/ejb-ref-name&gt;
        &lt;ejb-ref-type&gt;Session&lt;/ejb-ref-type&gt;
        &lt;home&gt;BHome&lt;/home&gt;
        &lt;remote&gt;B&lt;/remote&gt;
    &lt;/ejb-ref&gt;
    &lt;ejb-ref&gt;
        &lt;ejb-ref-name&gt;ejb/RemoteBHome&lt;/ejb-ref-name&gt;
        &lt;ejb-ref-type&gt;Session&lt;/ejb-ref-type&gt;
        &lt;home&gt;BHome&lt;/home&gt;
        &lt;remote&gt;B&lt;/remote&gt;
    &lt;/ejb-ref&gt;
&lt;/web-app&gt;
</pre><pre class="programlisting">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;jboss-web&gt;
    &lt;!-- A reference to an EJB in the same server with a custom JNDI binding --&gt;
    &lt;ejb-ref&gt;
        &lt;ejb-ref-name&gt;ejb/BHome&lt;/ejb-ref-name&gt;
        &lt;jndi-name&gt;someapp/ejbs/beanB&lt;/jndi-name&gt;
    &lt;/ejb-ref&gt;
    &lt;!-- A reference to an EJB in an external server --&gt;
    &lt;ejb-ref&gt;
        &lt;ejb-ref-name&gt;ejb/RemoteBHome&lt;/ejb-ref-name&gt;
        &lt;jndi-name&gt;jnp://otherserver/application/beanB&lt;/jndi-name&gt;
    &lt;/ejb-ref&gt;
&lt;/jboss-web&gt;

</pre><p>IMPORTANT NOTE: this will tell jboss where to look for bean B. You also have 
to tell jboss what bean B is: in case of an external ejb-reference to another application be
sure to include bean B's home and remote interface in servlet war. </p></div></div><div class="section"><a name="d0e2934"></a><div class="titlepage"><div><h3 class="title"><a name="d0e2934"></a>Declaring the Security Domain</h3></div></div><p>The final element in the jboss-web.xml descriptor is the security-domain.
This defines the JNDI name of the security manager implementation that should be
used to perform authentication and authorization of web clients. This element only
works with web containers that have been integrated into the JBoss server using
the org.jboss.web.AbstractWebContainer integration point and are using its security
interface. Currently both the contributed Tomcat and Jetty web containers support this.
An example jboss-web with a security-domain element is:
		</p><pre class="programlisting">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;jboss-web&gt;
    &lt;!-- Use the JaasSecurityMgr other security domain for authentication
      and authorization of secured web content.
     --&gt;
    &lt;security-domain&gt;java:/jaas/other&lt;/security-domain&gt;
&lt;/jboss-web&gt;

</pre><p>
           See the JAAS HowTo and the JBossSX chapter for details on setting up security.
		</p></div></div><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="432" height="79"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch07.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch07s16.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch07s16.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch08.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch08.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -