Search in sources :

Example 1 with Dispatch

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!");
    }
}
Also used : StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) Dispatch(jakarta.xml.ws.Dispatch) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source)

Example 2 with Dispatch

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());
}
Also used : Dispatch(jakarta.xml.ws.Dispatch) JAXBContext(jakarta.xml.bind.JAXBContext) JAXBElement(jakarta.xml.bind.JAXBElement) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with Dispatch

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!");
    }
}
Also used : MessageFactory(jakarta.xml.soap.MessageFactory) StreamSource(javax.xml.transform.stream.StreamSource) SOAPException(jakarta.xml.soap.SOAPException) StringReader(java.io.StringReader) Dispatch(jakarta.xml.ws.Dispatch) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 4 with Dispatch

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;
}
Also used : Response(jakarta.xml.ws.Response) Dispatch(jakarta.xml.ws.Dispatch) JAXBContext(jakarta.xml.bind.JAXBContext)

Example 5 with Dispatch

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);
    }
}
Also used : Response(jakarta.xml.ws.Response) Iterator(java.util.Iterator) Dispatch(jakarta.xml.ws.Dispatch) InputSource(org.xml.sax.InputSource) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) SAXSource(javax.xml.transform.sax.SAXSource)

Aggregations

Dispatch (jakarta.xml.ws.Dispatch)97 WebServiceException (jakarta.xml.ws.WebServiceException)41 Source (javax.xml.transform.Source)32 JAXBContext (jakarta.xml.bind.JAXBContext)30 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)27 MalformedURLException (java.net.MalformedURLException)24 JAXBException (jakarta.xml.bind.JAXBException)22 StreamSource (javax.xml.transform.stream.StreamSource)18 Service (jakarta.xml.ws.Service)16 DOMSource (javax.xml.transform.dom.DOMSource)13 SAXSource (javax.xml.transform.sax.SAXSource)13 InputSource (org.xml.sax.InputSource)13 SOAPMessage (jakarta.xml.soap.SOAPMessage)10 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)10 SAXException (org.xml.sax.SAXException)10 Response (jakarta.xml.ws.Response)9 Iterator (java.util.Iterator)8 URISyntaxException (java.net.URISyntaxException)7 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)6 WSBindingProvider (com.sun.xml.ws.developer.WSBindingProvider)6