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.
This code sample indicates how to use OHLog for an SAPĀ® back end.
package com.sybase.vader.test.mms; import java.util.AbstractMap; import java.util.Map; import com.sap.conn.jco.JCoFunction; import com.sap.conn.jco.JCoParameterList; import com.sap.conn.jco.JCoRecord; import com.sybase.sup.sap3.SAPResultChecker; import com.sybase.dataservices.DSException; import com.sybase.dataservices.OHLog; public class TestSAPResultChecker implements SAPResultChecker { public Map.Entry<Boolean, String> checkReturn( JCoFunction f ) { JCoRecord returnStructure = null; JCoParameterList jpl = f.getExportParameterList(); int supCode = 200; // Use a standard http code, or 900+ for custom int eisCode = 0; // Use code returned by backend system if ( jpl != null ) { try { returnStructure = jpl.getStructure("RETURN"); if ( returnStructure != null ) { String type = returnStructure.getString("TYPE"); String message = returnStructure.getString("MESSAGE"); eisCode = returnStructure.getInt("NUMBER"); OHLog.log(supCode, eisCode, "TYPE: " + type, OHLog.DEBUG); if ( !(type.equals("") || type.equals("S") || type.equals("I")) ) { if ( !type.equals("W")) { throw new DSException (DSException.INTERNAL_SERVER_ERROR, eisCode, message); } else { OHLog.log(supCode, eisCode, message, OHLog.WARN); } } } } catch (DSException dse) { throw dse; } catch (Exception e) { OHLog.log(OHLog.EIS_RESOURCE_NOT_FOUND, 0, e.getMessage(), OHLog.WARN); } } else { OHLog.log(200, 0, "No parameter list returned", OHLog.WARN); } return new AbstractMap.SimpleEntry<Boolean, String>( true, "" ); } }
This code sample indicates how to use OHLog for a SOAP Web service back end.
package com.sybase.vader.test.mms; import java.io.StringWriter; import java.util.AbstractMap;import java.util.Map.Entry; import com.sybase.dataservices.DSException; import com.sybase.dataservices.OHLog; import com.sybase.sup.ws.soap.SoapOperationHandler; import com.sybase.sup.ws.soap.WSResultChecker; 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 TestSoapResultChecker implements WSResultChecker { public Entry<Boolean, String> checkReturn(SOAPEnvelope response) { int supCode = 900; // Use a standard http code, or 900+ for custom int eisCode = 0; // Use code returned by backend system OHLog.log(supCode, eisCode, toXML(response), OHLog.DEBUG); try{ SOAPFault fault = response.getBody().getFault(); if(fault!=null) { throw new DSException (DSException.INTERNAL_SERVER_ERROR, Integer.valueOf(fault.getFaultCode()), fault.getFaultString()); } } catch (DSException dse) { throw dse; } catch (Exception e) { OHLog.log(OHLog.EIS_RESOURCE_NOT_FOUND, 0, e.getMessage(), OHLog.WARN); } return new AbstractMap.SimpleEntry<Boolean, String> ( true, "" ); } 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; } }
This code sample indicates how to use OHLog for a RESTful Web service back end.
package com.sybase.vader.test.mms; import java.net.URL; import java.util.AbstractMap; import java.util.List; import java.util.Map; import com.sybase.sup.ws.rest.RestResultChecker; import com.sybase.dataservices.OHLog; import com.sybase.dataservices.DSException; public class TestRestResultChecker implements RestResultChecker { public Map.Entry<Boolean, String> checkReturn( String responseBody, List<List<String>> responseHeaders, int httpStatusCode ) { int supCode = 900; // Use a standard http code, or 900+ for custom int eisCode = httpStatusCode; // Use code returned by backend system OHLog.log(supCode, eisCode, "httpStatusCode="+httpStatusCode, OHLog.INFO); if(responseBody != null) { if(responseBody.isEmpty()){ OHLog.log(supCode, eisCode, "response body empty", OHLog.WARN); } else { OHLog.log(supCode, eisCode, responseBody, OHLog.DEBUG); } } else { OHLog.log(supCode, eisCode, "response body null", OHLog.WARN); } int i=1; for(List<String> list : responseHeaders) { String msg = "" + list.get(0) + "=" + list.get(1); OHLog.log(901, i++, msg, OHLog.INFO); } if(httpStatusCode>=300) { throw new DSException (DSException.INTERNAL_SERVER_ERROR, httpStatusCode, "HTTP status code ["+httpStatusCode+"] too high"); } return new AbstractMap.SimpleEntry<Boolean, String>( true, "" ); } }