saxsourcedispatch.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 356 行 · 第 1/2 页
JAVA
356 行
while (!monitor.isDone()) {
TestLogger.logger.debug(">> Async invocation still not complete");
Thread.sleep(1000);
}
Source response = callbackHandler.getValue();
assertNotNull("dispatch invoke returned null", response);
// Prepare the response content for checking
XMLStreamReader reader = inputFactory.createXMLStreamReader(response);
Reader2Writer r2w = new Reader2Writer(reader);
String responseText = r2w.getAsString();
TestLogger.logger.debug(responseText);
// Check to make sure the content is correct
assertTrue(responseText.contains("soap"));
assertTrue(responseText.contains("Envelope"));
assertTrue(responseText.contains("Body"));
assertTrue(responseText.contains("echoStringResponse"));
}
public void testAsyncPollingPayloadMode() throws Exception {
TestLogger.logger.debug("---------------------------------------");
TestLogger.logger.debug("test: " + getName());
// Initialize the JAX-WS client artifacts
Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
Source.class, Service.Mode.PAYLOAD);
// Create a SAXSource out of the string content
byte[] bytes = DispatchTestConstants.sampleBodyContent.getBytes();
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
InputSource input = new InputSource(stream);
Source request = new SAXSource(input);
TestLogger.logger.debug(">> Invoking async (polling) Dispatch");
Response<Source> asyncResponse = dispatch.invokeAsync(request);
while (!asyncResponse.isDone()) {
TestLogger.logger.debug(">> Async invocation still not complete");
Thread.sleep(1000);
}
Source response = asyncResponse.get();
assertNotNull("dispatch invoke returned null", response);
// Prepare the response content for checking
XMLStreamReader reader = inputFactory.createXMLStreamReader(response);
Reader2Writer r2w = new Reader2Writer(reader);
String responseText = r2w.getAsString();
TestLogger.logger.debug(responseText);
// Check to make sure the content is correct
assertTrue(!responseText.contains("soap"));
assertTrue(!responseText.contains("Envelope"));
assertTrue(!responseText.contains("Body"));
assertTrue(responseText.contains("echoStringResponse"));
}
public void testAsyncPollingMessageMode() throws Exception {
TestLogger.logger.debug("---------------------------------------");
TestLogger.logger.debug("test: " + getName());
// Initialize the JAX-WS client artifacts
Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
Source.class, Service.Mode.MESSAGE);
// Create a SAXSource out of the string content
byte[] bytes = DispatchTestConstants.sampleSoapMessage.getBytes();
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
InputSource input = new InputSource(stream);
Source request = new SAXSource(input);
TestLogger.logger.debug(">> Invoking async (callback) Dispatch");
Response<Source> asyncResponse = dispatch.invokeAsync(request);
while (!asyncResponse.isDone()) {
TestLogger.logger.debug(">> Async invocation still not complete");
Thread.sleep(1000);
}
Source response = asyncResponse.get();
assertNotNull("dispatch invoke returned null", response);
// Prepare the response content for checking
XMLStreamReader reader = inputFactory.createXMLStreamReader(response);
Reader2Writer r2w = new Reader2Writer(reader);
String responseText = r2w.getAsString();
TestLogger.logger.debug(responseText);
// Check to make sure the content is correct
assertTrue(responseText.contains("soap"));
assertTrue(responseText.contains("Envelope"));
assertTrue(responseText.contains("Body"));
assertTrue(responseText.contains("echoStringResponse"));
}
public void testOneWayPayloadMode() throws Exception {
TestLogger.logger.debug("---------------------------------------");
TestLogger.logger.debug("test: " + getName());
// Initialize the JAX-WS client artifacts
Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
Source.class, Service.Mode.PAYLOAD);
// Create a SAXSource out of the string content
byte[] bytes = DispatchTestConstants.sampleBodyContent.getBytes();
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
InputSource input = new InputSource(stream);
Source request = new SAXSource(input);
TestLogger.logger.debug(">> Invoking One Way Dispatch");
dispatch.invokeOneWay(request);
}
public void testOneWayMessageMode() throws Exception {
TestLogger.logger.debug("---------------------------------------");
TestLogger.logger.debug("test: " + getName());
// Initialize the JAX-WS client artifacts
Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
Source.class, Service.Mode.MESSAGE);
// Create a SAXSource out of the string content
byte[] bytes = DispatchTestConstants.sampleSoapMessage.getBytes();
ByteArrayInputStream stream = new ByteArrayInputStream(bytes);
InputSource input = new InputSource(stream);
Source request = new SAXSource(input);
TestLogger.logger.debug(">> Invoking One Way Dispatch");
dispatch.invokeOneWay(request);
}
public void testBadSAXSource() throws Exception {
TestLogger.logger.debug("---------------------------------------");
TestLogger.logger.debug("test: " + getName());
// Initialize the JAX-WS client artifacts
Service svc = Service.create(DispatchTestConstants.QNAME_SERVICE);
svc.addPort(DispatchTestConstants.QNAME_PORT, null, DispatchTestConstants.URL);
Dispatch<Source> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
Source.class, Service.Mode.MESSAGE);
// Create an empty (invalid) SAXSource
Source request = new SAXSource();
try {
dispatch.invoke(request);
fail("WebServiceException was expected");
} catch (WebServiceException e) {
TestLogger.logger.debug("A Web Service Exception was expected: " + e.toString());
assertTrue(e.getMessage() != null);
} catch (Exception e) {
fail("WebServiceException was expected, but received:" + e);
}
try {
dispatch.invokeOneWay(request);
fail("WebServiceException was expected");
} catch (WebServiceException e) {
TestLogger.logger.debug("A Web Service Exception was expected: " + e.toString());
assertTrue(e.getMessage() != null);
} catch (Exception e) {
fail("WebServiceException was expected, but received:" + e);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?