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()));
String saveMsgText = "";
if (persist == SAVE_AND_PERSIST) {
// Simulate saving the message so that it can be fully rebuilt.
saveMsgText = m.getAsOMElement().toString();
}
Object customBuiltObject = null;
if (installJAXBCustomBuilder) {
OMElement om = m.getAsOMElement();
om = ((org.apache.axiom.soap.SOAPEnvelope) om).getBody().getFirstElement();
if (om instanceof OMSourcedElement &&
((OMSourcedElement) om).getDataSource() instanceof JAXBDataSource) {
customBuiltObject = ((JAXBDataSource) ((OMSourcedElement) om).getDataSource()).getObject();
}
}
// Get the BlockFactory
JAXBBlockFactory bf = (JAXBBlockFactory)
FactoryRegistry.getFactory(JAXBBlockFactory.class);
// Create the JAXBContext instance that will be used
// to deserialize the JAX-B object content in the message.
JAXBBlockContext context =
new JAXBBlockContext(EchoStringResponse.class.getPackage().getName());
// Get the JAXBBlock that wraps the content
Block b = m.getBodyBlock(context, bf);
// 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.
isFault = m.isFault();
assertTrue(!isFault);
assertTrue("XMLPart Representation is " + m.getXMLPartContentType(),
"SPINE".equals(m.getXMLPartContentType()));
// Get the business object from the block, which should be a
// JAX-B object
Object bo = b.getBusinessObject(false);
m.setPostPivot();
// Simulate restoring the message
if (persist == SAVE_AND_PERSIST) {
sr = new StringReader(saveMsgText);
XMLStreamReader saveMsgReader = inputFactory.createXMLStreamReader(sr);
builder = new StAXSOAPModelBuilder(saveMsgReader, null);
omElement = builder.getSOAPEnvelope();
m = mf.createFrom(omElement, null);
}
if (installJAXBCustomBuilder) {
// If installed jaxb custom builder, then custom built object should be same object as the business object
assertTrue (customBuiltObject == bo);