Search in sources :

Example 6 with GreetMe

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

the class XMLStreamDataReaderTest method testReadWrapper.

@Test
public void testReadWrapper() throws Exception {
    JAXBDataBinding db = getDataBinding(GreetMe.class);
    reader = getTestReader("../resources/GreetMeDocLiteralReq.xml");
    assertNotNull(reader);
    DataReader<XMLStreamReader> dr = db.createReader(XMLStreamReader.class);
    assertNotNull(dr);
    Object val = dr.read(reader);
    assertNotNull(val);
    assertTrue(val instanceof GreetMe);
    assertEquals("TestSOAPInputPMessage", ((GreetMe) val).getRequestType());
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) XMLStreamReader(javax.xml.stream.XMLStreamReader) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) Test(org.junit.Test)

Example 7 with GreetMe

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

the class XMLStreamDataWriterTest method testWriteWithContextualNamespaceDecls.

@Test
public void testWriteWithContextualNamespaceDecls() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(GreetMe.class);
    Map<String, String> nspref = new HashMap<>();
    nspref.put("http://apache.org/hello_world_soap_http/types", "x");
    db.setNamespaceMap(nspref);
    db.setContextualNamespaceMap(nspref);
    // use the output stream instead of XMLStreamWriter to test
    DataWriter<OutputStream> dw = db.createWriter(OutputStream.class);
    assertNotNull(dw);
    GreetMe val = new GreetMe();
    val.setRequestType("Hello");
    dw.write(val, baos);
    String xstr = new String(baos.toByteArray());
    // there should be no namespace decls
    if (!db.getContext().getClass().getName().contains("eclipse")) {
        // bug in eclipse moxy
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=421463
        assertEquals("<x:greetMe><x:requestType>Hello</x:requestType></x:greetMe>", xstr);
    }
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) Test(org.junit.Test)

Example 8 with GreetMe

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

the class XMLStreamDataWriterTest method testWriteWithNamespacePrefixMapping.

@Test
public void testWriteWithNamespacePrefixMapping() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(GreetMe.class);
    Map<String, String> nspref = new HashMap<>();
    nspref.put("http://apache.org/hello_world_soap_http/types", "x");
    db.setNamespaceMap(nspref);
    // use the output stream instead of XMLStreamWriter to test
    DataWriter<OutputStream> dw = db.createWriter(OutputStream.class);
    assertNotNull(dw);
    GreetMe val = new GreetMe();
    val.setRequestType("Hello");
    dw.write(val, baos);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLStreamReader xr = inFactory.createXMLStreamReader(bais);
    DepthXMLStreamReader reader = new DepthXMLStreamReader(xr);
    StaxUtils.toNextElement(reader);
    QName qname = reader.getName();
    assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "greetMe"), qname);
    assertEquals("x", qname.getPrefix());
    assertEquals(1, reader.getNamespaceCount());
    assertEquals("http://apache.org/hello_world_soap_http/types", reader.getNamespaceURI(0));
    assertEquals("x", reader.getNamespacePrefix(0));
    StaxUtils.nextEvent(reader);
    StaxUtils.toNextElement(reader);
    qname = reader.getName();
    assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "requestType"), qname);
    assertEquals("x", qname.getPrefix());
    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("Hello", reader.getText());
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) QName(javax.xml.namespace.QName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) Test(org.junit.Test)

Example 9 with GreetMe

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

the class DispatchClientServerTest method testJAXBObjectPAYLOADWithFeature.

@Test
public void testJAXBObjectPAYLOADWithFeature() throws Exception {
    createBus("org/apache/cxf/systest/dispatch/client-config.xml");
    BusFactory.setThreadDefaultBus(bus);
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    String bindingId = "http://schemas.xmlsoap.org/wsdl/soap/";
    String endpointUrl = "http://localhost:" + greeterPort + "/SOAPDispatchService/SoapDispatchPort";
    Service service = Service.create(wsdl, SERVICE_NAME);
    service.addPort(PORT_NAME, bindingId, endpointUrl);
    assertNotNull(service);
    JAXBContext jc = JAXBContext.newInstance("org.apache.hello_world_soap_http.types");
    Dispatch<Object> disp = service.createDispatch(PORT_NAME, jc, Service.Mode.PAYLOAD);
    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));
    assertEquals("Feature should be applied", 1, TestDispatchFeature.getCount());
    assertEquals("Feature based interceptors should be added", 1, TestDispatchFeature.getCount());
    assertEquals("Feature based In interceptors has be added to in chain.", 1, TestDispatchFeature.getInInterceptorCount());
    assertEquals("Feature based interceptors has to be added to out chain.", 1, TestDispatchFeature.getOutInterceptorCount());
    bus.shutdown(true);
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) SOAPService(org.apache.hello_world_soap_http.SOAPService) Service(javax.xml.ws.Service) WebService(javax.jws.WebService) JAXBContext(javax.xml.bind.JAXBContext) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) URL(java.net.URL) Test(org.junit.Test)

Example 10 with GreetMe

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

GreetMe (org.apache.hello_world_soap_http.types.GreetMe)19 Test (org.junit.Test)14 QName (javax.xml.namespace.QName)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 XMLStreamReader (javax.xml.stream.XMLStreamReader)6 GreetMeResponse (org.apache.hello_world_soap_http.types.GreetMeResponse)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Unmarshaller (javax.xml.bind.Unmarshaller)5 XMLInputFactory (javax.xml.stream.XMLInputFactory)5 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)5 JAXBElement (javax.xml.bind.JAXBElement)4 JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)4 InputStream (java.io.InputStream)3 Marshaller (javax.xml.bind.Marshaller)3 XMLEventReader (javax.xml.stream.XMLEventReader)3 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)3 EndpointImpl (org.apache.cxf.endpoint.EndpointImpl)3 Exchange (org.apache.cxf.message.Exchange)3 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)3 MessageImpl (org.apache.cxf.message.MessageImpl)3