Getting location from XMLStreamReader

964 Views Asked by At

I'm working on a streaming SOAP-proxy that will be used for authentication and routing. Proxy must read and validate credentials and routing information from the SOAP header. It also must enrich the SOAP header with additional metadata that is consumed by the target services.

I first wrapped up a quick proof of concept using StAX (XMLStreamReader and XMLStreamWriter). It seemed to work without issues, so concept was proven, but performance was not what I was exepcting. While profiling the prototype I noticed that application spent considerable amount of cpu time on character encoding/decoding (30-80%)

I thought the solution would be simple:

  • Store data read by XMLStreamReader from InputStream to a buffer
  • Get the offset right before SOAP header's end tag (getLocation())
  • Send data from buffer until offset is reached
  • Send additional data
  • Send remaining data from buffer
  • Send data from InputStream

This would avoid all the unneccessary encoding/decoding. However to my surprise, I found that standard implementation does not support getLocation() - it returns -1.

Obsolete section - following does NOT actually work because XMLStreamReader consumes ridiculous amounts of memory when reading a byte at time. "I noticed that I can get the offset from InputStream, if I write a InputStreamReader that returns one byte at a time and tracks number of bytes read. This however doesn't feel like the right solution - absurd number of read calls will most likely cause greater performance hit than the extra decoding/encoding."

What are my options here, if writing custom parser is out of the question? Is there a standard compliant XMLStreamReader implementation that is both proven and supports the getLocation()?

0

There are 0 best solutions below