StringReader sr = new StringReader(sampleJAXBEnvelope);
XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null);
OMElement omElement = builder.getSOAPEnvelope();
JAXBDSContext jds = null;
if (installJAXBCustomBuilder) {
jds = new JAXBDSContext(EchoStringResponse.class.getPackage().getName());
JAXBCustomBuilder jcb = new JAXBCustomBuilder(jds);
builder.registerCustomBuilderForPayload(jcb);
}
// Create a SOAP 1.1 Message from the sample incoming XML
MessageFactory mf = (MessageFactory)
FactoryRegistry.getFactory(MessageFactory.class);
Message m = mf.createFrom(omElement, null);
// Check to see if the message is a fault. The client/server will always call this method.
// The Message must respond appropriately without doing a conversion.
boolean isFault = m.isFault();
assertTrue(!isFault);
assertTrue("XMLPart Representation is " + m.getXMLPartContentType(),
"OM".equals(m.getXMLPartContentType()));
if (installJAXBCustomBuilder) {
// The JAXBDSContext and the JAXBUtils access the JAXBContext
// for the "test" package.
// The JAXBContext creation is very expensive.
// However the JAXBContext can also be very large.
//
// For these reasons, the JAXBUtils code caches the JAXBContext values.
// And, the JAXBDSContext and JAXBUtils code use WeakReferences to refer
// to the JAXBContext (so that it is easily gc'd).
// The following code checks makes sure that the caching and gc is correct.
// Get the JAXBContext
JAXBContext context = jds.getJAXBContext();
// Get the identity hash code. This is an indicator of the unique memory pointer
// for the context.
int contextPointer = System.identityHashCode(context);