About this task
Create a request connector when you want to send data,
or publish events to external systems, and receive a response.
The
following example shows the Java™ classes
that you need to create for a request connector:
Javadoc documentation for the Connector
Framework API is available at
Connector API.
Procedure
To create a request connector, complete the following
steps.
- Create the connector by extending the AbstractRequestConnector
class.
The following example request connector Java file demonstrates how to create
a request connector:
package connector.database;
import com.ibm.connectors.AbstractRequestConnector;
import com.ibm.connectors.ConnectorException;
import com.ibm.connectors.RequestInteraction;
public class myRequestConnector extends AbstractRequestConnector {
@Override
public RequestInteraction createRequestInteraction() throws ConnectorException {
// TODO Create the request interaction here. The interaction is the object
// that represents the actual request (even if it doesn't actually perform it).
// The interaction will receive any dynamic properties configured by the message
// flow, as well as the actual data to be sent
return null;
}
}
The connector framework calls the createRequestInteraction
method when a message is to be processed.
- Specify the request connector interaction by extending
the AbstractRequestInteraction class.
The following
example of a request interaction Java file
demonstrates how to create the request interaction:
package connector.database;
import java.util.Properties;
import com.ibm.connectors.AbstractRequestInteraction;
import com.ibm.connectors.ConnectorCallback;
import com.ibm.connectors.ConnectorException;
// The request interaction class performs a request/response with a remote system.
// Currently, data is received as a byte array, and should return a byte array in
// response. Dynamic properties may be passed in to configure the request per-message.
public class myRequestInteraction extends AbstractRequestInteraction {
@Override
public Object request(Properties overrideProperties, Object data)
throws ConnectorException {
byte[] input = (byte[]) data;
// TODO Implement code here to send the byte data to the external
// system. Return the response which currently must be a byte array.
byte[] output = new byte[0];
return output;
}
@Override
public long asyncRequest(Properties overrideProperties, Object data,
ConnectorCallback callback) throws ConnectorException {
// TODO Request asynchronously and return a 'ticket'. Currently
// unsupported/unused.
return 0;
}
}
What to do next
After you create the connector factory and connector, create
the
connector.xml descriptor file (see
Creating a connector descriptor file).