Hi Asankha,

 

I am using that prefix and it is working. Thanks.

 

Sanjesh

 


From: Asankha C. Perera [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 16, 2006 12:30 AM
To: [email protected]
Subject: Re: getting property value

 

Sanjesh

You are setting a property in the MessageContext - which is local to the message. After you set the property as you state, you can now get this value back (e.g. log it etc) for this same message instance. Once this message passes through the <send> mediator, the response is pushed through the synapse rules all over again - but this is a *new* message. Hence if you want this response to be correlated to your request, you must name the properties with the said prefix.

asankha

Sanjesh Pathak wrote:

Hi Hadrian,

 

Thanks for your offer of help. I have followed the builtin log mediator and developed a mediator. In mediate method I am doing this:

 

    public boolean mediate(MessageContext synCtx) {

   

        // check if it is in request phase   

        if(!synCtx.isResponse()) {       

            // if request, set property value  

            synCtx.setProperty("Id", new Long(1));

        } else {

            // response phase, retrieve value

            Long i = (Long) synCtx.getProperty("Id");

            // I am getting i as  null here

            if(i != null) {

                  log.info("Id: " + i.longValue());

            } else {

                  log.info("i is null");

            }

        }

        return true;

    }

 

The value of i is null in response phase. I have gone through the debugger as well and I see i as null during response.

 

I am attaching synapse.xml file with this mail. The mediator tag is <myMediator/> which is below <log../> tag.

 

Sanjesh

 

 


From: Hadrian Zbarcea [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 15, 2006 3:07 PM
To: [email protected]
Subject: Re: getting property value

 

Hi Sanjesh,

If I guess correctly you have two different instances of your mediator, which would explain the behavior.  You have a few options from extending the sequence mediator to using a static map for properties, thread local storage etc.

Would it be possible to share more details of what you are trying to achieve?  The synapse.xml configuration you are using for your mediator would be great and any sample code you can share.

Regards,
Hadrian

On 8/15/06, Sanjesh Pathak <[EMAIL PROTECTED]> wrote:

Hi,

 

I have created a new mediator and it is working fine. Now I want to set a property value in the request phase of the mediate method and retrieve it in response phase. What is the right approach?

 

I tried using msgContext:setProperty() in request phase and when I retrieve it using msgContext :getPorperty() I am getting a null value.

 

Sanjesh

 

 


 
<synapse xmlns="http://ws.apache.org/ns/synapse">
  
  <definitions>
    
    <sequence name="stockquote">
        <!-- set the To address to the real endpoint -->
        <header name="To" value="http://www.webservicex.net/stockquote.asmx"/>
    
        <!-- check if the symbol is MSFT -->
      <filter xpath="//*[wsx:symbol='MSFT']" xmlns:wsx="http://services.samples/xsd">
        <!-- if it is throw a fault -->
        <makefault>
               <code value="tns:Receiver" xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/>
               <reason value="Isn't there a Windows API for that?"/>
        </makefault>
      </filter>
    </sequence>
 
  </definitions>
 
  <rules>
        <!-- now log the message using log4j -->
        <log level="full"/>
        <myMediator/>
        
        <!-- Check if the URL matches the stockquote gateway/dumb case -->
        <filter source="get-property('To')" regex=".*/StockQuote.*">
               <sequence ref="stockquote"/>
        </filter>
        
        <!-- check if the URL matches the virtual url - either the proxy or ws-add case -->
               <filter source="get-property('To')" regex="http://.*stockquotes.*">
               <sequence ref="stockquote"/>
        </filter>
        
        <!-- send the message on -->
        <send/>
  </rules>
 
</synapse> 
  
 



 
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to