Implementing a Custom Adapter Factory

Configuring Custom Adapters 14-15 See Section 14.3.1, How to Pass Static Login Credentials to the Data Feed Provider. 8. Edit the MANIFEST.MF file of the application and add the com.bea.core.encryption package to the Import-Package header. See Section 24.2.2.1, Creating the MANIFEST.MF File. 9. Re-assemble and deploy your application as usual. See Chapter 24, Assembling and Deploying Oracle CEP Applications.

14.3.3 How to Access Login Credentials From an Adapter at Runtime

This section describes how update your custom adapter Java code to dynamically get the user and password values from the extended adapter configuration, and then use the com.bea.core.encryption.EncryptionService API to decrypt the encrypted password. The code snippets below build on the HelloWorld adapter Java code, shown in Section 14.2.2.1, Implementing a Custom Adapter as an Event Source. To access login credential properties from an adapter at runtime: 1. Import the additional APIs that you will need to decrypt the encrypted password: import com.bea.core.encryption.EncryptionService; import com.bea.core.encryption.EncryptionServiceException; import com.bea.wlevs.util.Service; 2. Use the Service annotation to get a reference to the EncryptionService: private EncryptionService encryptionService; ... Service public void setEncryptionServiceEncryptionService encryptionService { this.encryptionService = encryptionService; } 3. In the Prepare callback method, get the values of the user and password properties of the extended adapter configuration as usual only code for the password value is shown: private String password; ... public String getPassword { return password; } public void setPasswordString password { this.password = password; ... Prepare public void checkConfigurationHelloWorldAdapterConfig adapterConfig { if adapterConfig.getMessage == null || adapterConfig.getMessage.length == 0 { throw new RuntimeExceptioninvalid message: + message; } this.password= adapterConfig.getPassword; ... } 14-16 Oracle Complex Event Processing Developers Guide See Section 19.3, Programming Access to the Configuration of a Custom Adapter or Event Bean for information about accessing the extended adapter configuration. 4. Use the EncryptionService.decryptStringAsCharArray method in the Prepare callback method to decrypt the encrypted password: Prepare public void checkConfigurationHelloWorldAdapterConfig adapterConfig { if adapterConfig.getMessage == null || adapterConfig.getMessage.length == 0 { throw new RuntimeExceptioninvalid message: + message; } this.password= adapterConfig.getPassword; try { char[] decrypted = encryptionService.decryptStringAsCharArraypassword; System.out.printlnDECRYPTED PASSWORD is + new Stringdecrypted; } catch EncryptionServiceException e { throw new RuntimeExceptione; } } The signature of the decryptStringAsCharArray method is as follows: char[] decryptStringAsCharArrayString encryptedString throws EncryptionServiceException 5. Pass these credentials to the data feed provider using the vendor API.

14.4 Configuring the Custom Adapter EPN Assembly File

The adapter and adapter factory if used must be registered in the EPN assembly file, as discussed in the following sections: ■ Section 14.4.1, Registering the Custom Adapter Factory ■ Section 14.4.2, Declaring the Custom Adapter Components in your Application For a complete description of the configuration file, including registration of other components of your application, see Section 4.3, Creating EPN Assembly Files.

14.4.1 Registering the Custom Adapter Factory

You register factories in the EPN assembly file using the wlevs:factory element: wlevs:factory provider-name=myprovider class=my.Implementation If you need to specify service properties, then you must use the osgi:service element to register the factory as an OSGI service in the EPN assembly file. The scope of the OSGI service registry is the entire Oracle CEP. This means that if more than one application deployed to a given server is going to use the same adapter factory, be sure to register the adapter factory only once as an OSGI service. Add an entry to register the service as an implementation of the com.bea.wlevs.ede.api.AdapterFactory interface. Provide a property, with the key attribute equal to type, and the name by which this adapter provider will be referenced. Finally, add a nested standard Spring bean element to register your specific adapter class in the Spring application context