WebLogic Server 6.1 Code Examples, BEA Systems, Inc.

Package examples.iiop.wls2wls

This example illustrates interoperability between WebLogic 5.1 and WebLogic 6.1 Servers.

See:
          Description

Interface Summary
Trader The methods in this interface are the public face of TraderBean.
TraderHome This interface is the home interface for the TraderBean.java, which in WebLogic is implemented by the code-generated container class TraderBeanC.
 

Class Summary
InteropServlet Call this servlet using an URL such as
TraderBean TraderBean is a stateless Session Bean.
TradeResult This class reflects the results of a buy/sell transaction.
 

Package examples.iiop.wls2wls Description

This example illustrates interoperability between WebLogic 5.1 and WebLogic 6.1 Servers.

Package examples.iiop.wls2wls Description

This example uses an EJB and a servlet to demonstrate interoperability between WebLogic 5.1 and WebLogic 6.1. The necessary WebLogic 5.1 files for this example are included in your WebLogic 5.1 home directory under examples/iiop/wls2wls. The WebLogic 6.1 files are in your WebLogic 6.1 home directory under samples/examples/iiop/wls2wls. Interoperability between 5.1 and 6.1 WebLogic Servers requires Service Packs 11 and 2 respectively. This example has two parts:

WebLogic 5.1--->WebLogic 6.1

See our Interoperability Guide for further information and posting on interoperability between 5.1 and 6.1 WebLogic Servers. As you go through the example, the following are the key points to notice:

System Requirements

The following items are required to run this example:

Setting up the example

This example demonstrates calling an EJB hosted on WebLogic Server 6.1 from a servlet on WebLogic 5.1. The setup is split up into two parts to make it easier to follow. It is recommended that you open two development shells, one for setting up your WebLogic 5.1 server and the other for setting up your WebLogic 6.1 Server.

Setting up your WebLogic 5.1 Server

  1. Set your environment. Use the setEnv script provided in the WebLogic 5.1 home directory.

  2. In your WebLogic 5.1 WL_HOME/examples/iiop/wls2wls directory there is a build script called build_client.cmd. Edit this file changing the following JAVA_HOME and WL_HOME to respectively match the location of your 1.3.1 JDK and WebLogic 5.1 home directory:

    JAVA_HOME=c:\jdk1.3.1_home
    if "" == "%WL_HOME%" set WL_HOME=c:\WL_HOME

  3. Run the 5.1 build script by typing:

    c:/WL_HOME/examples/iiop/wls2wls>build_client.cmd

  4. In your weblogic.properties file, register the servlet that was just built with the following line:

    weblogic.httpd.register.InteropServlet=examples.iiop.wls2wls.InteropServlet

    Note: If you had previously run the example in the other direction (Calling a 5.1 Server from a 6.1 Server) make sure that you have undeployed the 5.1 EJB used in that example. You can do this by simply adding a # character in front of the EJB in your properties file. This comments the line with the EJB out--preventing it from being deployed.

  5. You must add the proper security credentials to your WebLogic 5.1 Server. In the servlet code the user is set to 'iiop' and the password to 'password'. Add the following to your weblogic.properties file to register the same credentials in your 5.1 WebLogic Server:

    weblogic.password.iiop=password

  6. Certain bean classes are required on the client side; these were built into a jar when you compiled the WebLogic 5.1 servlet/client-side. Reference the iiop_wlsw2wls_client.jar that was created in your WebLogic CLASSPATH for the WebLogic 5.1 Server. Do so by adding the following to your WebLogic 5.1 startup script at the end of the WEBLOGIC_CLASSPATH:

    ;.\myserver\clientclasses\iiop_wls2wls_client.jar

  7. Start the WebLogic 5.1 server.

Setting up your 6.1 WebLogic Server

  1. Set your environment by using the setExamplesEnv script in your WebLogic 6.1 WL_HOME/config/examples directory.

  2. Run the build script by typing:

    WL_HOME/samples/examples/iiop/wls2wls>ant -f build_ejb.xml

  3. Start the WebLogic 6.1 examples server.

