You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Sonoerin <hu...@yahoo.com> on 2012/06/26 16:27:18 UTC

Interceptor capture of SOAP request

Good day,

Is there anyway to capture a SOAP request that causes a Unmarshall
Exception?  I created a fault interceptor that fires off when the exception
occurs, but I have not been able to figure out how to capture the actual
request so I can store it on the file system.  I have tried various parent
interceptors and various phases, but I only get partial request at best

Here is my attempt:
p/ublic class MyFaultInterceptor extends AbstractSoapInterceptor { 

public MyFaultInterceptor() {
        super(Phase.POST_PROTOCOL);  // MARSHAL seems more promising?
    }

@Override
    public void handleMessage(SoapMessage message) throws Fault {

        if (message instanceof SoapMessage) {
            LOGGER.error("MyFaultInterceptor Invoked ");
            try {
                Exchange exchange = message.getExchange();
                if (exchange != null) {
                    SoapMessage exMessage = (SoapMessage)
exchange.getInMessage();
                    InputStream inmessage =
exMessage.getContent(InputStream.class);
                    String payload =
MyRestUtilities.extractStringFromPayload(inmessage);

                    savePayloadToFile(payload);
                }
            } catch (Exception e) {
                LOGGER.error(e.getMessage());
            }
        }
    }/

And here is how I invoke it:
/<cxf:jaxws-service serviceClass="my.WebService" validationEnabled="false">
   
	<cxf:outFaultInterceptors>
		<spring:bean id="faultInterceptor" class="MyFaultInterceptor"/>					
	</cxf:outFaultInterceptors>
</cxf:jaxws-service>/

This has been driving me nuts and I have not found a way to extract the
actual request (headers optional) into a string so I can write to a file.



--
View this message in context: http://cxf.547215.n5.nabble.com/Interceptor-capture-of-SOAP-request-tp5710324.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Interceptor capture of SOAP request

Posted by Aki Yoshida <el...@googlemail.com>.
The problem with your approach is that the original input stream of
the request message is already gone/consumed when the control lands on
the fault chain.

One idea would be to use a similar message capturing approach used by
the logging interceptor in the in-chain but instead of always writing
out the captured message after the stream is consumed, keep its
reference in the exchange so that you can write it out from your fault
handler when the control reaches there. In this approach, you would
need another interceptor in the normal out-chain to clean up any
temporary resource associated with this reference.

regards, aki

2012/6/26 Sonoerin <hu...@yahoo.com>:
> Good day,
>
> Is there anyway to capture a SOAP request that causes a Unmarshall
> Exception?  I created a fault interceptor that fires off when the exception
> occurs, but I have not been able to figure out how to capture the actual
> request so I can store it on the file system.  I have tried various parent
> interceptors and various phases, but I only get partial request at best
>
> Here is my attempt:
> p/ublic class MyFaultInterceptor extends AbstractSoapInterceptor {
>
> public MyFaultInterceptor() {
>         super(Phase.POST_PROTOCOL);  // MARSHAL seems more promising?
>     }
>
> @Override
>     public void handleMessage(SoapMessage message) throws Fault {
>
>         if (message instanceof SoapMessage) {
>             LOGGER.error("MyFaultInterceptor Invoked ");
>             try {
>                 Exchange exchange = message.getExchange();
>                 if (exchange != null) {
>                     SoapMessage exMessage = (SoapMessage)
> exchange.getInMessage();
>                     InputStream inmessage =
> exMessage.getContent(InputStream.class);
>                     String payload =
> MyRestUtilities.extractStringFromPayload(inmessage);
>
>                     savePayloadToFile(payload);
>                 }
>             } catch (Exception e) {
>                 LOGGER.error(e.getMessage());
>             }
>         }
>     }/
>
> And here is how I invoke it:
> /<cxf:jaxws-service serviceClass="my.WebService" validationEnabled="false">
>
>         <cxf:outFaultInterceptors>
>                 <spring:bean id="faultInterceptor" class="MyFaultInterceptor"/>
>         </cxf:outFaultInterceptors>
> </cxf:jaxws-service>/
>
> This has been driving me nuts and I have not found a way to extract the
> actual request (headers optional) into a string so I can write to a file.
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/Interceptor-capture-of-SOAP-request-tp5710324.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: Interceptor capture of SOAP request

Posted by Sonoerin <hu...@yahoo.com>.
Thank you Kartheek,

I am able to have my interceptor invoked via:


<cxf:jaxws-service serviceClass="my.WebService" validationEnabled="false">   
        <cxf:outFaultInterceptors>
                <spring:bean id="faultInterceptor"
class="MyFaultInterceptor"/>                                        
        </cxf:outFaultInterceptors>
</cxf:jaxws-service>


However, I am unable to actually retrieve the complete SOAP contents.  As I
only want to handle this on Fault, and not logging every request I am not
sure at which phase and with which Interceptor to use.  Do I use
AbstractSoapInterceptor, AbstractPhaseInterceptor, or another?  At what
phase is the soap request available to me?

thank you again for your help,



Hi Sonoerin,

If you are using spring and have not tried this yet,there is a way to log
the inbound/outbound SOAP messages.It is detailed in the below link.It
should also be implementable via the API as well.

http://cxf.apache.org/docs/configuration.html

check this section(Enabling message logging using plain Spring bean
elements)



Saludos
Kartheek


--
View this message in context: http://cxf.547215.n5.nabble.com/Interceptor-capture-of-SOAP-request-tp5710324p5710345.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: Interceptor capture of SOAP request

Posted by kdesin <ka...@gmail.com>.
Hi Sonoerin,

If you are using spring and have not tried this yet,there is a way to log
the inbound/outbound SOAP messages.It is detailed in the below link.It
should also be implementable via the API as well.

http://cxf.apache.org/docs/configuration.html

check this section(Enabling message logging using plain Spring bean
elements)



Saludos
Kartheek

-----
Saludos
Kartheek
--
View this message in context: http://cxf.547215.n5.nabble.com/Interceptor-capture-of-SOAP-request-tp5710324p5710335.html
Sent from the cxf-user mailing list archive at Nabble.com.