Skip Navigation

Intercepting and Modifying Sabre Emulator Commands

Intercepting Sabre Emulator Commands

Before you begin, you need a working Red App project in your Eclipse workspace.

  1. Add the following required dependencies to the plug-in project:

    • com.sabre.edge.cf.core

    • com.sabre.edge.cf.model

    • com.sabre.edge.cf.emu

    • com.sabre.edge.cf.common

  2. Add the following Java code for emulator command intercept services.

    Create the class that implements the IService interface, and override the process() method.

    public class CommandModificationService implements IService
    {
        @Override
        public void process(IServiceContext context)
        {
    
        }
    }

    Inside the process() method, verify that the type of request you received is the type that you expected. The request type should be an instance of the EmulatorCommandRequest class. If this is not the case, create an error object with the appropriate code and description, and then add it to the context. Set the service status to ServiceStatus.ERROR.

    ContextStatusAdvisor contextAdvisor = new ContextStatusAdvisor(context,getClass());
    IRequest request = context.getRequest();
    if (request instanceof EmulatorCommandRequest)
    {
    
    }
    else
    {
      String errorCode = ErrorCodeFormatter.getInstance("BRIDGE001").format(1);
      String[] parameters = { context.getRequestorId(),
      context.getContextName() };
      IError error = contextAdvisor.error(errorCode, parameters);
    }

    In the preceding example, errorCode is generated by using the ErrorCodeFormatter class. This class automatically composes the error code with the given prefix, and a zero-filled, 3-digit number that is passed as an argument to the format method. In the above example, the error code that is generated is BRIDGE001.

    The error description is obtained from the properties file that is loaded by the class loader of that class, passed as a second argument to the Error constructor. You must place this file in the class path in any source folder that you create in your Eclipse IDE. The file must be named errors.properties. Using the preceding example, errors.properties has the following entry:

    BRIDGE001: Invalid request type.

    The error code is associated with a description of the error.

    If the request type is valid, you can either perform command modification or prevent sending the command to the host.

    If you want to modify the command, complete this step. Create a new EmulatorCommandResponse instance. As a constructor parameter, pass the EmulatorCommand object with the modified command. The modified command is sent to the host in place of the original command. A code sample that modifies a command is shown below.

    // Obtain the intercepted command
    EmulatorCommandRequest commandRequest = (EmulatorCommandRequest) request;
    
    EmulatorCommand command = commandRequest.getEmulatorCommand();
    
    EmulatorCommandResponse commandResponse = null;
    
    if (command.getCommand().startsWith("1KM")){
      // The changed command will be sent to host
      EmulatorCommand modified = new EmulatorCommand("1KRKMUC");
      EmulatorCommandResponse = new EmulatorCommandResponse(modified);
          ((ServiceContext) context).setResponse(commandResponse);
    }
    context.setStatus(ServiceStatus.SUCCESS);

    If you want to prevent the command from being sent to the host, complete this step. Create a new EmulatorCommandResponse instance using the constructor without parameters. A code sample is shown below.

    if (command.getCommand().startsWith("1LA"))
    {
      EmulatorCommandResponse commandResponse = new EmulatorCommandResponse();
    
      ((ServiceContext) context).setResponse(commandResponse);
    }
  3. Add an entry to your redapp.xml file to register your service. Using the examples in this procedure, the entry for registering this service is shown below.

    <Service  name="EMU_COMMAND"
    handler_name="com.sabre.redapp.example.cf.emu.bridge.CommandModificationService"  action_code = "1" />

    Review the information in Building a redapp.xml File to ensure that your file meets all requirements for the components in your Red App.