12
返回列表 发新帖
楼主: Sky-Tiger

Know your Oracle application server

[复制链接]
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
11#
 楼主| 发表于 2009-5-8 22:49 | 只看该作者
Context context = new InitialContext();
JavaWorld javaWorld = (JavaWorld)context.lookup("ejb/JavaWorld");
Context context = new InitialContext();
JavaWorld javaWorld =
    (JavaWorld)context.lookup("ejb/JavaWorld#datamodel.logic.JavaWorld");
In the last line of this code, the value of the mappedName attribute precedes the #, and the package plus the Java class name of the business interface follows the #. Note that the mappedName attribute is used to refer to resources configured in the entire application server, not just the application. OC4J doesn't support this attribute.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
12#
 楼主| 发表于 2009-5-8 22:49 | 只看该作者
Configuring resources

In general, it's preferable to configure resources in an application server instead of doing all the coding yourself. A Java Message Service (JMS) service is one such resource. JMS is a messaging standard that lets EJB components create, send, receive, and read messages. To configure a JMS provider on a WebLogic server, you must follow a few steps:

   1. Create a persistence store -- a physical repository for storing data related to the system.
   2. Create a JMS server -- a container that manages queues and topics.
   3. Configure JMS resources, such as queues and topics, as JMS modules.
   4. Create a sub-deployment -- a mechanism that groups JMS resources and binds them to the JMS server.
   5. Create JMS resources -- queues, topics, and connection factories. Queues and topics are destinations that a client can specify as the target or the source, respectively, of the produced or consumed messages. A connection factory is used to connect to a JMS server.

Next, add the persistent store, JMS server, and the JMS modules to the config.xml file in the domain-home/config directory. Put the JMS resources into a separate file located in the domain-home/config/jms directory. This file contains the provided JNDI names. If you use OC4J, you must add the JMS resources to the jms.xml file located in the oc4j-home/config directory.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
13#
 楼主| 发表于 2009-5-8 22:50 | 只看该作者
Resource injection

Java EE lets you retrieve configured resources by using resource injection. Suppose you have configured a connection factory and registered it using the JNDI name jms/JavaWorld. With OC4J, you can retrieve this resource by using:

@Resource(name = "jms/JavaWorld")
private ConnectionFactory javaWorld;

On a WebLogic server, resource injection is not supported by itself. If a certain enterprise bean wants to use configured resources, you must add these resources to the weblogic-ejb-jar.xml file. This file, which defines the beans, can be used to override certain deployment settings. Of course you can still use a JNDI lookup to retrieve the resource.

If an application is being deployed, you can also create a deployment plan that contains various module-override sections. This example deployment-plan section specifies a number of files in which you can define the overrides:

<weblogic-ejb-jar...>
  <weblogic-enterprise-bean>
    <ejb-name>JavaWorld</ejb-name>
    <enable-call-by-reference>True</enable-call-by-reference>
    <jndi-name>ejb/JavaWorld</jndi-name>
  </weblogic-enterprise-bean>
</weblogic-ejb-jar>

Note that the resources to be used by the enterprise bean can be defined in the deployment plan.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
14#
 楼主| 发表于 2009-5-8 22:50 | 只看该作者
Container-managed resources

You can rely on the container to manage resources by:

    * Letting the container manage transactions. The EJB container demarcates the transaction: a transaction is started just before an EJB method starts, and the transaction is committed or rolled back just before the EJB method ends.
    * Using the container's lifecycle to initiate resources (PostConstruct phase) and remove them (PreDestroy phase). For example, if you need a connection to a JMS provider, you create this in the PostConstruct phase and remove it in the PreDestroy phase. If resources such as JMS connections are not removed, it is possible that no new resources can be released by the provider.
    * Letting the container manage the EntityManager. Using a container-managed EntityManager causes the persistence context to be automatically propagated to every component that uses the EntityManager within the transaction.

Using container-managed resources lets the application server handle verbose code. This leaves you with the specific problem at hand, without all the code surrounding it.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
15#
 楼主| 发表于 2009-5-8 22:50 | 只看该作者
MyFaces Trinidad and WebLogic

A JSF component library -- Apache MyFaces Trinidad -- presents another scenario that calls for tweaking WebLogic. If you use a Trinidad version older than 10.*.10 on a WebLogic server, the partial page rendering mechanism does not function properly. (Trinidad has no problems on OC4J.) Trinidad assumes that the content type of an Ajax request is always text/xml. On a WebLogic server this assumption is wrong. On WebLogic the content type is text/html and is interpreted as such by Trinidad, with the result that the partial page rendering mechanism fails. A solution for this issue is to hard-code the content type, as shown in Listing 3:
Listing 3. Hard-coding an Ajax request's content type on WebLogic

@SuppressWarnings("deprecation")
final class XmlHttpServletResponse extends HttpServletResponseWrapper {
    private String _contentType = null;

    XmlHttpServletResponse(ServletResponse response) {
        super((HttpServletResponse)response);
        _contentType = "text/xml;charset=utf-8";
    }
...

    @Override
    public void setContentType(final String type) {
        super.setContentType(_contentType);
    }
}

The setContentType method overrides the default behavior and sets the content type to text/xml, relegating the partial page rendering issue to the history books.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
16#
 楼主| 发表于 2009-5-8 22:50 | 只看该作者
Deploying Trinidad to WebLogic domains

As I mentioned earlier, WebLogic uses domains. It is possible to install libraries -- for example, a Trinidad library -- on a certain domain. To achieve this you just package the Trinidad JARs into a WAR file. Then you can deploy the library as you would any other application. After the library is deployed, this entry is automatically added to the domain's configuration file (config.xml):

<library>
    <name>trinidad</name>
    <target>GeneralServer</target>
    <module-type>war</module-type>
    <source-path>pad\trinidad.war</source-path>
    <deployment-order>1</deployment-order>
    <security-dd-model>DDOnly</security-dd-model>
</library>

Note that the configuration file contains all the domain's configured resources. To let a deployed application use a library, you must configure the deployment override for the application by adding an entry to the weblogic.xml file (which is created automatically if a deployment plan has been created):

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
17#
 楼主| 发表于 2009-5-8 22:52 | 只看该作者
Deploying libraries to OC4J

The process for deploying libraries to OC4J is different from the process for WebLogic. For example, to use a TimesTen data source, you must point the OC4J to the locations of the TimesTen JAR files by running through the following steps:

   1. Add a shared-lib/TimesTen/5.0 directory to the OC4J home.
   2. Place all the JARs in this directory.
   3. Add the following to the server.xml file (located in the oc4j-home/config directory):

      <shared-library name="timesten" version="5.0" library-compatible="true">
          <code-source path="pad/shared-lib/timesten/5.0/ttjdbc5.jar"/>
      </shared-library>

   4. Add the following to the application.xml file (located in the oc4j-home/config directory):

      <imported-shared-libraries>
          <import-shared-library name="timesten"/>
      </imported-shared-libraries>

By using libraries, you no longer need to add the JARs to an EAR or a WAR file.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
18#
 楼主| 发表于 2009-5-8 22:52 | 只看该作者
Controlling classloading

As I mentioned in this article's introduction, sometimes an application server's own system classes can interfere with the classes in the framework you're using. I'll demonstrate this issue and a solution for WebLogic through an example that uses the Hibernate ORM framework.

Commonly, an ORM framework uses a custom-defined query language. Hibernate's query language is HQL. An HQL query is composed of Java objects instead of database objects. In order for the query to communicate with the database, an SQL query must be parsed from the query language. To this end, Hibernate uses a query parser -- the ANTLR library. Unfortunately, WebLogic uses its own version of ANTLR in its system classpath, and it is loaded before classes related to the application are loaded. Because the WebLogic server does not have a proper classloading isolation mechanism, WebLogic doesn't recognize the Hibernate classes in the context of the application. WebLogic fixes this issue by prefixing the names of packages. However, the ANTLR version used in the WebLogic server does not have this prefix.

A workaround is to make sure that the Hibernate classes are loaded before the system classes are loaded. You can accomplish this by editing the setDomainEnv file to include this section:

