Search in sources :

Example 6 with GreetMeResponse

use of org.apache.hello_world_soap_http.types.GreetMeResponse 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)

Example 7 with GreetMeResponse

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

the class BareInInterceptorTest method testInterceptorOutbound.

@Test
public void testInterceptorOutbound() throws Exception {
    setUpUsingHelloWorld();
    BareInInterceptor interceptor = new BareInInterceptor();
    message.setContent(XMLStreamReader.class, XMLInputFactory.newInstance().createXMLStreamReader(getTestStream(getClass(), "resources/GreetMeDocLiteralResp.xml")));
    message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
    interceptor.handleMessage(message);
    List<?> parameters = message.getContent(List.class);
    assertEquals(1, parameters.size());
    Object obj = parameters.get(0);
    assertTrue(obj instanceof GreetMeResponse);
    GreetMeResponse greet = (GreetMeResponse) obj;
    assertEquals("TestSOAPOutputPMessage", greet.getResponseType());
}
Also used : GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor) Test(org.junit.Test)

Example 8 with GreetMeResponse

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

the class XMLStreamDataWriterTest method testWriteWrapperReturn.

@Test
public void testWriteWrapperReturn() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(GreetMeResponse.class);
    DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class);
    assertNotNull(dw);
    GreetMeResponse retVal = new GreetMeResponse();
    retVal.setResponseType("TESTOUTPUTMESSAGE");
    dw.write(retVal, streamWriter);
    streamWriter.flush();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLStreamReader xr = inFactory.createXMLStreamReader(bais);
    DepthXMLStreamReader reader = new DepthXMLStreamReader(xr);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse"), reader.getName());
    StaxUtils.nextEvent(reader);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "responseType"), reader.getName());
    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("TESTOUTPUTMESSAGE", reader.getText());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) QName(javax.xml.namespace.QName) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Test(org.junit.Test)

Example 9 with GreetMeResponse

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

the class NettyClientTest method testCallAsync.

@Test
public void testCallAsync() throws Exception {
    updateAddressPort(g, PORT);
    GreetMeResponse resp = (GreetMeResponse) g.greetMeAsync("asyncTest", new AsyncHandler<GreetMeResponse>() {

        public void handleResponse(Response<GreetMeResponse> res) {
            try {
                res.get().getResponseType();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
    }).get();
    assertEquals("Hello asyncTest", resp.getResponseType());
    MyLaterResponseHandler handler = new MyLaterResponseHandler();
    g.greetMeLaterAsync(1000, handler).get();
    // need to check the result here
    assertEquals("Hello, finally!", handler.getResponse().getResponseType());
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Test(org.junit.Test)

Example 10 with GreetMeResponse

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

the class AsyncHTTPConduitTest method testCallAsync.

@Test
public void testCallAsync() throws Exception {
    updateAddressPort(g, PORT);
    GreetMeResponse resp = (GreetMeResponse) g.greetMeAsync(request, new AsyncHandler<GreetMeResponse>() {

        public void handleResponse(Response<GreetMeResponse> res) {
            try {
                res.get().getResponseType();
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
    }).get();
    assertEquals("Hello " + request, resp.getResponseType());
    g.greetMeLaterAsync(1000, new AsyncHandler<GreetMeLaterResponse>() {

        public void handleResponse(Response<GreetMeLaterResponse> res) {
        }
    }).get();
}
Also used : GreetMeLaterResponse(org.apache.hello_world_soap_http.types.GreetMeLaterResponse) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Response(javax.xml.ws.Response) AsyncHandler(javax.xml.ws.AsyncHandler) ExecutionException(java.util.concurrent.ExecutionException) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Test(org.junit.Test)

Aggregations

GreetMeResponse (org.apache.hello_world_soap_http.types.GreetMeResponse)11 Test (org.junit.Test)10 ExecutionException (java.util.concurrent.ExecutionException)5 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 Response (javax.xml.ws.Response)3 GreetMeLaterResponse (org.apache.hello_world_soap_http.types.GreetMeLaterResponse)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URL (java.net.URL)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 QName (javax.xml.namespace.QName)2 AsyncHandler (javax.xml.ws.AsyncHandler)2 Endpoint (javax.xml.ws.Endpoint)2 JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)2 DepthXMLStreamReader (org.apache.cxf.staxutils.DepthXMLStreamReader)2 SOAPService (org.apache.hello_world_soap_http.SOAPService)2 GreetMe (org.apache.hello_world_soap_http.types.GreetMe)2 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 Executor (java.util.concurrent.Executor)1 TimeoutException (java.util.concurrent.TimeoutException)1