Previous     Contents     Index     DocHome     Next     
iPlanet Application Server Enterprise Connector for R/3 Developer's Guide



Chapter 4   Programming Samples


The R/3 connector is designed to facilitate development of communication between the EIS tier and the application server. Programming samples of the R/3 connector are provided to facilitate development of your own applications.

This chapter contains actual samples that show how the connector works. The following samples can be run on both Windows NT and Solaris platforms.



R/3 Samples

The R/3 samples provided show the general flow of a connector program.


Activation

The R/3 sample consist of servlets which activate R/3 programs that access R/3 management system.


To Run the R/3 Samples on Windows NT

  1. Select Programs>iPlanet Application Server 6.0>R/3 Connector 6.0 - Start Worker Process.

  2. Select Programs>iPlanet Application Server 6.0>R/3 Connector 6.0 - Sample Applications.

    The R/3 sample script, displayed in Figure 4-1, has links to the samples.

  3. Click on the link "To Start The Simple Sample - Get Customer Details Demo" to activate the sample shown in Figure 4-2.

Figure 4-1    R/3 Customer Details Samples



To Run the R/3 Samples on Solaris

  1. Enter the following command:

    <ias directory>/ias/APPS/bin/startR3worker.sh start

  2. Start your browser.

  3. Enter the following URL:

    <host name>:<web server port>/R3Samples

    Run this script before running the samples.


SIMPLE_BAPI_CUSTOMER_GETDETAIL SAMPLE

The SIMPLE_ BAPI_ CUSTOMER_ GETDETAIL sample shows how to write servlets that communicate with backend systems.


To Activate the SIMPLE_BAPI_CUSTOMER_GETDETAIL Sample

  1. Click on the Get Customer Details Demo hyperlink.

    The StartForm is displayed with the WebUserId and CUSTOMERNO, as shown in Figure 4-2.

  2. Enter the following information:

    WebUserID - default is W2

    CUSTOMERNO - default is 1000

Figure 4-2    startForm.jsp


  1. Click Execute.

    Figure 4-3 displays the Customer Details.

Figure 4-3    Customer Details




Code Samples



The code samples are included to show the programmer how to set input and output parameters and the BAPI call.

This is a fully operational sample. You can use it as a model for building your own application.

Code Example 4-1 and Code Example 4-2 describe the SIMPLE_BAPI_CUSTOMER_GETDETAIL sample.

Code Example 4-1 startForm.jsp

<HTML>

<HEAD

>   <TITLE>SIMPLE_BAPI_CUSTOMER_GETDETAIL Demo</TITLE>

</HEAD>

<BODY>

<center>

<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="600" >

   <tr>

      <td VALIGN=TOP WIDTH="420" >

         <form action="/NASApp/SIMPLE_BAPI_CUSTOMER_GETDETAIL/main" method=get>

         <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=6 WIDTH="100%">

         <tr>

            <td BGCOLOR="#8979C8">

            <b><font face="sans-serif,arial,helvetica" color=white>

               SIMPLE_BAPI_CUSTOMER_GETDETAIL Start Form</font>

            </b>

            </td>

         </tr>

         <tr VALIGN=TOP>

            <td BGCOLOR="#666699">

            <p>

            <center>

            <TABLE BORDER=0 cellspacing=0 cellpadding=0>

            <tr>

               <td><font face="arial, helvetica, sans-serif" color=white size="-1">WebUserId:</font></td>

               <td><font face="arial, helvetica, sans-serif">

                  <input type="text" name="WebUserId" size=20 maxsize=50 value="W2" ></font>

               </td>

            </tr>

            <tr>

               <td><font face="arial, helvetica, sans-serif" color=white size="-1">CUSTOMERNO:</font></td>

               <td><font face="arial, helvetica, sans-serif">

                  <input type="text" name="INPUT.CUSTOMERNO" size=20 maxsize=50 value="0000001000" ></font>

               </td>

            </tr>

            <tr>

               <td><font face="arial, helvetica, sans-serif" color=white size="-1">PI_DISTR_CHAN:</font></td>

               <td><font face="arial, helvetica, sans-serif">

                  <input type="text" name="INPUT.PI_DISTR_CHAN" size=20 maxsize=50></font>

               </td>

            </tr>

            <tr>

               <td><font face="arial, helvetica, sans-serif" color=white size="-1">PI_DIVISION:</font></td>

               <td><font face="arial, helvetica, sans-serif">

                  <input type="text" name="INPUT.PI_DIVISION" size=20 maxsize=50></font>

               </td>

            </tr>

            <tr>

               <td><font face="arial, helvetica, sans-serif" color=white size="-1">PI_SALESORG:</font></td>

               <td><font face="arial, helvetica, sans-serif">

                  <input type="text" name="INPUT.PI_SALESORG" size=20 maxsize=50></font>

               </td>

            </tr>

            </TABLE>

            </center>

            </td>

         </tr>

         </TABLE>

         <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%" >

         <tr>

            <td BGCOLOR="#666699" >

            <TABLE>

            <tr>

               <td valign=top ><input type="submit" name="execute" value="EXECUTE">

               </td>

            </tr>

            </TABLE>

            </td>

         </tr>

         </TABLE>

         </form>

      </td>

   </tr>

