Thanks, for that, I will try it in next few days.  

Ruwan Linton wrote:
> 
> Hi Kim,
> 
> So, first of all you cannot pass message properties to the class mediator
> as
> I described earlier and you will have to use the POJOCommand mediator to
> handle such a case.
> 
> Being said that, by looking at your code and the requirement, you could
> use
> the Class Mediator that you wrote but with a little different but straight
> forward manner to get this working;
> 
> I the design I am proposing the mediator code that you wrote doesn't have
> to
> have class fields called "reqUsername" and "reqPassword" and you could
> extract these values inside the method itself using the
> MessageContext.getPropety(String propertyName) API call. So the code
> fragment in the mediate method has to be changed to the following fragment
> and the two fields has to go away;
> 
> public boolean mediate(MessageContext synCtx) {
> 
>       log.debug("CreateBasicAuthMediator: Create Auth Header started...");
>       if (synCtx.getProperty("Username") == null) {
>               throw new SynapseException("reqUsername property MUST be 
> provided!");
>       }
>               
>       String sAuth = reqUsername;
>               
>       if (synCtx.getProperty("Password") != null) {
>               sAuth = sAuth + ":" + synCtx.getProperty("Password");
>       }
> 
>       //      Extract authentication headers
>       org.apache.axis2.context.MessageContext mc = ((Axis2MessageContext)
> synCtx).getAxis2MessageContext();
>       Map map = (Map)
> mc.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
>               
>       // Set the authentication headers
>       map.put("Authorization", "Basic " + (String)
> Base64.encode(sAuth.getBytes()));
> 
>       log.debug("CreateBasicAuthMediator: Auth Created succeeded!");
> 
>       return true;
> }
> 
> 
> And the script has to set the reqUsername and reqPassword values as
> message
> context properties with names "Username" and "Password" respectively.
> 
> You could use the MessageContext.setProperty(String name, String value);
> API
> call to store the message context property from the script.
> 
> Hope this will solve the issue :-)
> 
> Thanks,
> Ruwan
> 
> On Wed, Mar 11, 2009 at 10:23 AM, kimhorn <[email protected]> wrote:
> 
>>
>> We'll that will save me some time.. I was just about the test a
>> POJOComand
>> trying to access the MessageContext with init.
>>
>> However, I'm now I confused. In the prior POST you mentioned:
>>
>> "So if you have them in the message as properties, then you could use a
>> pojoCommand mediator [1] and use the expression attrbiute to specify an
>> xpath to extract the values stored in the message. If that is stored as a
>> property in the message context you could user the get-property function
>> by
>> passing the property name as the expression. "
>>
>> This is from the "Java Class Properties Setting" posts...
>>
>> The issue was changing the username and password per message for a
>> mediator
>> that adds these to the Transport Header, see java attached.
>>
>> http://www.nabble.com/file/p22448842/CreateBasicAuthMediator.java
>> CreateBasicAuthMediator.java
>>
>> I believe it was suggested that I convert this from a Class Mediator to a
>> POJOCommand.
>> How can I pass different property values, per message, to some Java code
>> that can access the MessageContext ?
>>
>> So in the above I would need to pass different username and passwords for
>> different users but these values are set elsewhere in the script. The
>> original issue was how to pass property value based on an XPath to Class,
>> and it was agreed this could not be done.
>>
>>
>>
>>
>> Ruwan Linton wrote:
>> >
>> > Hi Kim,
>> >
>> > You cannot get the messageContext into the POJOCommand mediator, and it
>> > doesn't support the init method as well.
>> >
>> > You have the access to the message context through the properties
>> because
>> > it
>> > always set and get the properties from the current message, you can use
>> > the
>> > UpdateMessage action with a xpath expression to update the message with
>> > the
>> > out put from the POJO.
>> >
>> > Thanks,
>> > Ruwan
>> >
>> > On Tue, Mar 10, 2009 at 7:17 AM, kimhorn <[email protected]>
>> wrote:
>> >
>> >>
>> >>
>> >> Should / Can the POJO implement ManagedLifecycle to get the Synapse
>> >> Environment to get the
>> >> MesageContext?
>> >>
>> >>
>> >>
>> >> kimhorn wrote:
>> >> >
>> >> > Does any one have a Java example of a POJOCommand that uses Message
>> >> > Context.
>> >> > Unclear how you access it from execute method ?
>> >> >
>> >> > Background to this is in "Java Class Properties Setting" item,
>> >> including
>> >> > the Java
>> >> > code.
>> >> >
>> >> > Basically it was recomended to convert this from a Mediator to a
>> POJO
>> >> but
>> >> > not
>> >> > sure it can be done ?
>> >> >
>> >> >
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Accessing-Message-Context-in-POJOCommand-tp22425548p22426517.html
>> >> Sent from the Synapse - User mailing list archive at Nabble.com.
>> >>
>> >>
>> >
>> >
>> > --
>> > Ruwan Linton
>> > Senior Software Engineer & Product Manager; WSO2 ESB;
>> http://wso2.org/esb
>> > WSO2 Inc.; http://wso2.org
>> > email: [email protected]; cell: +94 77 341 3097
>> > blog: http://ruwansblog.blogspot.com
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Accessing-Message-Context-in-POJOCommand-tp22425548p22448842.html
>> Sent from the Synapse - User mailing list archive at Nabble.com.
>>
>>
> 
> 
> -- 
> Ruwan Linton
> Senior Software Engineer & Product Manager; WSO2 ESB; http://wso2.org/esb
> WSO2 Inc.; http://wso2.org
> email: [email protected]; cell: +94 77 341 3097
> blog: http://ruwansblog.blogspot.com
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Accessing-Message-Context-in-POJOCommand-tp22425548p22449253.html
Sent from the Synapse - User mailing list archive at Nabble.com.

Reply via email to