stringdispatch.java
来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 385 行 · 第 1/2 页
JAVA
385 行
*/
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<String> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
String.class, Service.Mode.PAYLOAD);
TestLogger.logger.debug(">> Invoking async (polling) Dispatch");
Response<String> asyncResponse = dispatch.invokeAsync(DispatchTestConstants.sampleBodyContent);
while (!asyncResponse.isDone()) {
TestLogger.logger.debug(">> Async invocation still not complete");
Thread.sleep(1000);
}
String response = asyncResponse.get();
assertNotNull("dispatch invoke returned null", response);
TestLogger.logger.debug(response);
// Check to make sure the content is correct
assertTrue(!response.contains("soap"));
assertTrue(!response.contains("Envelope"));
assertTrue(!response.contains("Body"));
assertTrue(response.contains("echoStringResponse"));
}
/**
* Invoke a Dispatch<String> using the async polling API in MESSAGE mode
*/
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<String> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
String.class, Service.Mode.MESSAGE);
TestLogger.logger.debug(">> Invoking async (polling) Dispatch with Message Mode");
Response<String> asyncResponse = dispatch.invokeAsync(DispatchTestConstants.sampleSoapMessage);
while (!asyncResponse.isDone()) {
TestLogger.logger.debug(">> Async invocation still not complete");
Thread.sleep(1000);
}
String response = asyncResponse.get();
assertNotNull("dispatch invoke returned null", response);
TestLogger.logger.debug(response);
// Check to make sure the content is correct
assertTrue(response.contains("soap"));
assertTrue(response.contains("Envelope"));
assertTrue(response.contains("Body"));
assertTrue(response.contains("echoStringResponse"));
}
/**
* Invoke a Dispatch<String> one-way in PAYLOAD mode
*/
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<String> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
String.class, Service.Mode.PAYLOAD);
TestLogger.logger.debug(">> Invoking one-way Dispatch");
dispatch.invokeOneWay(DispatchTestConstants.sampleBodyContent);
}
/**
* Invoke a Dispatch<String> one-way in MESSAGE mode
*/
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<String> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
String.class, Service.Mode.MESSAGE);
TestLogger.logger.debug(">> Invoking one-way Dispatch");
dispatch.invokeOneWay(DispatchTestConstants.sampleSoapMessage);
}
public void testSyncPayloadMode_badHostName() {
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.BADURL);
Dispatch<String> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
String.class, Service.Mode.PAYLOAD);
// Invoke the Dispatch
Throwable ttemp = null;
try {
TestLogger.logger.debug(">> Invoking sync Dispatch");
String response = dispatch.invoke(DispatchTestConstants.sampleBodyContent);
} catch (Throwable t) {
assertTrue(t instanceof WebServiceException);
assertTrue(t.getCause() instanceof UnknownHostException);
ttemp = t;
}
assertNotNull(ttemp);
}
public void testAsyncCallbackMessageMode_badHostName() 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.BADURL);
Dispatch<String> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
String.class, Service.Mode.MESSAGE);
// Create the callback for async responses
AsyncCallback<String> callback = new AsyncCallback<String>();
TestLogger.logger.debug(">> Invoking async (callback) Dispatch with Message Mode");
Future<?> monitor = dispatch.invokeAsync(DispatchTestConstants.sampleSoapMessage, callback);
while (!monitor.isDone()) {
TestLogger.logger.debug(">> Async invocation still not complete");
Thread.sleep(1000);
}
if (callback.hasError()) {
Throwable t = callback.getError();
t.printStackTrace();
assertTrue(t.getClass().getName() + " does not match expected type ExecutionException", t instanceof ExecutionException);
Throwable cause = t.getCause();
assertNotNull("There must be a cause under the ExecutionException", cause);
assertTrue(cause.getClass().getName() + " does not match expected type WebServiceException" ,cause instanceof WebServiceException);
Throwable hostException = t.getCause().getCause();
assertNotNull("There must be a cause under the WebServiceException", hostException);
assertTrue(hostException.getClass().getName() + " does not match expected type UnknownHostException", hostException instanceof UnknownHostException);
} else {
fail("No fault thrown. Should have retrieved an UnknownHostException from callback");
}
}
public void testAsyncPollingPayloadMode_badHostName() 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.BADURL);
Dispatch<String> dispatch = svc.createDispatch(DispatchTestConstants.QNAME_PORT,
String.class, Service.Mode.PAYLOAD);
TestLogger.logger.debug(">> Invoking async (polling) Dispatch");
Response<String> asyncResponse = dispatch.invokeAsync(DispatchTestConstants.sampleBodyContent);
while (!asyncResponse.isDone()) {
TestLogger.logger.debug(">> Async invocation still not complete");
Thread.sleep(1000);
}
Throwable ttemp = null;
try {
asyncResponse.get();
} catch (Throwable t) {
assertTrue(t instanceof ExecutionException);
assertTrue(t.getCause() instanceof WebServiceException);
assertTrue(t.getCause().getCause() instanceof UnknownHostException);
ttemp = t;
}
assertNotNull(ttemp);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?