</TABLE>

<P>

<CENTER>

<TABLE BGCOLOR="#cccccc" BORDER="0" CELLPADDING="1" CELLSPACING="0" WIDTH="600">

<tr>

   <td><p>&nbsp;</P>

      <FONT size="-2" face="PrimaSans BT, Verdana, sans-serif">Copyright © 1999

         <A HREF="http://home.netscape.com/" NAME="Link3">Netscape Communications Corp</A>

          All rights reserved.</FONT>

   </td>

</tr>

</TABLE>

</CENTER>

</P>

</center>

</BODY>

</HTML>



Code Example 4-2 main.java

package SIMPLE_BAPI_CUSTOMER_GETDETAIL;

import java.util.*;

import javax.servlet.http.*;

import java.io.*;

import javax.servlet.*;

import javax.naming.*;

import netscape.bsp.*;

import netscape.bsp.runtime.*;

import netscape.bsp.dataobject.*;

import netscape.bsp.BspException.*;

public class main extends HttpServlet

{

   protected String getInputString(HttpServletRequest request, String parameterName,ServletOutputStream out) throws IOException

   {

      // This method is useful since getValString returns null on

      // some platforms and an empty string on other platforms for

      // missing input parameters.   It also removes any whitespace

      // characters that the user my have inadvertantly entered.

      String parameter = request.getParameter(parameterName);

      if (parameter != null)

      {

         parameter = parameter.trim();

      }

      else

         out.println("\n<BR>parameter "+ parameterName+" is null");

      return parameter;

   }

   protected ServletOutputStream setOutputStream (HttpServletResponse res)

      throws ServletException, IOException

   {

      res.setContentType("text/html");

      ServletOutputStream out = res.getOutputStream();

      return out;

   }

   private IBSPRuntime getRuntime() throws BspException

   {

      com.kivasoft.IContext _ctx = ((com.netscape.server.servlet.platformhttp.PlatformServletContext)    getServletContext()).getContext();

      IBSPRuntime ibspruntime = access_cBSPRuntime.getcBSPRuntime(_ctx, null, null);

      return ibspruntime;

   }

   private IBSPServiceProvider getServiceProvider(IBSPRuntime runtime) throws BspException

   {

      if(runtime != null)

         return runtime.createServiceProvider("R3", "connection");

      else

         return null;

   }

   public void doGet (

      HttpServletRequest   request,

      HttpServletResponse   response ) throws ServletException, IOException

