Open topic with navigation

# Implement Custom Actions

You can implement custom actions in a ConnectorLib C++ connector.

Action | Description | Method to override
--- | --- | ---
`action=MyAction` | Perform custom actions on a repository. | `Custom`

First add the custom feature to the list of supported features returned by the `features` function on `ConnectorBase`:

           Features::feature_type MyConnector::features()
           {
              return Features::synchronize|Features::collect|Features::custom;
           }

To implement a custom action, override the `custom` method on the `ConnectorBase` interface.

The ``custom`` method is passed the name of the action that was called in the request. The name is always in upper case, because action names are case-insensitive. You can use the `custom` method to handle as many action names as necessary, however the action names `FETCH`, `VIEW`, `GETURI`, `GETSTATUS`, and so on, are reserved by the connector for the standard actions.

The `custom` method is also passed a `CustomTask` object. The `CustomTask` object provides access to a request object which provides all of the action parameters. Access action parameters using `task.request().getParameter(String parameterName)`.

NOTE:

All actions require a configuration file section name for the action to run. For a synchronous custom action, this is taken from the `configsection` parameter in the request (for example `MyActionSection` in the request `action=MyAction&configsection=MyActionSection`). If `configsection` is not set the connector uses the value of the `sectionname` parameter. If neither of these action parameters are set the connector uses the section name `Default`. In this case, the connector logs the following warning:

`WARNING: Custom action is not associated with a configuration section, using [Default] section`

The section name is available through the `CustomTask` object. Standard operations that read the configuration file use the correct section automatically.

Your code must use the parameters from the request to perform the action and populate the action response. Use the method `response.setValue(String elementName, String value)` to set the value of XML elements in the response.

You can add attributes and nested elements to the action response using XPath-like expressions with element indexes. For example:

           Response.setValue("document[0]/metadata[7]/@name", "MyField");

Your implementation of the custom method should return `false` only if the action name is not supported. In all other cases, return `true`. If another failure occurs then throw an exception from the `custom` method, giving the reason for the failure.

The following sample code shows how a custom action might be implemented for a basic connector. For a complete example, see the example File System Connector that is included in the SDK.

           bool MyConnector::custom(const std::string& action, const CustomTask& task)
           {
              if (action == "MOVE")
              {
                 std::string from = task.request().getParameter("from");
                 std::string to = task.request().getParameter("to");

                 boost::filesystem::rename(from, to);

                 task.response().setValue("moved_from", from);
                 task.response().setValue("moved_to", to);

                 return true;
              }

              return false;
           }

© 2018 Micro Focus or one of its affiliates | Send documentation feedback to Micro Focus Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a web mail client, and send this email to swpdl.idoldocsfeedback@microfocus.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_FT_HTML5_bannerTitle.htm