Search in sources :

Example 1 with GreetMeLater

use of org.apache.hello_world_soap_http.types.GreetMeLater in project cxf by apache.

the class DispatchClientServerTest method doJAXBPayload.

private void doJAXBPayload(Dispatch<Object> disp) throws Exception {
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort");
    String expected = "Hello Jeeves";
    GreetMe greetMe = new GreetMe();
    greetMe.setRequestType("Jeeves");
    Object response = disp.invoke(greetMe);
    assertNotNull(response);
    String responseValue = ((GreetMeResponse) response).getResponseType();
    assertTrue("Expected string, " + expected, expected.equals(responseValue));
    // Test oneway
    disp.invokeOneWay(greetMe);
    // Test async polling
    Response<Object> response2 = disp.invokeAsync(greetMe);
    assertNotNull(response2);
    GreetMeResponse greetMeResponse = (GreetMeResponse) response2.get();
    String responseValue2 = greetMeResponse.getResponseType();
    assertTrue("Expected string, " + expected, expected.equals(responseValue2));
    // Test async callback
    TestJAXBHandler tjbh = new TestJAXBHandler();
    Future<?> fd = disp.invokeAsync(greetMe, tjbh);
    assertNotNull(fd);
    waitForFuture(fd);
    String responseValue3 = ((GreetMeResponse) tjbh.getResponse()).getResponseType();
    assertTrue("Expected string, " + expected, expected.equals(responseValue3));
    org.apache.hello_world_soap_http.types.TestDocLitFault fr = new org.apache.hello_world_soap_http.types.TestDocLitFault();
    fr.setFaultType(BadRecordLitFault.class.getSimpleName());
    tjbh = new TestJAXBHandler();
    fd = disp.invokeAsync(fr, tjbh);
    waitForFuture(fd);
    try {
        fd.get();
        fail("did not get expected exception");
    } catch (ExecutionException ex) {
    // expected
    }
    GreetMeLater later = new GreetMeLater();
    later.setRequestType(1000);
    HTTPClientPolicy pol = new HTTPClientPolicy();
    pol.setReceiveTimeout(100);
    disp.getRequestContext().put(HTTPClientPolicy.class.getName(), pol);
    Response<Object> o = disp.invokeAsync(later);
    try {
        o.get(10, TimeUnit.SECONDS);
        fail("Should have gotten a SocketTimeoutException");
    } catch (ExecutionException ex) {
        assertTrue(ex.getCause() instanceof SocketTimeoutException);
    }
    later.setRequestType(20000);
    pol.setReceiveTimeout(20000);
    disp.getRequestContext().put(HTTPClientPolicy.class.getName(), pol);
    o = disp.invokeAsync(later);
    try {
        o.get(100, TimeUnit.MILLISECONDS);
        fail("Should have gotten a SocketTimeoutException");
    } catch (TimeoutException ex) {
    // ignore - expected
    }
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) SocketTimeoutException(java.net.SocketTimeoutException) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ExecutionException(java.util.concurrent.ExecutionException) GreetMeLater(org.apache.hello_world_soap_http.types.GreetMeLater) TimeoutException(java.util.concurrent.TimeoutException) SocketTimeoutException(java.net.SocketTimeoutException)

Aggregations

SocketTimeoutException (java.net.SocketTimeoutException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)1 BadRecordLitFault (org.apache.hello_world_soap_http.BadRecordLitFault)1 GreetMe (org.apache.hello_world_soap_http.types.GreetMe)1 GreetMeLater (org.apache.hello_world_soap_http.types.GreetMeLater)1 GreetMeResponse (org.apache.hello_world_soap_http.types.GreetMeResponse)1