public void testOMElementDispatchWithParsedEntityReader() throws Exception {
// Subsitute a ParsedEntityReader that will provide the
// payload InputStream. This simulates parsers that provide this
// feature.
ParsedEntityReaderFactory factory = (ParsedEntityReaderFactory)
FactoryRegistry.getFactory(ParsedEntityReaderFactory.class);
ParsedEntityReader per = new ParsedEntityReaderTest();
factory.setParsetEntityReader(per);
try {
// Create the JAX-WS client needed to send the request
Service service = Service.create(QNAME_SERVICE);
service.addPort(QNAME_PORT, SOAPBinding.SOAP12HTTP_BINDING, URL_ENDPOINT);
Dispatch<OMElement> dispatch = service.createDispatch(
QNAME_PORT, OMElement.class, Mode.MESSAGE);
// Create the OMElement object with the payload contents. Since
// we're in PAYLOAD mode, we don't have to worry about the envelope.
StringReader sr = new StringReader(sampleEnvelope);
XMLStreamReader inputReader = inputFactory.createXMLStreamReader(sr);
StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inputReader, null);
SOAPEnvelope soap12Envelope = (SOAPEnvelope) builder.getDocumentElement();
// Invoke
OMElement response = dispatch.invoke(soap12Envelope);
SOAPEnvelope responseEnv = (SOAPEnvelope) response;
SOAPBody responseBody = responseEnv.getBody();
OMElement payload = responseBody.getFirstElement();
// At this point, the payload should be an OMSourcedElement
// that was created from the ParsedEntityReader's stream
assertTrue(payload instanceof OMSourcedElement);
// Check to make sure the contents of the message are correct
String responseText = payload.toStringWithConsume();
assertTrue(responseText.contains("TEST RESPONSE"));
} finally {
// Uninstall the Test ParsedEntityReader
factory.setParsetEntityReader(null);
}
}