blocktests.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,055 行 · 第 1/3 页
JAVA
1,055 行
* @throws Exception
*/
public void testJAXBOutflow2() throws Exception {
// Get the BlockFactory
JAXBBlockFactory f = (JAXBBlockFactory)
FactoryRegistry.getFactory(JAXBBlockFactory.class);
// Create a jaxb object
ObjectFactory factory = new ObjectFactory();
EchoString jaxb = factory.createEchoString();
jaxb.setInput("Hello World");
JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
QName expectedQName = jbi.getElementName(jaxb);
// Create a Block using the sample string as the content. This simulates
// what occurs with an outbound JAX-WS JAXB parameter
Block block = f.createFrom(jaxb, context, expectedQName);
// We did pass in a qname, so the following should return false
assertTrue(block.isQNameAvailable());
// Assume that we need to find the QName (perhaps to identify the operation and
// determine if handlers are installed). This is not very perfomant since
// it causes an underlying parse of the String...but we need to support this.
QName qName = block.getQName();
assertTrue("Expected: " + expectedQName + " but found: " + qName, expectedQName.equals(qName));
// Assuming no handlers are installed, the next thing that will happen
// is a XMLStreamReader will be requested...to go to OM. At this point the
// block should be consumed.
XMLStreamReader reader = block.getXMLStreamReader(true);
// The block should be consumed
assertTrue(block.isConsumed());
// To check that the output is correct, get the String contents of the
// reader
Reader2Writer r2w = new Reader2Writer(reader);
String newText = r2w.getAsString();
assertTrue(newText.contains("Hello World"));
assertTrue(newText.contains("echoString"));
}
/**
* Create a Block representing an JAXB and simulate a
* normal Dispatch<JAXB> input flow
* @throws Exception
*/
public void testJAXBInflow() throws Exception {
// Get the BlockFactory
JAXBBlockFactory f = (JAXBBlockFactory)
FactoryRegistry.getFactory(JAXBBlockFactory.class);
// Create a jaxb object
ObjectFactory factory = new ObjectFactory();
EchoString jaxb = factory.createEchoString();
jaxb.setInput("Hello World");
JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
// On inbound, there will already be a XMLStreamReader (probably from OM)
// which represents the message. We will simulate this with inflow.
StringWriter sw = new StringWriter();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
Marshaller marshaller = JAXBUtils.getJAXBMarshaller(context.getJAXBContext());
marshaller.marshal(jaxb, writer);
JAXBUtils.releaseJAXBMarshaller(context.getJAXBContext(), marshaller);
writer.flush();
sw.flush();
StringReader sr = new StringReader(sw.toString());
XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
// Create a Block from the inflow.
Block block = f.createFrom(inflow, context, null);
// Assuming no handlers are installed, the next thing that will happen
// is the proxy code will ask for the business object.
Object bo = block.getBusinessObject(true);
assertTrue(bo instanceof EchoString);
// The block should be consumed
assertTrue(block.isConsumed());
// Check for accuracy
assertTrue("Unexpected:" + ((EchoString)bo).getInput(), ((EchoString)bo).getInput().equals(jaxb.getInput()));
}
/**
* Create a Block representing an JAXB and simulate a
* normal Dispatch<JAXB> input flow
* @throws Exception
*/
public void testJAXBInflow2() throws Exception {
// Get the BlockFactory
JAXBBlockFactory f = (JAXBBlockFactory)
FactoryRegistry.getFactory(JAXBBlockFactory.class);
// Create a jaxb object
ObjectFactory factory = new ObjectFactory();
EchoString jaxb = factory.createEchoString();
jaxb.setInput("Hello World");
JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
QName expectedQName = jbi.getElementName(jaxb);
// On inbound, there will already be a XMLStreamReader (probably from OM)
// which represents the message. We will simulate this with inflow.
StringWriter sw = new StringWriter();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
Marshaller marshaller = JAXBUtils.getJAXBMarshaller(context.getJAXBContext());
marshaller.marshal(jaxb, writer);
JAXBUtils.releaseJAXBMarshaller(context.getJAXBContext(), marshaller);
writer.flush();
sw.flush();
StringReader sr = new StringReader(sw.toString());
XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
// Create a Block from the inflow.
Block block = f.createFrom(inflow, context, null);
// Assume that we need to find the QName (perhaps to identify the operation and
// determine if handlers are installed). This is not very perfomant since
// it causes an underlying parse of the String...but we need to support this.
QName qName = block.getQName();
assertTrue("Expected: " + expectedQName + " but found: " + qName, expectedQName.equals(qName));
// Assuming no handlers are installed, the next thing that will happen
// is the proxy code will ask for the business object.
Object bo = block.getBusinessObject(true);
assertTrue(bo instanceof EchoString);
// The block should be consumed
assertTrue(block.isConsumed());
// Check for accuracy
assertTrue("Unexpected:" + ((EchoString)bo).getInput(), ((EchoString)bo).getInput().equals(jaxb.getInput()));
}
/**
* Create a Block representing an JAXB and simulate a
* normal Dispatch<JAXB> input flow
* @throws Exception
*/
public void testJAXBInflow3() throws Exception {
// Get the BlockFactory
JAXBBlockFactory f = (JAXBBlockFactory)
FactoryRegistry.getFactory(JAXBBlockFactory.class);
// Create a jaxb object
ObjectFactory factory = new ObjectFactory();
EchoString jaxb = factory.createEchoString();
jaxb.setInput("Hello World");
JAXBBlockContext context = new JAXBBlockContext(EchoString.class.getPackage().getName());
JAXBIntrospector jbi = JAXBUtils.getJAXBIntrospector(context.getJAXBContext());
QName expectedQName = jbi.getElementName(jaxb);
// On inbound, there will already be a XMLStreamReader (probably from OM)
// which represents the message. We will simulate this with inflow.
StringWriter sw = new StringWriter();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(sw);
Marshaller marshaller = JAXBUtils.getJAXBMarshaller(context.getJAXBContext());
marshaller.marshal(jaxb, writer);
JAXBUtils.releaseJAXBMarshaller(context.getJAXBContext(), marshaller);
writer.flush();
sw.flush();
StringReader sr = new StringReader(sw.toString());
XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
// Create a Block from the inflow.
Block block = f.createFrom(inflow, context, expectedQName);
// We passed in a qname, so the following should return false
assertTrue(block.isQNameAvailable());
// Assume that we need to find the QName (perhaps to identify the operation and
// determine if handlers are installed). This is not very perfomant since
// it causes an underlying parse of the String...but we need to support this.
QName qName = block.getQName();
assertTrue("Expected: " + expectedQName + " but found: " + qName, expectedQName.equals(qName));
// Assuming no handlers are installed, the next thing that will happen
// is the proxy code will ask for the business object.
Object bo = block.getBusinessObject(true);
assertTrue(bo instanceof EchoString);
// The block should be consumed
assertTrue(block.isConsumed());
// Check for accuracy
assertTrue("Unexpected:" + ((EchoString)bo).getInput(), ((EchoString)bo).getInput().equals(jaxb.getInput()));
}
/**
* Create a Block representing an OM and simulate a
* normal Dispatch<OMElement> flow
* @throws Exception
*/
public void testOMOutflow() throws Exception {
// Get the BlockFactory
OMBlockFactory f = (OMBlockFactory)
FactoryRegistry.getFactory(OMBlockFactory.class);
// Create a Block using the sample string as the content. This simulates
// what occurs on the outbound JAX-WS dispatch<OMElement> client
StringReader sr = new StringReader(sampleText);
XMLStreamReader inputReader = inputFactory.createXMLStreamReader(sr);
StAXOMBuilder builder = new StAXOMBuilder(inputReader);
OMElement om = builder.getDocumentElement();
Block block = f.createFrom(om, null, null);
// Assuming no handlers are installed, the next thing that will happen
// is a XMLStreamReader will be requested...to go to OM. At this point the
// block should be consumed.
XMLStreamReader reader = block.getXMLStreamReader(true);
// The block should be consumed
assertTrue(block.isConsumed());
// To check that the output is correct, get the String contents of the
// reader
Reader2Writer r2w = new Reader2Writer(reader);
String newText = r2w.getAsString();
assertTrue(sampleText.equals(newText));
}
/**
* Create a Block representing an OM and simulate a
* different Dispatch<OMElement> flow
* @throws Exception
*/
public void testOMOutflow2() throws Exception {
// Get the BlockFactory
OMBlockFactory f = (OMBlockFactory)
FactoryRegistry.getFactory(OMBlockFactory.class);
// Create a Block using the sample string as the content. This simulates
// what occurs on the outbound JAX-WS dispatch<OMElement> client
StringReader sr = new StringReader(sampleText);
XMLStreamReader inputReader = inputFactory.createXMLStreamReader(sr);
StAXOMBuilder builder = new StAXOMBuilder(inputReader);
OMElement om = builder.getDocumentElement();
Block block = f.createFrom(om, null, null);
// Assume that we need to find the QName (perhaps to identify the operation and
// determine if handlers are installed). This is not very perfomant since
// it causes an underlying parse of the String...but we need to support this.
QName qName = block.getQName();
assertTrue("Expected: " + sampleQName + " but found: " + qName, sampleQName.equals(qName));
// Assuming no handlers are installed, the next thing that will happen
// is a XMLStreamReader will be requested...to go to OM. At this point the
// block should be consumed.
XMLStreamReader reader = block.getXMLStreamReader(true);
// The block should be consumed
assertTrue(block.isConsumed());
// To check that the output is correct, get the String contents of the
// reader
Reader2Writer r2w = new Reader2Writer(reader);
String newText = r2w.getAsString();
assertTrue(sampleText.equals(newText));
}
/**
* Create a Block representing an XMLString and simulate a
* Dispatch<OMElement> inflow
* @throws Exception
*/
public void testOMInflow() throws Exception {
// Get the BlockFactory
OMBlockFactory f = (OMBlockFactory)
FactoryRegistry.getFactory(OMBlockFactory.class);
// On inbound, there will already be a XMLStreamReader (probably from OM)
// which represents the message. We will simulate this with inflow.
StringReader sr = new StringReader(sampleText);
XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
// Create a Block from the inflow.
Block block = f.createFrom(inflow, null, null);
// Let's assume we need to get the QName to find the operation name.
// This will cause an underlying parse
QName qName = block.getQName();
assertTrue(sampleQName.equals(qName));
// Assuming no handlers are installed, the next thing that will happen
// is the proxy code will ask for the business object (String).
Object bo = block.getBusinessObject(true);
assertTrue(bo instanceof OMElement);
// The block should be consumed
assertTrue(block.isConsumed());
// Check the String for accuracy
assertTrue(sampleText.equals(bo.toString()));
}
/**
* Create a Block representing a Source and simulate a
* normal Dispatch<Source> flow
* @throws Exception
*/
public void testStreamSourceOutflow() throws Exception {
// Get the BlockFactory
SourceBlockFactory f = (SourceBlockFactory)
FactoryRegistry.getFactory(SourceBlockFactory.class);
StreamSource ss = new StreamSource(new StringReader(sampleText));
// Create a Block using the sample string as the content. This simulates
// what occurs on the outbound JAX-WS dispatch<Source> client
Block block = f.createFrom(ss, null, null);
// We didn't pass in a qname, so the following should return false
assertTrue(!block.isQNameAvailable());
// Assuming no handlers are installed, the next thing that will happen
// is a XMLStreamReader will be requested...to go to OM. At this point the
// block should be consumed.
XMLStreamReader reader = block.getXMLStreamReader(true);
// The block should be consumed
assertTrue(block.isConsumed());
// To check that the output is correct, get the String contents of the
// reader
Reader2Writer r2w = new Reader2Writer(reader);
String newText = r2w.getAsString();
assertTrue(sampleText.equals(newText));
}
/**
* Create a Block representing a Source and
* simulate a different Dispatch<Source> flow
* @throws Exception
*/
public void testStreamSourceOutflow2() throws Exception {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?