@REM SET THE CLASSPATH
set CLASSPATH=..\..\..\wlserver_10.3\Hibernate\antlr-2.7.6.jar
set CLASSPATH=%CLASSPATH%;..\..\..\wlserver_10.3\Hibernate\asm.jar
set CLASSPATH=%CLASSPATH%;..\..\..\wlserver_10.3\Hibernate\asm-attrs.jar
set CLASSPATH=%CLASSPATH%;..\..\..\wlserver_10.3\Hibernate\cglib-2.1.3.jar
set CLASSPATH=%CLASSPATH%;..\..\..\wlserver_10.3\Hibernate\commons-collections-2.1.1.jar
set CLASSPATH=%CLASSPATH%;..\..\..\wlserver_10.3\Hibernate\commons-logging-1.0.4.jar
set CLASSPATH=%CLASSPATH%;..\..\..\wlserver_10.3\Hibernate\dom4j-1.6.1.jar
set CLASSPATH=%CLASSPATH%;..\..\..\wlserver_10.3\Hibernate\ehcache-1.2.3.jar
set CLASSPATH=%CLASSPATH%;..\..\..\wlserver_10.3\Hibernate\hibernate3.jar
set CLASSPATH=%CLASSPATH%;..\..\..\wlserver_10.3\Hibernate\jta.jar
set CLASSPATH=%CLASSPATH%;..\..\..\wlserver_10.3\TimesTen\ttjdbc5.jar

set CLASSPATH=%CLASSPATH%;%PRE_CLASSPATH%;%WEBLOGIC_CLASSPATH%;...

If you want to use Hibernate on OC4J, you must remove the TopLink library, which also contains classes that interfere with Hibernate. To remove TopLink, add the following to the application.xml file:

<imported-shared-libraries>
    <remove-inherited name="oracle.toplink"/>
</imported-shared-libraries>

With all the Hibernate classes in the right place, Hibernate operates without any problems on both OC4J and the WebLogic server.

使用道具 举报

回复
论坛徽章:
350
2006年度最佳版主
日期:2007-01-24 12:56:49NBA大富翁
日期:2008-04-21 22:57:29地主之星
日期:2008-11-17 19:37:352008年度最佳版主
日期:2009-03-26 09:33:53股神
日期:2009-04-01 10:05:56NBA季后赛大富翁
日期:2009-06-16 11:48:01NBA季后赛大富翁
日期:2009-06-16 11:48:01ITPUB年度最佳版主
日期:2011-04-08 18:37:09ITPUB年度最佳版主
日期:2011-12-28 15:24:18ITPUB年度最佳技术原创精华奖
日期:2012-03-13 17:12:05
19#
 楼主| 发表于 2009-5-8 22:52 | 只看该作者
n conclusion

When you create an enterprise Java application, thoroughly understanding your application server is as important as mastering your development tools and framework. In this article, you've learned how to tweak WebLogic and OC4J to use some popular third-party libraries, and to enable EJBs to take advantage of JNDI lookups and Java EE resource injection. By delegating resource management to the application server, you can reduce development time, reduce your application's complexity, and improve your application's performance.

使用道具 举报

回复
论坛徽章:
333
青年奥林匹克运动会-铁人三项
日期:2014-09-07 15:58:19青年奥林匹克运动会-摔跤
日期:2014-08-26 19:30:29青年奥林匹克运动会-摔跤
日期:2014-10-12 16:54:49青年奥林匹克运动会-赛艇
日期:2014-08-30 07:59:23青年奥林匹克运动会-沙滩排球
日期:2014-10-12 16:54:49青年奥林匹克运动会-帆船
日期:2014-10-12 16:54:49青年奥林匹克运动会-帆船
日期:2014-10-12 16:54:49青年奥林匹克运动会-帆船
日期:2014-08-31 19:05:45青年奥林匹克运动会-摔跤
日期:2014-10-12 16:54:49青年奥林匹克运动会-艺术体操
日期:2014-11-06 06:49:13
20#
发表于 2009-5-10 19:04 | 只看该作者
能不能搞成中文

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表