use of jakarta.xml.ws.Dispatch in project metro-jax-ws by eclipse-ee4j.
the class AddNumbersClient method invokeAsyncCallbackAddNumbers.
// end invoke async poll
private void invokeAsyncCallbackAddNumbers(String request, Service.Mode mode) throws RemoteException {
Dispatch sourceDispatch = null;
sourceDispatch = service.createDispatch(portQName, Source.class, mode);
System.out.println("\nInvoking async calback xml request: " + request);
DispatchAsyncHandler handler = new DispatchAsyncHandler();
Future<?> response = sourceDispatch.invokeAsync(new StreamSource(new StringReader(request)), new DispatchAsyncHandler());
// go off and do something else
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (response.isDone()) {
if (handler.isFailure()) {
Throwable failure = handler.getFailure();
System.out.println("Failure in DispatchAsyncHandler " + failure.getMessage());
} else
System.out.println("Success processing result!");
}
}
use of jakarta.xml.ws.Dispatch in project metro-jax-ws by eclipse-ee4j.
the class AddNumbersClient method invokeAsyncPollAddNumbers.
private void invokeAsyncPollAddNumbers() throws RemoteException {
Dispatch jaxbDispatch = null;
JAXBContext jaxbContext = createJAXBContext();
jaxbDispatch = service.createDispatch(portQName, jaxbContext, Service.Mode.PAYLOAD);
ObjectFactory factory = new ObjectFactory();
AddNumbers numbers = new AddNumbers();
int number1 = 10;
int number2 = 20;
numbers.setArg0(number1);
numbers.setArg1(number2);
JAXBElement<AddNumbers> addNumbers = factory.createAddNumbers(numbers);
System.out.printf("\nInvoking async poll addNumbers(%d, %d)\n", number1, number2);
Response<JAXBElement<AddNumbersResponse>> response = jaxbDispatch.invokeAsync(addNumbers);
while (!response.isDone()) {
// go do some work
}
AddNumbersResponse result = null;
try {
JAXBElement<AddNumbersResponse> jaxbResponse = response.get();
result = jaxbResponse.getValue();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
System.out.printf("The result of adding %d and %d is %d.\n", number1, number2, result.getReturn());
}
use of jakarta.xml.ws.Dispatch in project metro-jax-ws by eclipse-ee4j.
the class AddNumbersClient method invokeAsyncCallbackAddNumbers.
private void invokeAsyncCallbackAddNumbers(String msgString) throws RemoteException {
SOAPMessage message = null;
try {
MessageFactory factory = MessageFactory.newInstance();
message = factory.createMessage();
message.getSOAPPart().setContent((Source) new StreamSource(new StringReader(msgString)));
message.saveChanges();
} catch (SOAPException e) {
e.printStackTrace();
}
Dispatch smDispatch = null;
smDispatch = service.createDispatch(portQName, SOAPMessage.class, Service.Mode.MESSAGE);
System.out.println("\nInvoking async callback message: " + msgString);
DispatchAsyncHandler handler = new DispatchAsyncHandler();
Future<?> response = smDispatch.invokeAsync(message, handler);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (response.isDone()) {
if (handler.isFailure()) {
Throwable failure = handler.getFailure();
System.out.println("Failure in DispatchAsyncHandler " + failure.getMessage());
} else
System.out.println("Success processing result!");
}
}
use of jakarta.xml.ws.Dispatch in project metro-jax-ws by eclipse-ee4j.
the class DispatchHelloLiteralTest method testVoidAsyncPollJAXB.
/*Invalid test may not cancel
public void testHelloAsyncPollCancelXML() throws Exception {
Dispatch dispatch = getDispatchSource();
Collection<Source> sourceList = makeMsgSource(helloMsg);
Collection<Source> responseList = makeMsgSource(helloResponse);
for (Iterator iter = sourceList.iterator(); iter.hasNext();) {
Object sourceObject = iter.next();
Response result = dispatch.invokeAsync(sourceObject);
while (!result.isDone()) {
result.cancel(false);
assertEquals(true, result.isCancelled());
}
}
}
public void testHelloAsyncPollCancelInterruptXML() throws Exception {
Dispatch dispatch = getDispatchSource();
Collection<Source> sourceList = makeMsgSource(helloMsg);
Collection<Source> responseList = makeMsgSource(helloResponse);
for (Iterator iter = sourceList.iterator(); iter.hasNext();) {
Object sourceObject = iter.next();
Response result = dispatch.invokeAsync(sourceObject);
while (!result.isDone()) {
result.cancel(true);
assertEquals(true, result.isCancelled());
}
}
}
--end invalid test*/
public void testVoidAsyncPollJAXB() throws Exception {
JAXBContext jc = createJAXBContext();
VoidTest voidTest = new VoidTest();
VoidTestResponse voidTestResult = new VoidTestResponse();
Dispatch dispatch = getDispatchJAXB();
Response result = dispatch.invokeAsync(voidTest);
Object obj = result.get();
assertTrue(obj != null);
assertTrue(obj instanceof VoidTestResponse);
VoidTestResponse res = (VoidTestResponse) obj;
}
use of jakarta.xml.ws.Dispatch in project metro-jax-ws by eclipse-ee4j.
the class DispatchHelloLiteralTest method testHelloAsyncPollDoneXML.
// todo: object comes back as jaxb object investigate
public void testHelloAsyncPollDoneXML() throws Exception {
Dispatch dispatch = getDispatchSource();
Collection<Source> sourceList = makeMsgSource(helloMsg);
Collection<Source> responseList = makeMsgSource(helloResponse);
for (Iterator iter = sourceList.iterator(); iter.hasNext(); ) {
Object sourceObject = iter.next();
Response result = dispatch.invokeAsync(sourceObject);
while (!result.isDone()) {
}
Object realResult = ((Response) result).get();
assertTrue(realResult instanceof Source);
}
}
Aggregations