Ejemplo n.º 1
0
 /// <summary>  Constructs an exception to wrap one or more SIF_Errors received from an
 /// inbound SIF_Ack message. This form of constructor is only called by
 /// the Adk.
 /// </summary>
 public SifException( SIF_Ack ack,
                      IZone zone )
     : base(null, zone)
 {
     fAck = ack;
     fError = ack != null ? ack.SIF_Error : null;
 }
Ejemplo n.º 2
0
 /// <summary>  Constructs an exception to wrap one or more SIF_Errors received from an
 /// inbound SIF_Ack message. This form of constructor is only called by
 /// the Adk.
 /// </summary>
 public SifException( string msg,
                      SIF_Ack ack,
                      IZone zone )
     : base(msg, zone)
 {
     fAck = ack;
     fError = ack != null ? ack.SIF_Error : null;
 }
Ejemplo n.º 3
0
        /// <summary>
        ///  Attempts to parse attributes out of the source message enough to make a valid
        ///  SIF_Ack with a SIF_Error. This is useful in conditions where the source message cannot
        /// be parsed by the ADK
        /// </summary>
        /// <param name="sourceMessage"> The original message as a string</param>
        /// <param name="error">The error to place in the SIF_Ack/SIF_Error</param>
        /// <param name="zone">The zone associated with this message</param>
        /// <returns></returns>
        /// <exception cref="AdkMessagingException"></exception>
        public static SIF_Ack ackError(String sourceMessage, SifException error, ZoneImpl zone)
        {
            SifMessageInfo parsed = null;
            try
            {
                StringReader reader = new StringReader(sourceMessage);
                parsed = SifMessageInfo.Parse(reader, false, zone);
                reader.Close();
            }
            catch (Exception e)
            {
                zone.Log.Error(e, e);
            }

            SIF_Ack errorAck = new SIF_Ack(zone.HighestEffectiveZISVersion );

            if (parsed != null)
            {
                // Set SIFVersion, OriginalSourceId, and OriginalMsgId;
                if (parsed.SifVersion != null)
                {
                    errorAck.SifVersion = parsed.SifVersion;
                }
                errorAck.SIF_OriginalMsgId = parsed.GetAttribute("SIF_MsgId");
                errorAck.SIF_OriginalSourceId = parsed.GetAttribute("SIF_SourceId");
            }
            SetRequiredAckValues(errorAck);

            SIF_Error newErr = new SIF_Error();
            newErr.SIF_Category = (int)error.ErrorCategory;
            newErr.SIF_Code = error.ErrorCode;
            newErr.SIF_Desc = error.ErrorDesc;
            newErr.SIF_ExtendedDesc = error.ErrorExtDesc;
            errorAck.SIF_Error = newErr;

            return errorAck;
        }
        private static IMessageInputStream makeAck()
        {
            SIF_Ack retval = new SIF_Ack();
            retval.SIF_Status = new SIF_Status( 0 );
            MemoryStream ms = new MemoryStream();
            try
            {
                SifWriter sifWriter = new SifWriter( ms );
                sifWriter.Write( retval );
                sifWriter.Flush();
                //sifWriter.Close();

                MessageStreamImpl imp = new MessageStreamImpl( ms );
                return (IMessageInputStream) imp;
            }
            catch ( Exception )
            {
                return null;
            }
        }
Ejemplo n.º 5
0
        /// <summary>  Create a SIF_Ack for this message.</summary>
        /// <param name="code">The SIF_Status/SIF_Code value
        /// </param>
        /// <returns> A new SIF_Ack instance where the SIF_Status/SIF_Code value is
        /// set to the specified value and SIF_Ack header values are derived
        /// from this message's header values
        /// </returns>
        public virtual SIF_Ack ackStatus(int code)
        {
            SIF_Ack ack = new SIF_Ack();
            SIF_Status status = new SIF_Status(code);
            ack.SIF_Status = status;
            ack.SIF_OriginalMsgId = MsgId;
            ack.SIF_OriginalSourceId = SourceId;

            SifVersion msgVersion = this.SifVersion;

            if (code == 8 /* Receiver is sleeping */ )
            {
                if (msgVersion.Major == 1)
                {
                    // SIF 1.x used SIF_Data for text
                    SIF_Data d = new SIF_Data();
                    d.TextValue = "Receiver is sleeping";
                    status.SIF_Data = d;
                }
                else
                {
                    status.SIF_Desc = "Receiver is sleeping";
                }
            }

            ack.message = this;

            //  Ack using the same version of SIF as this message
            ack.SifVersion = msgVersion;

            return ack;
        }
