Result Checker Logging

Use OHLog to trap warnings but not halt execution of the result checker.

You can influence the error or warning code and message in the result checker by throwing a DSException, which produces errors and halts execution, or by calling OHLog, which is used for warnings and does not halt execution.

Use OHLog.log() to write to the client log. This method returns true if it successfully wrote the log entry, and false if no client is defined. For example, no client is typically defined for a scheduled refresh.

The following code examples illustrates implementation of OHLog for various enterprise information systems.

Data Source: SAP

package com.sybase.vader.test.mms;

import com.sap.conn.jco.JCoFunction;
import com.sybase.sup.sap3.SAPOperationHandler;
import com.sybase.dataservices.OHException;
import com.sybase.dataservices.OHLog;

public class TestSAPOperationHandler extends SAPOperationHandler {

 public void resultCheck(JCoFunction f) {
  OHLog.warn(901, 101, f.toXML());
  //throw new OHException(901, 101, "Throwing test OHException with 901 and 101.");
  }
 
 public void onError(Throwable cause, JCoFunction f) {
  if(f !=null) {
   OHLog.warn(901, 101, f.toXML());
  } else {
   OHLog.warn(902, 102, "JCoFunction null");
  }
  throw new OHException(904, 103, "old exception said '"+cause.getMessage()+"'");
 }
}

Data Source: Web Service (SOAP)

package com.sybase.vader.test.mms;

import java.io.StringWriter;

import com.sybase.dataservices.OHException;
import com.sybase.dataservices.OHLog;
import com.sybase.sup.ws.soap.SoapOperationHandler;

import javax.xml.transform.OutputKeys;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;

import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import javax.xml.soap.SOAPFault;
import javax.xml.soap.SOAPEnvelope;

public class TestSoapOperationHandler extends SoapOperationHandler {

 public void resultCheck(
      javax.xml.soap.SOAPEnvelope response, 
      javax.xml.soap.SOAPEnvelope request) {
   
  OHLog.info(901, 101, toXML(request));
  OHLog.warn(902, 102, toXML(response));
  
  try{
   SOAPFault fault = response.getBody().getFault();
   if(fault!=null) {
    throw new OHException(900, Integer.valueOf(fault.getFaultCode()), fault.getFaultString());
   }
  } catch (Exception e) {
   // ignore
  }
 } 
 
 public void onError(Throwable cause, 
   javax.xml.soap.SOAPEnvelope request) {
  if(request != null) {
   OHLog.info(901, 101, toXML(request));
  }
  throw new OHException(904, 103, "old exception said '"+cause.getMessage()+"'");
 }
 
 private String toXML(javax.xml.soap.SOAPEnvelope env) {
  String xmlString="";
  try {
   TransformerFactory transfac = TransformerFactory.newInstance();
   Transformer trans = transfac.newTransformer();
   trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
   trans.setOutputProperty(OutputKeys.INDENT, "yes");
 
   StringWriter sw = new StringWriter();
   StreamResult result = new StreamResult(sw);
   DOMSource source = new DOMSource(env);
   trans.transform(source, result);
   xmlString = sw.toString(); 
  }
  catch(Exception e) {
   
  }
  return xmlString;
 }
}

Data Source: RESTful Web Service

package com.sybase.vader.test.mms;

import java.net.URL;
import java.util.List;

import com.sybase.sup.ws.rest.RestOperationHandler;
import com.sybase.dataservices.OHLog;
import com.sybase.dataservices.OHException;

public class TestRestOperationHandler extends RestOperationHandler {

 public void resultCheck( String responseBody,
    List<List<String>> responseHeaders, int httpStatusCode, URL url,
         String requestBody, List<List<String>> requestHeaders) {

  OHLog.info(901, 101, url.toString());
  if(requestBody != null) {
   if(requestBody.isEmpty()){
    OHLog.debug(902, 102, "request body empty");
   }
   else {
    OHLog.debug(902, 102, requestBody);
   }
  } else {
   OHLog.debug(902, 102, "request body null");
  }
  int i=0;
  for(List<String> list : requestHeaders) {
   String msg = "" + list.get(0) + "=" + list.get(1);
   OHLog.warn(903, i++, msg);
  }

  OHLog.info(905, 105, "httpStatusCode="+httpStatusCode);
  if(responseBody != null) {
   if(responseBody.isEmpty()){
    OHLog.debug(906, 106, "response body empty");
   }
   else {
    OHLog.debug(906, 106, responseBody);
   }
  }
  else {
   OHLog.debug(906, 106, "response body null");
  }
  i=0;
  for(List<String> list : responseHeaders) {
   String msg = "" + list.get(0) + "=" + list.get(1);
   OHLog.warn(903, i++, msg);
  }
  
  if(httpStatusCode>=300) {
   throw new OHException(500, httpStatusCode, "HTTP status code ["+httpStatusCode+"] too high");
  }
 }

 public void onError(Throwable cause, URL url,
         String requestBody, List<List<String>> requestHeaders) {
  
  if(url != null) {
   OHLog.info(901, 101, url.toString());
  }
  if(requestBody!=null){
   OHLog.debug(902, 102, requestBody);
  }
  int i=0;
  if(requestHeaders != null) {
   for(List<String> list : requestHeaders) {
    String msg = "" + list.get(0) + "=" + list.get(1);
    OHLog.warn(903, i++, msg);
   }
  }
  System.out.println("onError called with following stack trace:");
  cause.printStackTrace();
  System.out.println("^^^^^^");
  throw new OHException(904, 103, "old exception said '"+cause.getMessage()+"'");
 }
}