Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Know your Oracle application server

Troubleshooting OC4J and WebLogic for Java EE application deployment

  • Print
  • Feedback

Page 5 of 6

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.

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.

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):

  • Print
  • Feedback

Resources

More from JavaWorld