Managed Code Sample Using the Siebel Resource Adapter

The following is a code sample using the Siebel Resource Adapter in a managed environment. The sample is a servlet that makes a simple invocation to a business service using the generated JCA code. (For more information about generating code, see About the Siebel Code Generator.)

The JCA ConnectionFactory is obtained through JNDI. Credentials are obtained at run time from the JAAS Subject passed to the servlet. The connect string and language are obtained from the deployment descriptor (ra.xml). Other connection parameters are obtained from the siebel.properties file.

Note: The siebel.properties file must be in the JVM classpath and must be specified explicitly when the business service instance is created.
  import javax.naming.*;
  import java.io.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import com.siebel.integration.jca.cci.SiebelConnectionFactory;
  import com.siebel.service.jca.eaifiletransport.*;

  public class ManagedConnectionServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) 
    throws IOException,ServletException {
    PrintWriter reply = response.getWriter();

    try {
      // Specify siebel.properties in the constructor.
      EAI_File_TransportBusServAdapter bs = new 
      EAI_File_TransportBusServAdapter("siebel.properties"?);
      InitialContext jndi = new InitialContext();
      SiebelConnectionFactory scf = 
      (SiebelConnectionFactory)jndi.lookup("siebelJCA"); 
      bs.setConnectionFactory(scf);

      // Username and password obtained from JAAS Subject passed by server at runtime.
      // Connect string and language obtained from deployment descriptor, ra.xml. 
      ReceiveInput input = new ReceiveInput();
      input.setfCharSetConversion("UTF-8");
      input.setfFileName("D:\\helloWorld.txt");
      ReceiveOutput output = bs.mReceive(input);
      reply.println(output.getf_Value_());
    }
    catch (Exception e) {
      reply.println("Exception:" + e.getMessage());
      }
    }
  }