messagetests.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 886 行 · 第 1/3 页
JAVA
886 行
assertTrue("XMLPart Representation is " + m.getXMLPartContentType(),
"SOAPENVELOPE".equals(m.getXMLPartContentType()));
// Normally the handler would not touch the body...but for our scenario, assume that it does.
// The whitespace is not preserved, so there should be no first child in the body
assertTrue(soapEnvelope.getBody().getFirstChild() == null);
// The block should be consumed at this point
assertTrue(block.isConsumed());
// After the handler processing the message is obtained as an OM
OMElement om = m.getAsOMElement();
// Serialize the Envelope using the same mechanism as the
// HTTP client.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
om.serializeAndConsume(baos, new OMOutputFormat());
// To check that the output is correct, get the String contents of the
// reader
String newText = baos.toString();
TestLogger.logger.debug(newText);
assertTrue(newText.contains("soap"));
assertTrue(newText.contains("Envelope"));
assertTrue(newText.contains("Body"));
}
/**
* Create a Block representing an XMLString with 2 elements and simulate a
* normal Dispatch<String> flow with an application handler.
* @throws Exception
*
* @REVIEW This test is disabled because (a) it fails and (b) we don't believe this
* is allowed due by WSI.
*/
public void _testStringOutflowDoubleElement() throws Exception {
// Create a SOAP 1.1 Message
MessageFactory mf = (MessageFactory)
FactoryRegistry.getFactory(MessageFactory.class);
Message m = mf.create(Protocol.soap11);
// Get the BlockFactory
XMLStringBlockFactory f = (XMLStringBlockFactory)
FactoryRegistry.getFactory(XMLStringBlockFactory.class);
// Create a Block using the sample string as the content. This simulates
// what occurs on the outbound JAX-WS dispatch<String> client
// In this case the sample string contains 2 elements a and aa
Block block = f.createFrom(this.sampleDouble, null, null);
// Add the block to the message as normal body content.
m.setBodyBlock(block);
// If there is a JAX-WS handler, the Message is converted into a SOAPEnvelope
SOAPEnvelope soapEnvelope = m.getAsSOAPEnvelope();
// 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(),
"SOAPENVELOPE".equals(m.getXMLPartContentType()));
// Normally the handler would not touch the body...but for our scenario, assume that it does.
String name = soapEnvelope.getBody().getFirstChild().getLocalName();
assertTrue("a".equals(name));
name = soapEnvelope.getBody().getLastChild().getLocalName();
assertTrue("aa".equals(name));
// The block should be consumed at this point
assertTrue(block.isConsumed());
// After the handler processing the message is obtained as an OM
OMElement om = m.getAsOMElement();
// Serialize the Envelope using the same mechanism as the
// HTTP client.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
om.serializeAndConsume(baos, new OMOutputFormat());
// To check that the output is correct, get the String contents of the
// reader
String newText = baos.toString();
TestLogger.logger.debug(newText);
assertTrue(newText.contains(sampleText));
assertTrue(newText.contains("soap"));
assertTrue(newText.contains("Envelope"));
assertTrue(newText.contains("Body"));
}
/**
* Create a Block representing an XMLString and simulate a
* normal Dispatch<String> input flow
* @throws Exception
*/
public void testStringInflow_soap11() throws Exception {
_testStringInflow(sampleEnvelope11);
}
public void testStringInflow_soap12() throws Exception {
_testStringInflow(sampleEnvelope12);
}
public void _testStringInflow(String sampleEnvelope) throws Exception {
// On inbound, there will already be an OM
// which represents the message. The following code simulates the input
// OM
StringReader sr = new StringReader(sampleEnvelope);
XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null);
OMElement omElement = builder.getSOAPEnvelope();
// The JAX-WS layer creates a Message from the OM
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()));
// Assuming no handlers are installed, the next thing that will happen
// is the proxy code will ask for the business object (String).
XMLStringBlockFactory blockFactory =
(XMLStringBlockFactory) FactoryRegistry.getFactory(XMLStringBlockFactory.class);
Block block = m.getBodyBlock(null, blockFactory);
Object bo = block.getBusinessObject(true);
assertTrue(bo instanceof String);
// The block should be consumed
assertTrue(block.isConsumed());
// Check the String for accuracy
assertTrue(sampleText.equals(bo.toString()));
}
/**
* Create a Block representing an XMLString and simulate a
* normal Dispatch<String> input flow with a JAX-WS Handler
* @throws Exception
*/
public void testStringInflow2_soap11() throws Exception {
_testStringInflow2(sampleEnvelope11);
}
public void testStringInflow2_soap12() throws Exception {
// Only run test if an SAAJ 1.3 MessageFactory is available
javax.xml.soap.MessageFactory mf = null;
try {
mf = getSAAJConverter().createMessageFactory(soap12env);
} catch (Exception e) {}
if (mf != null) {
_testStringInflow2(sampleEnvelope12);
}
}
public void _testStringInflow2(String sampleEnvelope) throws Exception {
// On inbound, there will already be an OM
// which represents the message. The following code simulates the input
// OM
StringReader sr = new StringReader(sampleEnvelope);
XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null);
OMElement omElement = builder.getSOAPEnvelope();
// The JAX-WS layer creates a Message from the OM
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 there is a JAX-WS handler, the Message is converted into a SOAPEnvelope
SOAPEnvelope soapEnvelope = m.getAsSOAPEnvelope();
// 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(),
"SOAPENVELOPE".equals(m.getXMLPartContentType()));
// Normally the handler would not touch the body...but for our scenario, assume that it does.
String name = soapEnvelope.getBody().getFirstChild().getLocalName();
assertTrue("a".equals(name));
// The next thing that will happen
// is the proxy code will ask for the business object (String).
XMLStringBlockFactory blockFactory =
(XMLStringBlockFactory) FactoryRegistry.getFactory(XMLStringBlockFactory.class);
Block block = m.getBodyBlock(null, blockFactory);
Object bo = block.getBusinessObject(true);
assertTrue(bo instanceof String);
// The block should be consumed
assertTrue(block.isConsumed());
// Check the String for accuracy
assertTrue(sampleText.equals(bo.toString()));
}
/**
* Create a Block representing an XMLString and simulate a
* normal Dispatch<String> input flow with a JAX-WS Handler that needs the whole Message
* @throws Exception
*/
public void testStringInflow3_soap11() throws Exception {
_testStringInflow3(sampleEnvelope11);
}
public void testStringInflow3_soap12() throws Exception {
//Only run test if an SAAJ 1.3 MessageFactory is available
javax.xml.soap.MessageFactory mf = null;
try {
mf = getSAAJConverter().createMessageFactory(soap12env);
} catch (Exception e) {}
if (mf != null) {
_testStringInflow3(sampleEnvelope12);
}
}
public void _testStringInflow3(String sampleEnvelope) throws Exception {
// On inbound, there will already be an OM
// which represents the message. The following code simulates the input
// OM
StringReader sr = new StringReader(sampleEnvelope);
XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow, null);
OMElement omElement = builder.getSOAPEnvelope();
// The JAX-WS layer creates a Message from the OM
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 there is a JAX-WS handler, the Message is converted into a SOAPEnvelope
SOAPMessage sm = m.getAsSOAPMessage();
// 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(),
"SOAPENVELOPE".equals(m.getXMLPartContentType()));
// Normally the handler would not touch the body...but for our scenario, assume that it does.
String name = sm.getSOAPBody().getFirstChild().getLocalName();
assertTrue("a".equals(name));
// The next thing that will happen
// is the proxy code will ask for the business object (String).
XMLStringBlockFactory blockFactory =
(XMLStringBlockFactory) FactoryRegistry.getFactory(XMLStringBlockFactory.class);
Block block = m.getBodyBlock(null, blockFactory);
Object bo = block.getBusinessObject(true);
assertTrue(bo instanceof String);
// The block should be consumed
assertTrue(block.isConsumed());
// Check the String for accuracy
assertTrue(sampleText.equals(bo.toString()));
}
/**
* Create a Block representing an XMLString, but this time use one that
* doesn't have a <soap:Header> element in it.
* @throws Exception
*/
public void testStringInflow4_soap11() throws Exception {
_testStringInflow4(sampleEnvelopeNoHeader11);
}
public void testStringInflow4_soap12() throws Exception {
_testStringInflow4(sampleEnvelopeNoHeader12);
}
public void _testStringInflow4(String sampleEnvelopeNoHeader) throws Exception {
// On inbound, there will already be an OM
// which represents the message. The following code simulates the input
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?