Ejemplo n.º 6
0
        /// <summary>  Create an error SIF_Ack for this message.</summary>
        /// <param name="category">The value of the SIF_Error/SIF_Category element
        /// </param>
        /// <param name="code">The value of the SIF_Error/SIF_Code element
        /// </param>
        /// <param name="desc">The value of the SIF_Error/SIF_Desc element
        /// </param>
        /// <param name="extDesc">The value of the SIF_Error/SIF_ExtendedDesc element
        /// </param>
        /// <returns> A new SIF_Ack instance with a SIF_Error element and SIF_Ack
        /// header values derived from this message's header values
        /// </returns>
        public virtual SIF_Ack AckError(SifErrorCategoryCode category,
                                         int code,
                                         string desc,
                                         string extDesc)
        {
            SIF_Ack ack = new SIF_Ack();
            ack.SIF_OriginalMsgId = this.MsgId;
            ack.SIF_OriginalSourceId = this.SourceId;
            SIF_Error error = new SIF_Error
                (
                (int)category,
                code,
                desc ?? "");

            if (extDesc != null)
            {
                error.SIF_ExtendedDesc = extDesc;
            }
            ack.SIF_Error = error;

            //  Ack using the same version of SIF as this message
            ack.SifVersion = SifVersion;

            return ack;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create an error SIF_Ack for this message.
        /// </summary>
        /// <param name="sifEx">The SIFException that is the cause of the error</param>
        /// <returns></returns>
        public SIF_Ack AckError(SifException sifEx)
        {
            SIF_Ack ack = new SIF_Ack();
            ack.message = this;

            ack.SIF_OriginalMsgId = this.MsgId;
            ack.SIF_OriginalSourceId = this.SourceId;

            SIF_Error error = new SIF_Error(
                sifEx.ErrorCategory,
                sifEx.ErrorCode,
                sifEx.ErrorDesc,
                sifEx.ErrorExtDesc);

            ack.SIF_Error = error;

            //  Ack using the same version of SIF as this message
            ack.SifVersion = this.SifVersion;

            return ack;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Constructs a SifException for delivery to the ZIS
 /// </summary>
 /// <param name="category">A <c>SifErrorCategoryCode.</c> error category</param>
 /// <param name="code">A <c>SifErrorCodes</c> error code</param>
 /// <param name="desc">The error description</param>
 /// <param name="extDesc">An option extended error description</param>
 /// <param name="zone">The zone on which the error occurred</param>
 /// <param name="innerException">The internal error that was thrown by the agent</param>
 /// <remarks>
 ///  The Adk will include
 /// the error information provided by the exception when it sends a SIF_Ack
 /// in response to the message being processed. This form of constructor is
 /// typically called by the Adk, but may also be called by agent code if an
 /// exception occurs in a <c>IPublisher</c>, <c>ISubscriber</c>, or <c>IQueryResults</c>
 /// message handler implementation.
 /// </remarks>
 public SifException( SifErrorCategoryCode category,
                      int code,
                      string desc,
                      string extDesc,
                      IZone zone,
                      Exception innerException )
     : base(desc, zone, innerException)
 {
     fAck = null;
     fError = new SIF_Error( (int) category, code, desc == null ? "" : desc );
     if ( extDesc != null ) {
         fError.SIF_ExtendedDesc = extDesc;
     }
 }
Ejemplo n.º 9
0
	private SifMessagePayload getPullMessagePayload( SIF_Ack sifPullAck )
	{
		 try
         {
				//  Get the next message
				SifElement msg = sifPullAck.SIF_Status.SIF_Data.GetChildList()[0];
				return (SifMessagePayload)msg.GetChildList()[0];
         }
         catch( Exception ex )
         {
             // TT 139 Andy E
             //An Exception occurred while trying to read the contents of the SIF_Ack
             throw new SifException(
             		SifErrorCategoryCode.Xml , SifErrorCodes.XML_MISSING_MANDATORY_ELEMENT_6,
                 "Unable to parse SIF_Ack", fZone, ex );
         }
	}
Ejemplo n.º 10
0
        /**
	 * Sends a SIF_Ack in response to a pulled message
	 * @param sifGetMessageAck The original SIF_Ack from the SIF_GetMessage. This is sometimes null, when
	 * 						parsing fails
	 * @param pulledMEssage The message delivered inside of the above ack. NOTE that even if parsing fails,
	 *          the SIFParser tries to return what it can, and will return this message payload (in getParsed()),
	 *          instead of the above container message.
	 * @param ackStatus The status to ack (NOTE: This is ignored if the err property is set)
	 * @param err The error to set in the SIF_Ack
	 */
	private void sendPushAck(SIF_Ack sifGetMessageAck,
			SifMessagePayload pulledMEssage, int ackStatus, SifException err) {
		try
		{
			SIF_Ack ack2 = null;
			if( fAckAckOnPull && sifGetMessageAck != null){
				ack2 = sifGetMessageAck.ackStatus( ackStatus );
			} else {
				ack2 = pulledMEssage.ackStatus(ackStatus);
			}


			//  If an error occurred processing the message, return
			//  the details in the SIF_Ack
			if( err != null )
			{
				fZone.Log.Debug( "Handling exception by creating a SIF_Error", err );

				SIF_Error newErr = new SIF_Error();
				newErr.SIF_Category =  (int)err.ErrorCategory;
				newErr.SIF_Code = err.ErrorCode;
				newErr.SIF_Desc = err.ErrorDesc;
				newErr.SIF_ExtendedDesc = err.ErrorExtDesc;
				ack2.SIF_Error = newErr;

				//  Get rid of the <SIF_Status>
				SIF_Status status = ack2.SIF_Status;
				if( status != null ) {
					ack2.RemoveChild( status );
				}
			}

			//  Send the ack
			send(ack2);
		}
		catch( Exception ackEx )
		{
			fZone.Log.Debug( "Failed to send acknowledgement to pulled message: " + ackEx, ackEx );
		}
	}
        private void AckPush( SIF_Ack ack,
                              AdkHttpResponse response )
        {
            try {
                //  Set SIF_Ack / SIF_Header fields
                SIF_Header hdr = ack.Header;
                hdr.SIF_Timestamp = DateTime.Now;

                hdr.SIF_MsgId = SifFormatter.GuidToSifRefID( Guid.NewGuid() );
                hdr.SIF_SourceId = this.Zone.Agent.Id;

                ack.LogSend( this.Zone.Log );

                response.ContentType = SifIOFormatter.CONTENTTYPE;
                // TODO: This code may need to change. The ADKHttpResponse should not automatically set the content length
                // and other implementations will not do so.
                SifWriter w = new SifWriter( response.GetResponseStream() );
                w.Write( ack );
                w.Flush();
            }
            catch ( Exception thr ) {
                Console.Out.WriteLine
                    ( "HttpProtocolHandler failed to send SIF_Ack for pushed message (zone=" +
                      this.Zone.ZoneId + "): " + thr );
                throw new AdkHttpException
                    ( AdkHttpStatusCode.ServerError_500_Internal_Server_Error, thr.Message, thr );
            }
        }
Ejemplo n.º 12
0
 /**
  * If the SIF_OriginalMsgID or SIF_OriginalSourceId are not set,
  * process according to Infrastructure resolution #157
  * @param errorAck
  */
 public static void SetRequiredAckValues(SIF_Ack errorAck)
 {
     //  Return a SIF_Ack with a blank SIF_OriginalSourceId and
     //  SIF_OriginalMsgId per SIFInfra resolution #157
     // Also See 4.1.2.1 SIF_Message processing
     if (errorAck.GetField(InfraDTD.SIF_ACK_SIF_ORIGINALMSGID) == null)
     {
         // Set SIF_OriginalMsgId to xsi:nill
         errorAck.SetField(InfraDTD.SIF_ACK_SIF_ORIGINALMSGID, new SifString(null));
     }
     if (errorAck.GetField(InfraDTD.SIF_ACK_SIF_ORIGINALSOURCEID) == null)
     {
         // Set SIF_OriginalSource to an empty string
         errorAck.SIF_OriginalSourceId = "";
     }
 }