You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@synapse.apache.org by Garth Patil <ga...@gmail.com> on 2008/05/20 03:01:23 UTC

mediator access to request body?

Hi All,
I am trying to write an mediator that needs access to the underlying
body of the request (in order to verify message authenticity using a
header). I can get the header like this:
public boolean mediate(MessageContext synCtx) {
	org.apache.axis2.context.MessageContext mc = ((Axis2MessageContext) synCtx)
			.getAxis2MessageContext();
	Map headers = (Map) mc
			.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
	String myHeader = (String) header.get("My-Digest-Header");
	...
But I also need to get access to the body of the request (like I'd do
using request.getInputStream() in a servlet). Any ideas if it is
available and how I can get at it?
Thanks,
Garth

Re: mediator access to request body?

Posted by Garth Patil <ga...@gmail.com>.
Some links for those looking for more information on this kind of
integrity and authenticity verification:
http://en.wikipedia.org/wiki/Message_authentication_code
http://en.wikipedia.org/wiki/HMAC

On Mon, May 19, 2008 at 6:33 PM, Garth Patil <ga...@gmail.com> wrote:
> Hi Ruwan,
> I need a byte-accurate representation of the body because my
> requirement is to validate the message authenticity using a keyed-hash
> message authentication code.
> For example, a client would sign the request by placing a value in the
> header that is the result of hashing the request body along with a
> shared secret key. In order to create a mediator that can accurately
> reproduce the keyed-hash message authentication code, the server must
> have the same bytes from the request as the client, not a
> representation of it.
> Given that, it sounds like I should access the data handler as I would
> a binary message. How do I do that in Synapse?
> Thanks,
> Garth
>
> On Mon, May 19, 2008 at 6:24 PM, Ruwan Linton <ru...@gmail.com> wrote:
>> At the same time could you please elaborate a bit on your requirement? why
>> you need the request body as an InputStream?
>>
>> Thanks,
>> Ruwan
>>
>> On Tue, May 20, 2008 at 6:53 AM, Ruwan Linton <ru...@gmail.com>
>> wrote:
>>
>>> Hi Garth,
>>>
>>> If you want to retrieve the message body as an input stream, no you cannot
>>> retrieve the input stream but just the built message as xml in which case;
>>>
>>> synCtx.getEnvelope() will give you the envelope.
>>>
>>> If you are referring to a binary message (non xml/non text, binary data)
>>> then you can access the request stream by getting the access to the data
>>> handler in the payload of the envelope. If what you are referring to is this
>>> please do let me know, so that I can provide you with more information on
>>> this.
>>>
>>> Thanks,
>>> Ruwan
>>>
>>>
>>> On Tue, May 20, 2008 at 6:31 AM, Garth Patil <ga...@gmail.com> wrote:
>>>
>>>> Hi All,
>>>> I am trying to write an mediator that needs access to the underlying
>>>> body of the request (in order to verify message authenticity using a
>>>> header). I can get the header like this:
>>>> public boolean mediate(MessageContext synCtx) {
>>>>        org.apache.axis2.context.MessageContext mc = ((Axis2MessageContext)
>>>> synCtx)
>>>>                        .getAxis2MessageContext();
>>>>        Map headers = (Map) mc
>>>>
>>>>  .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
>>>>        String myHeader = (String) header.get("My-Digest-Header");
>>>>        ...
>>>> But I also need to get access to the body of the request (like I'd do
>>>> using request.getInputStream() in a servlet). Any ideas if it is
>>>> available and how I can get at it?
>>>> Thanks,
>>>> Garth
>>>>
>>>
>>>
>>>
>>> --
>>> Ruwan Linton
>>> http://www.wso2.org - "Oxygenating the Web Services Platform"
>>
>>
>>
>>
>> --
>> Ruwan Linton
>> http://www.wso2.org - "Oxygenating the Web Services Platform"
>>
>

Re: mediator access to request body?

Posted by Ruwan Linton <ru...@gmail.com>.
Paul,

This is correct but a little bit of risky to assume that it is not being
processed, because even if there is log of the envelope then the message or
part of the message will be built and the original stream wont be there.

So I think the best solution is to add a wrapping Binary builder to either
attach a copy of the binary stream or the generated hash value to the
message context and delegate the message to the proper builder depending on
its content type.

Thanks,
Ruwan

On Wed, May 21, 2008 at 10:26 PM, Paul Fremantle <pz...@gmail.com> wrote:

> Garth
>
> Are you looking for the XML infoset or the actual bytes of the
> message? StAX and Synapse are designed to support exact access to the
> XML infoset. If you get the StAX stream from the body before you do
> any manipulation to it, then I believe that you can get a genuine
> unmodified representation from that.
>
> Paul
>
> On Tue, May 20, 2008 at 2:33 AM, Garth Patil <ga...@gmail.com> wrote:
> > Hi Ruwan,
> > I need a byte-accurate representation of the body because my
> > requirement is to validate the message authenticity using a keyed-hash
> > message authentication code.
> > For example, a client would sign the request by placing a value in the
> > header that is the result of hashing the request body along with a
> > shared secret key. In order to create a mediator that can accurately
> > reproduce the keyed-hash message authentication code, the server must
> > have the same bytes from the request as the client, not a
> > representation of it.
> > Given that, it sounds like I should access the data handler as I would
> > a binary message. How do I do that in Synapse?
> > Thanks,
> > Garth
> >
> > On Mon, May 19, 2008 at 6:24 PM, Ruwan Linton <ru...@gmail.com>
> wrote:
> >> At the same time could you please elaborate a bit on your requirement?
> why
> >> you need the request body as an InputStream?
> >>
> >> Thanks,
> >> Ruwan
> >>
> >> On Tue, May 20, 2008 at 6:53 AM, Ruwan Linton <ru...@gmail.com>
> >> wrote:
> >>
> >>> Hi Garth,
> >>>
> >>> If you want to retrieve the message body as an input stream, no you
> cannot
> >>> retrieve the input stream but just the built message as xml in which
> case;
> >>>
> >>> synCtx.getEnvelope() will give you the envelope.
> >>>
> >>> If you are referring to a binary message (non xml/non text, binary
> data)
> >>> then you can access the request stream by getting the access to the
> data
> >>> handler in the payload of the envelope. If what you are referring to is
> this
> >>> please do let me know, so that I can provide you with more information
> on
> >>> this.
> >>>
> >>> Thanks,
> >>> Ruwan
> >>>
> >>>
> >>> On Tue, May 20, 2008 at 6:31 AM, Garth Patil <ga...@gmail.com>
> wrote:
> >>>
> >>>> Hi All,
> >>>> I am trying to write an mediator that needs access to the underlying
> >>>> body of the request (in order to verify message authenticity using a
> >>>> header). I can get the header like this:
> >>>> public boolean mediate(MessageContext synCtx) {
> >>>>        org.apache.axis2.context.MessageContext mc =
> ((Axis2MessageContext)
> >>>> synCtx)
> >>>>                        .getAxis2MessageContext();
> >>>>        Map headers = (Map) mc
> >>>>
> >>>>
>  .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
> >>>>        String myHeader = (String) header.get("My-Digest-Header");
> >>>>        ...
> >>>> But I also need to get access to the body of the request (like I'd do
> >>>> using request.getInputStream() in a servlet). Any ideas if it is
> >>>> available and how I can get at it?
> >>>> Thanks,
> >>>> Garth
> >>>>
> >>>
> >>>
> >>>
> >>> --
> >>> Ruwan Linton
> >>> http://www.wso2.org - "Oxygenating the Web Services Platform"
> >>
> >>
> >>
> >>
> >> --
> >> Ruwan Linton
> >> http://www.wso2.org - "Oxygenating the Web Services Platform"
> >>
> >
>
>
>
> --
> Paul Fremantle
> Co-Founder and CTO, WSO2
> Apache Synapse PMC Chair
> OASIS WS-RX TC Co-chair
>
> blog: http://pzf.fremantle.org
> paul@wso2.com
>
> "Oxygenating the Web Service Platform", www.wso2.com
>



-- 
Ruwan Linton
http://www.wso2.org - "Oxygenating the Web Services Platform"

Re: mediator access to request body?

Posted by Paul Fremantle <pz...@gmail.com>.
Garth

Are you looking for the XML infoset or the actual bytes of the
message? StAX and Synapse are designed to support exact access to the
XML infoset. If you get the StAX stream from the body before you do
any manipulation to it, then I believe that you can get a genuine
unmodified representation from that.

Paul

On Tue, May 20, 2008 at 2:33 AM, Garth Patil <ga...@gmail.com> wrote:
> Hi Ruwan,
> I need a byte-accurate representation of the body because my
> requirement is to validate the message authenticity using a keyed-hash
> message authentication code.
> For example, a client would sign the request by placing a value in the
> header that is the result of hashing the request body along with a
> shared secret key. In order to create a mediator that can accurately
> reproduce the keyed-hash message authentication code, the server must
> have the same bytes from the request as the client, not a
> representation of it.
> Given that, it sounds like I should access the data handler as I would
> a binary message. How do I do that in Synapse?
> Thanks,
> Garth
>
> On Mon, May 19, 2008 at 6:24 PM, Ruwan Linton <ru...@gmail.com> wrote:
>> At the same time could you please elaborate a bit on your requirement? why
>> you need the request body as an InputStream?
>>
>> Thanks,
>> Ruwan
>>
>> On Tue, May 20, 2008 at 6:53 AM, Ruwan Linton <ru...@gmail.com>
>> wrote:
>>
>>> Hi Garth,
>>>
>>> If you want to retrieve the message body as an input stream, no you cannot
>>> retrieve the input stream but just the built message as xml in which case;
>>>
>>> synCtx.getEnvelope() will give you the envelope.
>>>
>>> If you are referring to a binary message (non xml/non text, binary data)
>>> then you can access the request stream by getting the access to the data
>>> handler in the payload of the envelope. If what you are referring to is this
>>> please do let me know, so that I can provide you with more information on
>>> this.
>>>
>>> Thanks,
>>> Ruwan
>>>
>>>
>>> On Tue, May 20, 2008 at 6:31 AM, Garth Patil <ga...@gmail.com> wrote:
>>>
>>>> Hi All,
>>>> I am trying to write an mediator that needs access to the underlying
>>>> body of the request (in order to verify message authenticity using a
>>>> header). I can get the header like this:
>>>> public boolean mediate(MessageContext synCtx) {
>>>>        org.apache.axis2.context.MessageContext mc = ((Axis2MessageContext)
>>>> synCtx)
>>>>                        .getAxis2MessageContext();
>>>>        Map headers = (Map) mc
>>>>
>>>>  .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
>>>>        String myHeader = (String) header.get("My-Digest-Header");
>>>>        ...
>>>> But I also need to get access to the body of the request (like I'd do
>>>> using request.getInputStream() in a servlet). Any ideas if it is
>>>> available and how I can get at it?
>>>> Thanks,
>>>> Garth
>>>>
>>>
>>>
>>>
>>> --
>>> Ruwan Linton
>>> http://www.wso2.org - "Oxygenating the Web Services Platform"
>>
>>
>>
>>
>> --
>> Ruwan Linton
>> http://www.wso2.org - "Oxygenating the Web Services Platform"
>>
>



-- 
Paul Fremantle
Co-Founder and CTO, WSO2
Apache Synapse PMC Chair
OASIS WS-RX TC Co-chair

blog: http://pzf.fremantle.org
paul@wso2.com

"Oxygenating the Web Service Platform", www.wso2.com

Re: mediator access to request body?

Posted by Garth Patil <ga...@gmail.com>.
Hi All,
Thanks for the feedback. Not having access to the XML content would be
unacceptable. I'll take a look at extending a message builder.
Thanks again,
Garth

On Tue, May 20, 2008 at 5:24 AM, Andreas Veithen
<an...@skynet.be> wrote:
> Ruwan,
>
> This would imply that you have to register BinaryBuilder for all incoming
> SOAP or XML messages. But then you will no longer be able to access the XML
> content which means that you can only do very limited mediation.
>
> I think a better approach would be to write some sort of message builder
> proxy/wrapper that calculates the hash and then delegates the decoding of
> the message to an existing message builder (SOAPBuilder or
> ApplicationXMLBuilder in our case). This proxy/wrapper would then be
> registered in the Axis2 configuration.
>
> Andreas
>
> Quoting Ruwan Linton <ru...@gmail.com>:
>
>> Hi Garth,
>>
>> Please have a look at the BinaryFormatter and the BinaryBuilder, you will
>> have to use the BinaryBuilder as the message builder in the axis2.xml,
>>
>> here is how you could retrieve the data handler,
>>
>> private DataHandler getDataHandler(MessageContext messageContext) {
>>        OMElement firstChild =
>> messageContext.getEnvelope().getBody().getFirstElement();
>>        if
>> (BaseConstants.DEFAULT_BINARY_WRAPPER.equals(firstChild.getQName())) {
>>            OMNode omNode = firstChild.getFirstOMChild();
>>            if (omNode != null && omNode instanceof OMText) {
>>                Object dh = ((OMText)omNode).getDataHandler();
>>                if (dh != null && dh instanceof DataHandler) {
>>                    return (DataHandler)dh;
>>                }
>>            }
>>        }
>>        return null;
>>    }
>>
>> then the input stream can be retrieved by;
>>
>> getDataHandler().getDataSource().getInputStream()
>>
>> Thanks,
>> Ruwan
>>
>> On Tue, May 20, 2008 at 7:03 AM, Garth Patil <ga...@gmail.com> wrote:
>>
>>> Hi Ruwan,
>>> I need a byte-accurate representation of the body because my
>>> requirement is to validate the message authenticity using a keyed-hash
>>> message authentication code.
>>> For example, a client would sign the request by placing a value in the
>>> header that is the result of hashing the request body along with a
>>> shared secret key. In order to create a mediator that can accurately
>>> reproduce the keyed-hash message authentication code, the server must
>>> have the same bytes from the request as the client, not a
>>> representation of it.
>>> Given that, it sounds like I should access the data handler as I would
>>> a binary message. How do I do that in Synapse?
>>> Thanks,
>>> Garth
>>>
>>> On Mon, May 19, 2008 at 6:24 PM, Ruwan Linton <ru...@gmail.com>
>>> wrote:
>>> > At the same time could you please elaborate a bit on your requirement?
>>> why
>>> > you need the request body as an InputStream?
>>> >
>>> > Thanks,
>>> > Ruwan
>>> >
>>> > On Tue, May 20, 2008 at 6:53 AM, Ruwan Linton <ru...@gmail.com>
>>> > wrote:
>>> >
>>> >> Hi Garth,
>>> >>
>>> >> If you want to retrieve the message body as an input stream, no you
>>> cannot
>>> >> retrieve the input stream but just the built message as xml in which
>>> case;
>>> >>
>>> >> synCtx.getEnvelope() will give you the envelope.
>>> >>
>>> >> If you are referring to a binary message (non xml/non text, binary
>>> >> data)
>>> >> then you can access the request stream by getting the access to the
>>> >> data
>>> >> handler in the payload of the envelope. If what you are referring to
>>> >> is
>>> this
>>> >> please do let me know, so that I can provide you with more information
>>> on
>>> >> this.
>>> >>
>>> >> Thanks,
>>> >> Ruwan
>>> >>
>>> >>
>>> >> On Tue, May 20, 2008 at 6:31 AM, Garth Patil <ga...@gmail.com>
>>> wrote:
>>> >>
>>> >>> Hi All,
>>> >>> I am trying to write an mediator that needs access to the underlying
>>> >>> body of the request (in order to verify message authenticity using a
>>> >>> header). I can get the header like this:
>>> >>> public boolean mediate(MessageContext synCtx) {
>>> >>>        org.apache.axis2.context.MessageContext mc =
>>> ((Axis2MessageContext)
>>> >>> synCtx)
>>> >>>                        .getAxis2MessageContext();
>>> >>>        Map headers = (Map) mc
>>> >>>
>>> >>>
>>>  .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
>>> >>>        String myHeader = (String) header.get("My-Digest-Header");
>>> >>>        ...
>>> >>> But I also need to get access to the body of the request (like I'd do
>>> >>> using request.getInputStream() in a servlet). Any ideas if it is
>>> >>> available and how I can get at it?
>>> >>> Thanks,
>>> >>> Garth
>>> >>>
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Ruwan Linton
>>> >> http://www.wso2.org - "Oxygenating the Web Services Platform"
>>> >
>>> >
>>> >
>>> >
>>> > --
>>> > Ruwan Linton
>>> > http://www.wso2.org - "Oxygenating the Web Services Platform"
>>> >
>>>
>>
>>
>>
>> --
>> Ruwan Linton
>> http://www.wso2.org - "Oxygenating the Web Services Platform"
>>
>
>
>
>
>

Re: mediator access to request body?

Posted by Andreas Veithen <an...@skynet.be>.
Ruwan,

This would imply that you have to register BinaryBuilder for all  
incoming SOAP or XML messages. But then you will no longer be able to  
access the XML content which means that you can only do very limited  
mediation.

I think a better approach would be to write some sort of message  
builder proxy/wrapper that calculates the hash and then delegates the  
decoding of the message to an existing message builder (SOAPBuilder or  
ApplicationXMLBuilder in our case). This proxy/wrapper would then be  
registered in the Axis2 configuration.

Andreas

Quoting Ruwan Linton <ru...@gmail.com>:

> Hi Garth,
>
> Please have a look at the BinaryFormatter and the BinaryBuilder, you will
> have to use the BinaryBuilder as the message builder in the axis2.xml,
>
> here is how you could retrieve the data handler,
>
> private DataHandler getDataHandler(MessageContext messageContext) {
>         OMElement firstChild =
> messageContext.getEnvelope().getBody().getFirstElement();
>         if
> (BaseConstants.DEFAULT_BINARY_WRAPPER.equals(firstChild.getQName())) {
>             OMNode omNode = firstChild.getFirstOMChild();
>             if (omNode != null && omNode instanceof OMText) {
>                 Object dh = ((OMText)omNode).getDataHandler();
>                 if (dh != null && dh instanceof DataHandler) {
>                     return (DataHandler)dh;
>                 }
>             }
>         }
>         return null;
>     }
>
> then the input stream can be retrieved by;
>
> getDataHandler().getDataSource().getInputStream()
>
> Thanks,
> Ruwan
>
> On Tue, May 20, 2008 at 7:03 AM, Garth Patil <ga...@gmail.com> wrote:
>
>> Hi Ruwan,
>> I need a byte-accurate representation of the body because my
>> requirement is to validate the message authenticity using a keyed-hash
>> message authentication code.
>> For example, a client would sign the request by placing a value in the
>> header that is the result of hashing the request body along with a
>> shared secret key. In order to create a mediator that can accurately
>> reproduce the keyed-hash message authentication code, the server must
>> have the same bytes from the request as the client, not a
>> representation of it.
>> Given that, it sounds like I should access the data handler as I would
>> a binary message. How do I do that in Synapse?
>> Thanks,
>> Garth
>>
>> On Mon, May 19, 2008 at 6:24 PM, Ruwan Linton <ru...@gmail.com>
>> wrote:
>> > At the same time could you please elaborate a bit on your requirement?
>> why
>> > you need the request body as an InputStream?
>> >
>> > Thanks,
>> > Ruwan
>> >
>> > On Tue, May 20, 2008 at 6:53 AM, Ruwan Linton <ru...@gmail.com>
>> > wrote:
>> >
>> >> Hi Garth,
>> >>
>> >> If you want to retrieve the message body as an input stream, no you
>> cannot
>> >> retrieve the input stream but just the built message as xml in which
>> case;
>> >>
>> >> synCtx.getEnvelope() will give you the envelope.
>> >>
>> >> If you are referring to a binary message (non xml/non text, binary data)
>> >> then you can access the request stream by getting the access to the data
>> >> handler in the payload of the envelope. If what you are referring to is
>> this
>> >> please do let me know, so that I can provide you with more information
>> on
>> >> this.
>> >>
>> >> Thanks,
>> >> Ruwan
>> >>
>> >>
>> >> On Tue, May 20, 2008 at 6:31 AM, Garth Patil <ga...@gmail.com>
>> wrote:
>> >>
>> >>> Hi All,
>> >>> I am trying to write an mediator that needs access to the underlying
>> >>> body of the request (in order to verify message authenticity using a
>> >>> header). I can get the header like this:
>> >>> public boolean mediate(MessageContext synCtx) {
>> >>>        org.apache.axis2.context.MessageContext mc =
>> ((Axis2MessageContext)
>> >>> synCtx)
>> >>>                        .getAxis2MessageContext();
>> >>>        Map headers = (Map) mc
>> >>>
>> >>>
>>  .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
>> >>>        String myHeader = (String) header.get("My-Digest-Header");
>> >>>        ...
>> >>> But I also need to get access to the body of the request (like I'd do
>> >>> using request.getInputStream() in a servlet). Any ideas if it is
>> >>> available and how I can get at it?
>> >>> Thanks,
>> >>> Garth
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> Ruwan Linton
>> >> http://www.wso2.org - "Oxygenating the Web Services Platform"
>> >
>> >
>> >
>> >
>> > --
>> > Ruwan Linton
>> > http://www.wso2.org - "Oxygenating the Web Services Platform"
>> >
>>
>
>
>
> --
> Ruwan Linton
> http://www.wso2.org - "Oxygenating the Web Services Platform"
>





Re: mediator access to request body?

Posted by Ruwan Linton <ru...@gmail.com>.
Hi Garth,

Please have a look at the BinaryFormatter and the BinaryBuilder, you will
have to use the BinaryBuilder as the message builder in the axis2.xml,

here is how you could retrieve the data handler,

private DataHandler getDataHandler(MessageContext messageContext) {
        OMElement firstChild =
messageContext.getEnvelope().getBody().getFirstElement();
        if
(BaseConstants.DEFAULT_BINARY_WRAPPER.equals(firstChild.getQName())) {
            OMNode omNode = firstChild.getFirstOMChild();
            if (omNode != null && omNode instanceof OMText) {
                Object dh = ((OMText)omNode).getDataHandler();
                if (dh != null && dh instanceof DataHandler) {
                    return (DataHandler)dh;
                }
            }
        }
        return null;
    }

then the input stream can be retrieved by;

getDataHandler().getDataSource().getInputStream()

Thanks,
Ruwan

On Tue, May 20, 2008 at 7:03 AM, Garth Patil <ga...@gmail.com> wrote:

> Hi Ruwan,
> I need a byte-accurate representation of the body because my
> requirement is to validate the message authenticity using a keyed-hash
> message authentication code.
> For example, a client would sign the request by placing a value in the
> header that is the result of hashing the request body along with a
> shared secret key. In order to create a mediator that can accurately
> reproduce the keyed-hash message authentication code, the server must
> have the same bytes from the request as the client, not a
> representation of it.
> Given that, it sounds like I should access the data handler as I would
> a binary message. How do I do that in Synapse?
> Thanks,
> Garth
>
> On Mon, May 19, 2008 at 6:24 PM, Ruwan Linton <ru...@gmail.com>
> wrote:
> > At the same time could you please elaborate a bit on your requirement?
> why
> > you need the request body as an InputStream?
> >
> > Thanks,
> > Ruwan
> >
> > On Tue, May 20, 2008 at 6:53 AM, Ruwan Linton <ru...@gmail.com>
> > wrote:
> >
> >> Hi Garth,
> >>
> >> If you want to retrieve the message body as an input stream, no you
> cannot
> >> retrieve the input stream but just the built message as xml in which
> case;
> >>
> >> synCtx.getEnvelope() will give you the envelope.
> >>
> >> If you are referring to a binary message (non xml/non text, binary data)
> >> then you can access the request stream by getting the access to the data
> >> handler in the payload of the envelope. If what you are referring to is
> this
> >> please do let me know, so that I can provide you with more information
> on
> >> this.
> >>
> >> Thanks,
> >> Ruwan
> >>
> >>
> >> On Tue, May 20, 2008 at 6:31 AM, Garth Patil <ga...@gmail.com>
> wrote:
> >>
> >>> Hi All,
> >>> I am trying to write an mediator that needs access to the underlying
> >>> body of the request (in order to verify message authenticity using a
> >>> header). I can get the header like this:
> >>> public boolean mediate(MessageContext synCtx) {
> >>>        org.apache.axis2.context.MessageContext mc =
> ((Axis2MessageContext)
> >>> synCtx)
> >>>                        .getAxis2MessageContext();
> >>>        Map headers = (Map) mc
> >>>
> >>>
>  .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
> >>>        String myHeader = (String) header.get("My-Digest-Header");
> >>>        ...
> >>> But I also need to get access to the body of the request (like I'd do
> >>> using request.getInputStream() in a servlet). Any ideas if it is
> >>> available and how I can get at it?
> >>> Thanks,
> >>> Garth
> >>>
> >>
> >>
> >>
> >> --
> >> Ruwan Linton
> >> http://www.wso2.org - "Oxygenating the Web Services Platform"
> >
> >
> >
> >
> > --
> > Ruwan Linton
> > http://www.wso2.org - "Oxygenating the Web Services Platform"
> >
>



-- 
Ruwan Linton
http://www.wso2.org - "Oxygenating the Web Services Platform"

Re: mediator access to request body?

Posted by Garth Patil <ga...@gmail.com>.
Hi Ruwan,
I need a byte-accurate representation of the body because my
requirement is to validate the message authenticity using a keyed-hash
message authentication code.
For example, a client would sign the request by placing a value in the
header that is the result of hashing the request body along with a
shared secret key. In order to create a mediator that can accurately
reproduce the keyed-hash message authentication code, the server must
have the same bytes from the request as the client, not a
representation of it.
Given that, it sounds like I should access the data handler as I would
a binary message. How do I do that in Synapse?
Thanks,
Garth

On Mon, May 19, 2008 at 6:24 PM, Ruwan Linton <ru...@gmail.com> wrote:
> At the same time could you please elaborate a bit on your requirement? why
> you need the request body as an InputStream?
>
> Thanks,
> Ruwan
>
> On Tue, May 20, 2008 at 6:53 AM, Ruwan Linton <ru...@gmail.com>
> wrote:
>
>> Hi Garth,
>>
>> If you want to retrieve the message body as an input stream, no you cannot
>> retrieve the input stream but just the built message as xml in which case;
>>
>> synCtx.getEnvelope() will give you the envelope.
>>
>> If you are referring to a binary message (non xml/non text, binary data)
>> then you can access the request stream by getting the access to the data
>> handler in the payload of the envelope. If what you are referring to is this
>> please do let me know, so that I can provide you with more information on
>> this.
>>
>> Thanks,
>> Ruwan
>>
>>
>> On Tue, May 20, 2008 at 6:31 AM, Garth Patil <ga...@gmail.com> wrote:
>>
>>> Hi All,
>>> I am trying to write an mediator that needs access to the underlying
>>> body of the request (in order to verify message authenticity using a
>>> header). I can get the header like this:
>>> public boolean mediate(MessageContext synCtx) {
>>>        org.apache.axis2.context.MessageContext mc = ((Axis2MessageContext)
>>> synCtx)
>>>                        .getAxis2MessageContext();
>>>        Map headers = (Map) mc
>>>
>>>  .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
>>>        String myHeader = (String) header.get("My-Digest-Header");
>>>        ...
>>> But I also need to get access to the body of the request (like I'd do
>>> using request.getInputStream() in a servlet). Any ideas if it is
>>> available and how I can get at it?
>>> Thanks,
>>> Garth
>>>
>>
>>
>>
>> --
>> Ruwan Linton
>> http://www.wso2.org - "Oxygenating the Web Services Platform"
>
>
>
>
> --
> Ruwan Linton
> http://www.wso2.org - "Oxygenating the Web Services Platform"
>

Re: mediator access to request body?

Posted by Ruwan Linton <ru...@gmail.com>.
At the same time could you please elaborate a bit on your requirement? why
you need the request body as an InputStream?

Thanks,
Ruwan

On Tue, May 20, 2008 at 6:53 AM, Ruwan Linton <ru...@gmail.com>
wrote:

> Hi Garth,
>
> If you want to retrieve the message body as an input stream, no you cannot
> retrieve the input stream but just the built message as xml in which case;
>
> synCtx.getEnvelope() will give you the envelope.
>
> If you are referring to a binary message (non xml/non text, binary data)
> then you can access the request stream by getting the access to the data
> handler in the payload of the envelope. If what you are referring to is this
> please do let me know, so that I can provide you with more information on
> this.
>
> Thanks,
> Ruwan
>
>
> On Tue, May 20, 2008 at 6:31 AM, Garth Patil <ga...@gmail.com> wrote:
>
>> Hi All,
>> I am trying to write an mediator that needs access to the underlying
>> body of the request (in order to verify message authenticity using a
>> header). I can get the header like this:
>> public boolean mediate(MessageContext synCtx) {
>>        org.apache.axis2.context.MessageContext mc = ((Axis2MessageContext)
>> synCtx)
>>                        .getAxis2MessageContext();
>>        Map headers = (Map) mc
>>
>>  .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
>>        String myHeader = (String) header.get("My-Digest-Header");
>>        ...
>> But I also need to get access to the body of the request (like I'd do
>> using request.getInputStream() in a servlet). Any ideas if it is
>> available and how I can get at it?
>> Thanks,
>> Garth
>>
>
>
>
> --
> Ruwan Linton
> http://www.wso2.org - "Oxygenating the Web Services Platform"




-- 
Ruwan Linton
http://www.wso2.org - "Oxygenating the Web Services Platform"

Re: mediator access to request body?

Posted by Ruwan Linton <ru...@gmail.com>.
Hi Garth,

If you want to retrieve the message body as an input stream, no you cannot
retrieve the input stream but just the built message as xml in which case;

synCtx.getEnvelope() will give you the envelope.

If you are referring to a binary message (non xml/non text, binary data)
then you can access the request stream by getting the access to the data
handler in the payload of the envelope. If what you are referring to is this
please do let me know, so that I can provide you with more information on
this.

Thanks,
Ruwan

On Tue, May 20, 2008 at 6:31 AM, Garth Patil <ga...@gmail.com> wrote:

> Hi All,
> I am trying to write an mediator that needs access to the underlying
> body of the request (in order to verify message authenticity using a
> header). I can get the header like this:
> public boolean mediate(MessageContext synCtx) {
>        org.apache.axis2.context.MessageContext mc = ((Axis2MessageContext)
> synCtx)
>                        .getAxis2MessageContext();
>        Map headers = (Map) mc
>
>  .getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
>        String myHeader = (String) header.get("My-Digest-Header");
>        ...
> But I also need to get access to the body of the request (like I'd do
> using request.getInputStream() in a servlet). Any ideas if it is
> available and how I can get at it?
> Thanks,
> Garth
>



-- 
Ruwan Linton
http://www.wso2.org - "Oxygenating the Web Services Platform"