   {

      int hr=0;

      IBSPServiceProvider sp=null;

      IBSPFunctionObject fn = null;

      IBSPDataObject data = null, prop = null;

      ServletOutputStream out = setOutputStream(response);

      try

      {

         String WebUserId=new String(getInputString(request,"WebUserId",out));

         IBSPRuntime runtime = getRuntime();

         if(runtime != null )

         {

            sp = getServiceProvider(runtime);

            if(sp != null )

            {

               IBSPDataObject config=sp.getConfig();

               config.setAttrFString("WebUserId",WebUserId);

               fn = runtime.createFunctionObject("R3", "BAPI_CUSTOMER_GETDETAIL");

               hr = sp.enable();

               if(hr!=0)

                  return;

               if( fn != null )

               {

                  hr = fn.useServiceProvider(sp);

                  if(hr!=0)

                     return;

                  hr = fn.prepare("Execute");

                  if(hr!=0)

                     return;

                  data = fn.getDataBlock();

                  setInputData(request,data,out);

                  hr = fn.execute();

                  if( hr == 0 )

                  {

                     data = fn.getDataBlock();

                     if(data != null )

                        getOutputData(out,data);

                  } // if(hr == 0)

                  else

                     out.println("\n<BR>Execute Failed");

               } // if(fn != null)

               else

                  out.println("\n<BR>Create function object Failed");

            } // if( sp != null )

            else

               out.println("\n<BR>Create service provider Failed");

            hr = sp.disable();

         }

         else

            out.println("\n<BR>Create runtime Failed");

      }//try.

      catch(BspException BspError)

      {

         if(sp!=null)

         {

            hr = sp.disable();

         }

         String errorMessage="BspException:"+BspError.getMessage();

         IBSPDataObjectStructure info = null;

         info=BspError.getInfo();

         if (info != null && info.attrExists("msgid") )

         {

            errorMessage += " Error code : " + info.getAttrInt("msgid") ;

         }

         out.println("\n<BR>"+errorMessage);

      }

      catch(Exception exception)

      {

         if(sp!=null)

         {

            hr = sp.disable();

         }

         String errorMessage="Exception:"+exception.toString();

         out.println("\n<BR>"+errorMessage);

      }

      return;

   }//doGet.

   public void setInputData(HttpServletRequest request,IBSPDataObject data,ServletOutputStream out) throws BspException,IOException

   {

       data.setAttrFString("INPUT.CUSTOMERNO",getInputString(request,"INPUT.CUSTOMERNO ",out));

       data.setAttrFString("INPUT.PI_DISTR_CHAN",getInputString(request,"INPUT.PI_DIST R_CHAN",out));

       data.setAttrFString("INPUT.PI_DIVISION",getInputString(request,"INPUT.PI_DIVISI ON",out));

       data.setAttrFString("INPUT.PI_SALESORG",getInputString(request,"INPUT.PI_SALESO RG",out));

   }

   public void getOutputData(ServletOutputStream out,IBSPDataObject data) throws BspException,IOException

