You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Marian Muller <ma...@serli.com> on 2010/11/17 16:23:06 UTC
Replacing the response message
Hello again,
I would like some help with a client-side inbound interceptor. I am trying,
within an interceptor at phase PRE_PROTOCOL, to replace the received
response with a forged one. The forged response is a standard SOAPMessage.
I tried replacing the InMessage in the exchange, but it does not seem to
work: the former response is used instead of the forged one.
SOAPMessage response = // get the forged response somewhere
//this.currentMessage.getInterceptorChain().abort();
Endpoint e =
this.currentMessage.getExchange().get(Endpoint.class);
if (!this.currentMessage.getExchange().isOneWay()) {
Message responseMsg = new MessageImpl();
responseMsg.setExchange(this.currentMessage.getExchange());
responseMsg = e.getBinding().createMessage(responseMsg);
this.currentMessage.getExchange().setInMessage(responseMsg);
responseMsg.setContent(SOAPMessage.class, response);
InterceptorChain chain = /*OutgoingChainInterceptor
.getOutInterceptorChain(this.currentMessage.getExchange());*/
this.currentMessage.getInterceptorChain();
responseMsg.setInterceptorChain(chain);
/*chain.doInterceptStartingAfter(responseMsg,
SoapPreProtocolOutInterceptor.class.getName());*/
logger.error("doIntercept() ON THE NEW RESPONSE");
chain.doIntercept(responseMsg);
logger.error("ABORT INTERCEPTION OF THE OLD RESPONSE");
this.currentMessage.getInterceptorChain().abort();
logger.error("ENDING...");
}
Thank you for your help.
--
Marian MULLER
SERLI
Re: Replacing the response message
Posted by Daniel Kulp <dk...@apache.org>.
On Wednesday 17 November 2010 10:23:06 am Marian Muller wrote:
> Hello again,
>
> I would like some help with a client-side inbound interceptor. I am trying,
> within an interceptor at phase PRE_PROTOCOL, to replace the received
> response with a forged one. The forged response is a standard SOAPMessage.
>
> I tried replacing the InMessage in the exchange, but it does not seem to
> work: the former response is used instead of the forged one.
This is close, I think. You probably need:
responseMsg.setInterceptorChain(chain);
chain.reset(); //reset the iterator
chain.doIntercept(responseMsg);
// no need for this - chain.getInterceptorChain().abort();
That said, you'll probably need to setup a LOT more things for the message.
It will likely need an InputStream (not a SOAPMessage), a set of
PROTOCOL_HEADER things for the headers, etc...
Dan
>
>
> SOAPMessage response = // get the forged response somewhere
>
> //this.currentMessage.getInterceptorChain().abort();
> Endpoint e =
> this.currentMessage.getExchange().get(Endpoint.class);
> if (!this.currentMessage.getExchange().isOneWay()) {
> Message responseMsg = new MessageImpl();
> responseMsg.setExchange(this.currentMessage.getExchange());
> responseMsg = e.getBinding().createMessage(responseMsg);
>
> this.currentMessage.getExchange().setInMessage(responseMsg);
>
> responseMsg.setContent(SOAPMessage.class, response);
>
> InterceptorChain chain = /*OutgoingChainInterceptor
>
> .getOutInterceptorChain(this.currentMessage.getExchange());*/
> this.currentMessage.getInterceptorChain();
> responseMsg.setInterceptorChain(chain);
> /*chain.doInterceptStartingAfter(responseMsg,
> SoapPreProtocolOutInterceptor.class.getName());*/
> logger.error("doIntercept() ON THE NEW RESPONSE");
> chain.doIntercept(responseMsg);
> logger.error("ABORT INTERCEPTION OF THE OLD RESPONSE");
> this.currentMessage.getInterceptorChain().abort();
> logger.error("ENDING...");
> }
>
>
> Thank you for your help.
> --
> Marian MULLER
> SERLI
--
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog
Re: Replacing the response message
Posted by Marian Muller <ma...@serli.com>.
Sorry, the mail was sent before i could clean the code extract:
SOAPMessage response = // get the forged response
// Create a new CXF message and link it to the exchange
Endpoint e =
this.currentMessage.getExchange().get(Endpoint.class);
Message responseMsg = new MessageImpl();
responseMsg.setExchange(this.currentMessage.getExchange());
responseMsg = e.getBinding().createMessage(responseMsg);
this.currentMessage.getExchange().setInMessage(responseMsg);
// Put the forged SOAPMessage in the new CXF message
responseMsg.setContent(SOAPMessage.class, response);
// Continue the execution of the interceptor chain on the new
message
InterceptorChain chain =
this.currentMessage.getInterceptorChain();
responseMsg.setInterceptorChain(chain);
chain.doIntercept(responseMsg);
// Cancel the execution of the interceptor chain on the former
message
this.currentMessage.getInterceptorChain().abort();
Thanks
--
Marian MULLER
SERLI
On Wed, Nov 17, 2010 at 4:23 PM, Marian Muller <ma...@serli.com>wrote:
> Hello again,
>
> I would like some help with a client-side inbound interceptor. I am trying,
> within an interceptor at phase PRE_PROTOCOL, to replace the received
> response with a forged one. The forged response is a standard SOAPMessage.
>
> I tried replacing the InMessage in the exchange, but it does not seem to
> work: the former response is used instead of the forged one.
>
>
> SOAPMessage response = // get the forged response somewhere
>
> //this.currentMessage.getInterceptorChain().abort();
> Endpoint e =
> this.currentMessage.getExchange().get(Endpoint.class);
> if (!this.currentMessage.getExchange().isOneWay()) {
> Message responseMsg = new MessageImpl();
> responseMsg.setExchange(this.currentMessage.getExchange());
> responseMsg = e.getBinding().createMessage(responseMsg);
>
> this.currentMessage.getExchange().setInMessage(responseMsg);
>
> responseMsg.setContent(SOAPMessage.class, response);
>
> InterceptorChain chain = /*OutgoingChainInterceptor
>
> .getOutInterceptorChain(this.currentMessage.getExchange());*/
> this.currentMessage.getInterceptorChain();
> responseMsg.setInterceptorChain(chain);
> /*chain.doInterceptStartingAfter(responseMsg,
> SoapPreProtocolOutInterceptor.class.getName());*/
> logger.error("doIntercept() ON THE NEW RESPONSE");
> chain.doIntercept(responseMsg);
> logger.error("ABORT INTERCEPTION OF THE OLD RESPONSE");
> this.currentMessage.getInterceptorChain().abort();
> logger.error("ENDING...");
> }
>
>
> Thank you for your help.
> --
> Marian MULLER
> SERLI
>