Building Error Handling and Logging into Target Connectors
The following code example demonstrates how to build error handling and logging into target connectors:
package com.peoplesoft.pt.integrationgateway.targetconnector;
import ...
public class SampleTargetConnector implements TargetConnector {
public IBResponse ping(IBRequest request)
public IBResponse send(IBRequest request)throws
GeneralFrameworkException,
InvalidMessageException,
ExternalSystemContactException,
ExternalApplicationException,
MessageMarshallingException,
MessageUnmarshallingException,
DuplicateMessageException {
PSHttp httpObj = null;
try {
// Get handle on rootnode
XmlNode root = dom.GetDocumentElement();
// Cast the IBRequest back to an InternalIBRequest
InternalIBRequest request = (InternalIBRequest)requestOrig;
// Populate App Msg XML Dom Object from IBRequest
...
// Get the URL from either the IBRequest or from the
//prop file (default)
String URL = request.getConnectorInfo().getFieldValue("URL");
// Log the request
Logger.logMessage("SampleTargetConnector:
Application Message Request", dom.GenerateXmlString(),
Logger.STANDARD_INFORMATION);
// Send the request DOM Document
httpObj.setRequestProperty("content-type", "text/plain");
httpObj.send(dom.GenerateXmlString().getBytes());
// Get the response and convert to a String
responseString = new String(httpObj.getContent());
// Log the response
Logger.logMessage("SampleTargetConnector:
Application Message Response", responseString,
Logger.STANDARD_INFORMATION);
// Construct the IBResponse
response = new IBResponse();
...
// Return the successful IBResponse
return response;
} catch (XmlException xe) {
httpObj.disconnect();
throw new GeneralFrameworkException ("SampleTargetConnector:Failed
while parsing XML");
} catch (org.w3c.www.protocol.http.HttpException httpe) {
throw new ("SampleTargetConnector:HTTP Protocol
exception",httpe);
} catch (java.io.IOException ioe) {
throw new ExternalSystemContactException
("SampleTargetConnector:I/O Exception",ioe);
} finally {
httpObj.disconnect();
}
} // end send()
}