Run the Example

  • Open a browser and hit the servlet with the following syntax:

    http://5.1server_machinename:5.1server_port/InteropServlet?hostname=6.1server_machinename&port=6.1server_port

    In other words, if your WebLogic 5.1 server and servlet is running on gotham:7001 and your WebLogic 6.1 is on brooklyn:7003, your URL would look like the following:

    http://gotham:7001//InteropServlet?hostname=brooklyn&port=7003

    The example output

    From the servlet:

    
    WebLogic 5.1 <-> 6.1 Interoperability 
    
    Beginning examples.iiop.wls2wls example... 
    
    Looking up TraderHome on iiop://brooklyn:7003... 
    
    Got TraderBean. Performing stock transactions... 
    
    Buying shares... 
    
    Selling shares... 
    
    Removing TraderBean... 
    
    Done. 
    
    From the WebLogic 5.1 Server:
    
    init
    Buying 100 shares of BEAS.
    Buying 200 shares of MSFT.
    Buying 300 shares of AMZN.
    Buying 400 shares of HWP.
    Selling 100 shares of BEAS.
    Selling 200 shares of MSFT.
    Selling 300 shares of AMZN.
    Selling 400 shares of HWP.
    Removing the trader
    
    From the WebLogic 6.1 Server:
    setSessionContext called
    ejbCreate called
    Buying 100 shares of BEAS
    Buying 200 shares of MSFT
    Buying 300 shares of AMZN
    Buying 400 shares of HWP
    Selling 100 shares of BEAS
    Selling 200 shares of MSFT
    Selling 300 shares of AMZN
    Selling 400 shares of HWP
    

    Troubleshooting

    You may see the following message in your servlet:

    Beginning examples.iiop.wls2wls example...
    Looking up TraderHome on iiop://<hostname>:<port>...
    Error occurred while looking up TraderHome.

    1. Check that the WebLogic 6.1 server is running.
    2. Check that WebLogic 6.1 ejb is deployed.
    3. Check that WebLogic 6.1 ejb is deployed with the correct jndi name.
    4. Check that hostname and port are correct.

    If you see the following:

    Beginning examples.iiop.wls2wls example...
    Looking up TraderHome on iiop://<hostname>:<port>...
    Error occurred while trying to get the InitialContext.
    Error occurred while looking up TraderHome.

    1. Check that the 5.1 has a user and password set as iiop and password respectively

    There's more...

    Read more about interoperability at, WebLogic Server 5.1 and WebLogic Server 6.1 Interoperability Guide.

    Read more about RMI-IIOP at, WebLogic Server 6.1 RMI-IIOP Guide.

    WebLogic 6.1--->WebLogic 5.1

    This example illustrates:

    See our Interoperability Guide for further information and new postings on interoperability between 5.1 and 6.1 WebLogic Servers. As you go through the example, the following are the key points to notice.

    System Requirements

    The following items are required to run this example:

    Running the example

    This example demonstrates calling an EJB hosted on WebLogic Server 5.1 from a servlet on WebLogic 6.1.

    Setting up the example

    This example demonstrates calling an EJB hosted on WebLogic Server 5.1 from a servlet on WebLogic 6.1. The setup is split up into two parts to make it easier to follow. It is recommended that you open two development shells, one for setting up your WebLogic 5.1 server and the other for setting up your WebLogic 6.1 Server.

    Setting up your WebLogic 6.1 Server

    1. Run the setExamplesEnv script provided in your WebLogic 6.1 WL_HOME/config/examples directory.

    2. Run the WebLogic 6.1 Servlet/Client-side build script by typing: WL_HOME/examples/iiop/wls2wls>ant -f build_client.xml

    3. Your web.xml file which configures your servlet and the examples web application is located in the C:\WL_HOME\config\examples\applications\examplesWebApp\WEB-INF directory. In your web.xml file, add the following lines to configure the URL and location of the servlet: :

      <servlet>
          <servlet-name>InteropServlet</servlet-name>
          <servlet-class>examples.iiop.wls2wls.InteropServlet</servlet-class>
        </servlet>
      <servlet-mapping>
          <servlet-name>InteropServlet</servlet-name>
          <url-pattern>/InteropServlet/*</url-pattern>
      </servlet-mapping>
      </code>
      

    4. Add the client jar created when you compiled the servlet/client-side to the CLASSPATH of your WebLogic 6.1 Server. Do so by appending the following to the CLASSPATH of your WebLogic 6.1 examples domain startup script:

      ;.\config\examples\clientclasses\iiop_wls2wls_client.jar

    5. Start the WebLogic 6.1 server.

    6. Open the Administration Console. Make sure the bean iiop_wls2wls is targeted to "examplesServer". Click on 'Security' and then 'Users'. Add a user named iiop with the password: password.

    7. Once you have added the iiop user, you will see a new link appear:

      The changes you have made must be saved to the realm implementation.

      Click on this link in order to save the new user and have this change be a part of your running 6.1 WebLogic Server.

    Setting up your WebLogic 5.1 Server

    1. Set your environment. Use the setEnv script provided in the WebLogic 5.1 home directory.

    2. In your WebLogic 5.1 WL_HOME/examples/iiop/wls2wls directory there is a build script called build_ejb.cmd. Edit the first lines of this file to make sure that your JAVA_HOME points to your JDK 1.3.1 installation and that your WL_HOME point to the home directory of your WebLogic 5.1 installation. For example, you may change it to look like the following:

      set JAVA_HOME=c:\jdk1.3.1
      set WL_HOME=c:\weblogic

    3. Run the EJB build script in your WebLogic 5.1 examples directory by typing:

      WL_HOME/examples/iiop/wls2wls>build_ejb.cmd

    4. Edit your WebLogic 5.1 weblogic.properties file to have the bean deployed. You must add the path to the EJB jar file to the weblogic.ejb.deploy section of the properties file. For example:

      weblogic.ejb.deploy=
      c:/weblogic/myserver/iiop_wls2wls.jar

    5. Edit your WebLogic 5.1 startup script to point the JAVA_HOME variable to your 1.3.1 JDK.

    6. Start the WebLogic 5.1 server

    Run the Example

  • Open a browser and hit the servlet with the following syntax:

    http://6.1server_machinename:6.1server_port/InteropServlet?hostname=5.1server_machinename&port= 5.1server_port

    In other words, if your WebLogic 6.1 server and servlet is running on bronx:7006 and your WebLogic 6.1 is on flatbush:7008, your URL would look like the following:

    http://bronx:7006/examplesWebApp/InteropServlet?hostname=flatbush&port=7008

    The example output

    From the servlet:

    
    Beginning examples.iiop.wls2wls example... 
     Looking up TraderHome on iiop://bronx:7006... 
      Got TraderBean. Performing stock transactions... 
      Buying shares... 
      Selling shares... 
      Removing TraderBean... 
      Done. 
    From the 6.1 server:
    
     init
     Buying 100 shares of BEAS.
     Buying 200 shares of MSFT.
     Buying 300 shares of AMZN.
     Buying 400 shares of HWP.
     Selling 100 shares of BEAS.
     Selling 200 shares of MSFT.
     Selling 300 shares of AMZN.
     Selling 400 shares of HWP.
     Removing the trader
     
    
    From the 5.1 server:
    
     setSessionContext called
     ejbCreate called
     Buying 100 shares of BEAS
     Buying 200 shares of MSFT
     Buying 300 shares of AMZN
     Buying 400 shares of HWP
     Selling 100 shares of BEAS
     Selling 200 shares of MSFT
     Selling 300 shares of AMZN
     Selling 400 shares of HWP
    

    Troubleshooting

    You may see the following message in your servlet:

    Beginning examples.iiop.wls2wls example...
    Looking up TraderHome on iiop://<hostname>:<port>...
    Error occurred while looking up TraderHome.

    If you see this error:

    1. Check that the WebLogic 5.1 server is running.
    2. Check that WebLogic 5.1 ejb is deployed.
    3. Check that WebLogic 5.1 ejb is deployed with the correct jndi name.
    4. Check that hostname and port are correct.

    If you see the following message:

    Beginning examples.iiop.wls2wls example...
    Looking up TraderHome on iiop://<hostname>:<port>...
    Error occurred while trying to get the InitialContext.
    Error occurred while looking up TraderHome.

    1. Check that the 6.1 has a user, "iiop" with the password, "password"

    There's more...

    Read more about interoperability at, WebLogic Server 5.1 and WebLogic Server 6.1 Interoperability Guide.

    Read more about RMI-IIOP at, WebLogic Server 6.1 RMI-IIOP Guide.


    Documentation is available at
    http://e-docs.bea.com/wls/docs61

    Copyright © 2001 BEA Systems, Inc. All Rights Reserved.