JCA Adapters that support outbound connection to an external application are utilized via the client interface supported by the adapter. The client interface supported by Sun JCA Adapters are based on a simple Application Client Interface. The client interface involves establishment of an application connection via JNDI. The application connection is a container managed connection obtained from a connection pool. The application connection is used along with the OTD objects provided with the JCA adapter to perform operations on the external application.
The tooling for creating code, based on the outbound JCA's client interface is provided via the adapter in the form of specific objects from the Palette draggable onto the code editor. The Palette is made visible by selecting Palette from the Window top-level drop-down menu.
Upon dragging an item from the Palette to the code editor, the JCA wizard is started. In the JCA wizard, a method name must be specified. The method will be added to the code being edited. Depending on the type of external dragged from the Palette, the choice of OTD to be used may need to be specified. The JCA client interface code, required to obtain a JCA connector resource from JNDI, establishes then closes the JCA connection. It then instantiates the associated OTD object, which is also added. The method specified in the JCA wizard is created to simplify development of application logic as the method implementation can simply use OTD objects passed in.
For example, dragging the File object from the Palette to the onContents method of the File MDB and specifying a method name "send" in the JCA wizard adds the following code in the onContents method implementation:
public void onContents(byte[] data, String encoding) throws FaultException,
InboundException {
try {
_invoke_send(data, encoding);
} catch (java.lang.Throwable t) {
ectx.setRollbackOnly();
java.util.logging.Logger.getLogger(this.getClass().getName(
)).log(java.util.logging.Level.WARNING, "Failed to invoke _invoke_send: " + t, t);
}
}
The user application logic can be implemented in the send method which works directly with the OTD objects passed in.
private void send(byte[] data, String encoding, com.stc.connector.fileadapter.appconn.FileClientApplication fileOTD) throws java.lang.Exception {
}
The additional code shown below are also added providing the connection establishment and OTD instantiation.
// <editor - fold defaultstate= collapsed desc="Connection setup and takedown.
Click on the + sign on the left to edit the code.">
private void _invoke_send(byte[] data, String encoding) throws java.lang.Exception {
com.stc.connector.appconn.common.ApplicationConnection fileConnection = null;
try {
if (fileConnection != null) {
fileConnection.close();
}
} catch (Exception e) {
}
}
} // </editor-fold>
// <editor-fold defaultstate="collapsed" desc="file resource declaration. Click on the + sign on the left to edit the code.">
// comments for inserted variable
@javax.annotation.Resource(name = "jca/file", description = "", shareable = false)
private com.stc.connector.appconn.common.ApplicationConnectionFactory file; // </editor-fold>
// <editor-fold defaultstate="collapsed" desc="EJBContext declaration. Click on the + sign on the left to edit the code.">
@javax.annotation.Resource
private javax.ejb.EJBContext ectx; // <editor-fold>