/** * SIF_Request */ public SIF_Ack SifRequest(IZone zone, Query query, String destinationId, String sifMsgId) { // Send SIF_Request... SIF_Request msg = new SIF_Request(); // Find the maxmimum requested version and set the version of the message to lower // if the version is currently higher than the highest requested version. // In other words, if the Adk is initialized to 2.0, but the highest requested version // is 1.5r1, set the message version to 1.5r1 SifVersion highestRequestVersion = SifVersion.SIF11; if (query.ObjectType == InfraDTD.SIF_ZONESTATUS) { // This query will be satisfied by the ZIS. Use the ZIS compatibility // version, which returns the highest version supported by the ZIS // (Default to Adk.SIFVersion() if not specified in the config) highestRequestVersion = ((ZoneImpl)zone).HighestEffectiveZISVersion; msg.AddSIF_Version(new SIF_Version(highestRequestVersion)); } else { SifVersion[] requestVersions = query.SifVersions; if( requestVersions.Length > 0 ){ // If the Query has one or more SIFVersions set, use them, // and also add [major].* foreach( SifVersion version in requestVersions ){ msg.AddSIF_Version( new SIF_Version( version ) ); if( version.CompareTo( highestRequestVersion ) > 0 ){ highestRequestVersion = version; } } } else { highestRequestVersion = Adk.SifVersion; if( highestRequestVersion.Major == 1 ){ msg.AddSIF_Version( new SIF_Version( highestRequestVersion ) ); } else { // 2.0 and greater, request all data using // [major].*, with 2.0r1 as the message version // This allows for maximum compatibility will all 2.x providers msg.AddSIF_Version( new SIF_Version( highestRequestVersion.Major + ".*" )); msg.SifVersion = SifVersion.GetEarliest( highestRequestVersion.Major ); } } } AgentProperties zoneProperties = zone.Properties; if (zoneProperties.OverrideSifMessageVersionForSifRequests != null) { //There is a property in Agent.cfg that can be used to override the message version from the //default of 2.0r1 This is needed to pass the test harness for 2.3 msg.SifVersion = SifVersion.Parse(zoneProperties.OverrideSifMessageVersionForSifRequests); } else if(msg.SifVersion.CompareTo(highestRequestVersion) > 0) { // The current version of the SIF_Message is higher than the highest // requested version. Back the version number of message down to match msg.SifVersion = highestRequestVersion; } msg.SIF_MaxBufferSize = zone.Properties.MaxBufferSize; SIF_Query sifQ = CreateSIF_Query(query, highestRequestVersion, zone); msg.SIF_Query = sifQ; SIF_Header msgHeader = msg.Header; if (destinationId != null) { msgHeader.SIF_DestinationId = destinationId; } if (sifMsgId != null) { msgHeader.SIF_MsgId = sifMsgId; } // Set the SIF_Context msgHeader.SIF_Contexts = new SIF_Contexts( new SIF_Context(query.SifContext.Name)); return ((ZoneImpl)zone).Dispatcher.send(msg); }
// TODO: Implement /* [Test] public void testReportPublishSIFExceptionAfterReportInfo() { ElementDef objType = SifDtd.SIF_REPORTOBJECT; ErrorMessageHandler handler = new ErrorMessageHandler( ErrorMessageHandler.BVR_SET_REPORT_INFO_THROW_EXCEPTION ); fZone.setReportPublisher( handler, ADKFlags.PROV_NONE); TestProtocolHandler testProto = new TestProtocolHandler(); testProto.open(fZone); MessageDispatcher testDispatcher = new MessageDispatcher( fZone ); fZone.setDispatcher(testDispatcher); fZone.setProto(testProto); testDispatcher.dispatch( createSIF_Request( objType, ADK.makeGUID(), fZone ) ); String msg = testProto.readMsg(); assertNull(testProto.readMsg()); fZone.log.info(msg); SIFParser parser = SIFParser.newInstance(); SIFElement element = parser.parse(new StringReader(msg), fZone); assertTrue(element instanceof SIF_Response); SIF_Response response = (SIF_Response) element; assertTrue(response.getSIF_Error() != null); assertTrue(response.getSIF_Error().getSIF_Desc().startsWith("Blah")); } public void testReportPublishSIFExceptionAfterReportInfo() throws ADKException, IOException { ElementDef objType = SifDtd.SIF_REPORTOBJECT; ErrorMessageHandler handler = new ErrorMessageHandler( ErrorMessageHandler.BVR_SET_REPORT_INFO_THROW_EXCEPTION ); fZone.setReportPublisher( handler, ADKFlags.PROV_NONE); TestProtocolHandler testProto = new TestProtocolHandler(); testProto.open(fZone); MessageDispatcher testDispatcher = new MessageDispatcher( fZone ); fZone.setDispatcher(testDispatcher); fZone.setProto(testProto); testDispatcher.dispatch( createSIF_Request( objType, ADK.makeGUID(), fZone ) ); String msg = testProto.readMsg(); assertNull(testProto.readMsg()); fZone.log.info(msg); SIFParser parser = SIFParser.newInstance(); SIFElement element = parser.parse(new StringReader(msg), fZone); assertTrue(element instanceof SIF_Response); SIF_Response response = (SIF_Response) element; assertTrue(response.getSIF_Error() != null); assertTrue(response.getSIF_Error().getSIF_Desc().startsWith("Blah")); } */ private SIF_Request createSIF_Request(IElementDef objType) { SIF_Request request = new SIF_Request(); request.Header.SIF_MsgId = MSG_GUID; request.Header.SIF_SourceId = "foo"; request.SIF_MaxBufferSize = 32768; request.AddSIF_Version(new SIF_Version(Adk.SifVersion.ToString())); SIF_Query q = new SIF_Query(); SIF_QueryObject sqo = new SIF_QueryObject(); sqo.ObjectName = objType.Name; q.SIF_QueryObject = sqo; request.SIF_Query = q; return request; }
private void SetRequestPolicy( SIF_Request request, IZone zone ) { SIF_Query query = request.SIF_Query; if( query == null ) { // SIF_ExtendedQuery and SIF_Example are not supported by ADK Policy yet return; } // // Object Request Policy // // Determine if there is policy in effect for this Query // String objectName = query.SIF_QueryObject.ObjectName; ObjectRequestPolicy requestPolicy = fPolicyFactory.GetRequestPolicy( zone, objectName ); if( requestPolicy != null ){ // // SIF_Request/SIF_Version policy // String requestVersions = requestPolicy.RequestVersion; if( requestVersions != null ){ if( (Adk.Debug & AdkDebugFlags.Policy ) > 0 ){ zone.Log.Info( "POLICY: Setting SIF_Request/SIF_Version to " + requestVersions ); } // Clear the list of SIF Versions foreach( SIF_Version existingVersion in request.GetSIF_Versions() ){ request.RemoveChild( existingVersion ); } // The version will be a comma-delimited list. Set each of these // as SIF_Version elements, but also try to derive the most logical // version element to set the SIF Message/@Version attribute to // NOTE: Someone could theoretically set versions incorrectly, such // as "1.1,1.5r1". Multiple SIF_Version elements are not supported in // SIF 1.x, but we won't bother with validating incorrect settings. Policy // is power in the configurator's hands to use or abuse. String[] versions = requestVersions.Split( ',' ); String lowestVersion = versions[0]; foreach( String version in versions ){ String ver = version.Trim(); request.AddSIF_Version(new SIF_Version(ver)); if (lowestVersion.CompareTo(ver) > 0) { lowestVersion = ver; } } // Determine how the SIF_Message/@Version should be set to // * If the policy is set to a single version, use it // * If a list, use the lowest // * If *, ignore // * if [major].*, use the lowest version supported if( lowestVersion.Length > 0 ){ SifVersion newMsgVersion = null; if( lowestVersion.EndsWith( "*" ) ){ try { // 2.*, requests go out with a message version of 2.0r1 int major = int.Parse( lowestVersion.Substring( 0, 1 ) ); newMsgVersion = SifVersion.GetEarliest( major ); } catch( FormatException iae ){ zone.Log.Warn( "POLICY: Error parsing ObjectRequestPolicy version '" + requestVersions + "' : " + iae.Message, iae ); } } else { try { newMsgVersion = SifVersion.Parse( lowestVersion ); } catch( FormatException iae ){ zone.Log.Warn( "POLICY: Error parsing ObjectRequestPolicy version '" + requestVersions + "' : " + iae.Message, iae ); } } if( newMsgVersion != null ){ if( (Adk.Debug & AdkDebugFlags.Policy ) > 0 ){ zone.Log.Info( "POLICY: Setting SIF_Messaage/@Version to " + newMsgVersion ); } request.SifVersion = newMsgVersion; } } } // // SIF_DestinationID policy // String requestSourceId = requestPolicy.RequestSourceId ; if( requestSourceId != null ){ if( (Adk.Debug & AdkDebugFlags.Policy) > 0 ){ zone.Log.Info( "POLICY: Setting SIF_Request SIF_DestinationID to " + requestPolicy.RequestSourceId ); } request.SIF_Header.SIF_DestinationId = requestSourceId; } } }