![]() |
![]() |
![]() |
![]() |
![]() |
In addition, if a request is sent that is not of interest, the interceptor needs to be able to pass the request through quickly and efficiently.The PersonQuery example described in Chapter 4, “PersonQuery Sample Application,” uses an interceptor that determines whether the user of the PersonQuery client application can receive addresses. If the identity of the user matches specific criteria, the interceptor allows the full address number to be returned to the client. If no match exists, the interceptor returns only the string of x characters to the log file in place of the address.The topics that follow discuss implementation considerations that may be typical of many interceptors. Examples from the InterceptorData interceptors, which are described in Chapter 8, “InterceptorData Sample Interceptors,” are provided.
For information about getting these starter files from the WebLogic Enterprise Developer Center, see the Release Notes.You can start your interceptor implementation using the sample interceptor code provided in Appendix A, where YourInterceptor represents the name of the interceptor you are implementing. The ORB will always pass nil references for the ServiceContextList and CORBA::DataOutputStream parameters. You should not use or reference those parameters. You should not test those parameters for nil because this restriction may change in a future version.The following code fragment shows the statements to instantiate the InterceptorData client interceptor class. Note that this fragment uses a class named tracker, which is used for keeping track of each incoming client request so that it can be matched with the response returned by the target object. The tracker class is described in the section “Identifying Operations in the Request” on page -5.Using the extracted interface ID, the InterceptorData sample uses a simple switch statement to identify the operation in the client request. That way, the interceptor will know what do with the request parameters contained in the request.The following code fragment shows the switch statement that checks for either the Exit operation or the operation to query the database for a person by name. Note the use of the parser object, which extracts operations from the request retrieved from the tracker object.The InterceptorData samples implement a language object, called Tracker, that keeps a record of the target-bound requests, and then matches the target responses to them when those responses arrive back at the interceptor.The client_response and target_response operations on the InterceptorData samples extract interface and operation information from the Tracker object when responses are returned from the target.The following code fragment shows an example of how the InterceptorData sample places the request parameters from a data stream into a structure. The parameter S in the following code fragment represents a pointer to a DataInputStream structure that can be used by the interceptor implementation to retrieve the value of the reply parameters of the PersonQuery operation. The code encapsulated by the braces in this code fragment extracts the parameters of the response from the DataInputStream structure. For more information about the DataInputStream structure, see Chapter 7, “Request-Level Interceptor API.”Exceptions from interceptors returned via the excep_val parameter can only be a derived type from the CORBA::SystemException base class. (Any other exception type that the interceptor implementations return to the ORB is converted by the ORB to a CORBA::UNKNOWN exception, which is passed via the excep_val parameter.) You need to map exceptions to a CORBA::SystemException class or one of its derivatives.
• The include file needed for securityIn this code example, YourInterceptor represents the name of the interceptor you are creating.#include <CORBA.h>
#include <RequestLevelInterceptor.h>
#include <security_c.h> //for security
class YourInterceptorClient : public virtual RequestLevelInterceptor::ClientRequestInterceptor
{
private:
YourInterceptorClient() {}
CORBA::ORB_ptr m_orb;
public:
YourInterceptorClient(CORBA::ORB_ptr TheOrb);
~YourInterceptorClient() {}
Interceptors::ShutdownReturnStatus shutdown(
Interceptors::ShutdownReason reason,
CORBA::Exception_ptr & excep_val);
CORBA::String id();
void exception_occurred (
const RequestLevelInterceptor::ReplyContext & reply_context,
CORBA::Exception_ptr excep_val);
Interceptors::InvokeReturnStatus client_invoke (
const RequestLevelInterceptor::RequestContext & request_context,
RequestLevelInterceptor::ServiceContextList_ptr service_context,
CORBA::DataInputStream_ptr request_arg_stream,
CORBA::DataOutputStream_ptr reply_arg_stream,
CORBA::Exception_ptr & excep_val);
Interceptors::ResponseReturnStatus client_response (
const RequestLevelInterceptor::ReplyContext & reply_context,
RequestLevelInterceptor::ServiceContextList_ptr service_context,
CORBA::DataInputStream_ptr arg_stream,
CORBA::Exception_ptr & excep_val);
};
class YourInterceptorTarget : public virtual RequestLevelInterceptor::TargetRequestInterceptor
{
private:
YourInterceptorTarget() {}
CORBA::ORB_ptr m_orb;
SecurityLevel1::Current_ptr m_security_current; //for security
Security::AttributeTypeList * m_attributes_to_get; //for security
public:
YourInterceptorTarget(CORBA::ORB_ptr TheOrb);
~YourInterceptorTarget();
Interceptors::ShutdownReturnStatus shutdown(
Interceptors::ShutdownReason reason,
CORBA::Exception_ptr & excep_val);
CORBA::String id();
void exception_occurred (
const RequestLevelInterceptor::ReplyContext & reply_context,
CORBA::Exception_ptr excep_val);
Interceptors::InvokeReturnStatus target_invoke (
const RequestLevelInterceptor::RequestContext & request_context,
RequestLevelInterceptor::ServiceContextList_ptr service_context,
CORBA::DataInputStream_ptr request_arg_stream,
CORBA::DataOutputStream_ptr reply_arg_stream,
CORBA::Exception_ptr & excep_val);
Interceptors::ResponseReturnStatus target_response (
const RequestLevelInterceptor::ReplyContext & reply_context,
RequestLevelInterceptor::ServiceContextList_ptr service_context,
CORBA::DataInputStream_ptr arg_stream,
CORBA::Exception_ptr & excep_val);
};For more information about building and running the sample interceptors provided with the Oracle Tuxedo software, see Chapter 4, “PersonQuery Sample Application.”
• Boot the CORBA server application using the tmboot command