   {

       out.println("\n<BR>PE_ADDRESS.FORM_OF_AD:"+data.getAttrFString("OUTPUT.PE_ADDRE SS.FORM_OF_AD"));

       out.println("\n<BR>PE_ADDRESS.FIRST_NAME:"+data.getAttrFString("OUTPUT.PE_ADDRE SS.FIRST_NAME"));

       out.println("\n<BR>PE_ADDRESS.NAME:"+data.getAttrFString("OUTPUT.PE_ADDRESS.NAM E"));

       out.println("\n<BR>PE_ADDRESS.NAME_3:"+data.getAttrFString("OUTPUT.PE_ADDRESS.N AME_3"));

       out.println("\n<BR>PE_ADDRESS.NAME_4:"+data.getAttrFString("OUTPUT.PE_ADDRESS.N AME_4"));

       out.println("\n<BR>PE_ADDRESS.DATE_BIRTH:"+data.getAttrFString("OUTPUT.PE_ADDRE SS.DATE_BIRTH"));

       out.println("\n<BR>PE_ADDRESS.STREET:"+data.getAttrFString("OUTPUT.PE_ADDRESS.S TREET"));

       out.println("\n<BR>PE_ADDRESS.POSTL_CODE:"+data.getAttrFString("OUTPUT.PE_ADDRE SS.POSTL_CODE"));

       out.println("\n<BR>PE_ADDRESS.CITY:"+data.getAttrFString("OUTPUT.PE_ADDRESS.CIT Y"));

       out.println("\n<BR>PE_ADDRESS.REGION:"+data.getAttrFString("OUTPUT.PE_ADDRESS.R EGION"));

       out.println("\n<BR>PE_ADDRESS.COUNTRY:"+data.getAttrFString("OUTPUT.PE_ADDRESS. COUNTRY"));

       out.println("\n<BR>PE_ADDRESS.COUNTRNISO:"+data.getAttrFString("OUTPUT.PE_ADDRE SS.COUNTRNISO"));

       out.println("\n<BR>PE_ADDRESS.COUNTRAISO:"+data.getAttrFString("OUTPUT.PE_ADDRE SS.COUNTRAISO"));

       out.println("\n<BR>PE_ADDRESS.INTERNET:"+data.getAttrFString("OUTPUT.PE_ADDRESS .INTERNET"));

       out.println("\n<BR>PE_ADDRESS.FAX_NUMBER:"+data.getAttrFString("OUTPUT.PE_ADDRE SS.FAX_NUMBER"));

       out.println("\n<BR>PE_ADDRESS.TELEPHONE:"+data.getAttrFString("OUTPUT.PE_ADDRES S.TELEPHONE"));

       out.println("\n<BR>PE_ADDRESS.TELEPHONE2:"+data.getAttrFString("OUTPUT.PE_ADDRE SS.TELEPHONE2"));

       out.println("\n<BR>PE_ADDRESS.LANGU:"+data.getAttrFString("OUTPUT.PE_ADDRESS.LA NGU"));

       out.println("\n<BR>PE_ADDRESS.LANGU_ISO:"+data.getAttrFString("OUTPUT.PE_ADDRES S.LANGU_ISO"));

       out.println("\n<BR>PE_ADDRESS.CURRENCY:"+data.getAttrFString("OUTPUT.PE_ADDRESS .CURRENCY"));

       out.println("\n<BR>PE_ADDRESS.CURRENCY_ISO:"+data.getAttrFString("OUTPUT.PE_ADD RESS.CURRENCY_ISO"));

       out.println("\n<BR>RETURN.TYPE:"+data.getAttrFString("OUTPUT.RETURN.TYPE"));

       out.println("\n<BR>RETURN.CODE:"+data.getAttrFString("OUTPUT.RETURN.CODE"));

       out.println("\n<BR>RETURN.MESSAGE:"+data.getAttrFString("OUTPUT.RETURN.MESSAGE" ));

       out.println("\n<BR>RETURN.LOG_NO;"+data.getAttrFString("OUTPUT.RETURN.LOG_NO")) ;

       out.println("\n<BR>RETURN.LOG_MSG_NO:"+data.getAttrFString("OUTPUT.RETURN.LOG_M SG_NO"));

       out.println("\n<BR>RETURN.MESSAGE_V1:"+data.getAttrFString("OUTPUT.RETURN.MESSA GE_V1"));

       out.println("\n<BR>RETURN.MESSAGE_V2:"+data.getAttrFString("OUTPUT.RETURN.MESSA GE_V2"));

       out.println("\n<BR>RETURN.MESSAGE_V3:"+data.getAttrFString("OUTPUT.RETURN.MESSA GE_V3"));

       out.println("\n<BR>RETURN.MESSAGE_V4:"+data.getAttrFString("OUTPUT.RETURN.MESSA GE_V4"));

   }

}//main



Previous     Contents     Index     DocHome     Next     
Copyright © 2000 Sun Microsystems, Inc. Some preexisting portions Copyright © 2000 Netscape Communications Corp. All rights reserved.

Last Updated November 01, 2000