简体   繁体   中英

How to intercept and tamper HTTP responses with Java?

I have a Java application performing different http requests which I don't control directly (SOAP requests via Jaxws generated client). I have some difficulties with BOM flags in front of the XML prolog which I want to avoid currently. I would like to intercept the HTTP response and tamper with it before I let javax.xml parse the correct SOAP envelope.

Now to my question: How can I elegantly intercept any HTTP response with Java without the need of Fiddler or any other proxy?
Can I implement something like a proxy class and register it in the HTTP connection factory?
Would it be possible to implement a "real" http proxy doing the cleaning work for me?

I'm using org.codehaus.mojo:jaxws-maven-plugin:2.4.1 with Maven to create the stubs from WSDL.

Important: I only control the client, not the server. Therefore I can only make Java accept/parse the BOM flag in front of the response envelope or filter it out so that javax.xml can parse it normally.

You may use cxf interceptors. They should allow you to process the message in any phase of the input chain. They are well described here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM