Search in sources :

Example 1 with MyComplexStruct

use of org.apache.hello_world_rpclit.types.MyComplexStruct in project cxf by apache.

the class XMLStreamDataReaderTest method testReadRPC.

@Test
public void testReadRPC() throws Exception {
    JAXBDataBinding db = getDataBinding(MyComplexStruct.class);
    QName[] tags = { new QName("http://apache.org/hello_world_rpclit", "sendReceiveData") };
    reader = getTestReader("../resources/greetMeRpcLitReq.xml");
    assertNotNull(reader);
    XMLStreamReader localReader = getTestFilteredReader(reader, tags);
    DataReader<XMLStreamReader> dr = db.createReader(XMLStreamReader.class);
    assertNotNull(dr);
    Object val = dr.read(new QName("http://apache.org/hello_world_rpclit", "in"), localReader, MyComplexStruct.class);
    assertNotNull(val);
    assertTrue(val instanceof MyComplexStruct);
    assertEquals("this is element 1", ((MyComplexStruct) val).getElem1());
    assertEquals("this is element 2", ((MyComplexStruct) val).getElem2());
    assertEquals(42, ((MyComplexStruct) val).getElem3());
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) MyComplexStruct(org.apache.hello_world_rpclit.types.MyComplexStruct) Test(org.junit.Test)

Example 2 with MyComplexStruct

use of org.apache.hello_world_rpclit.types.MyComplexStruct in project cxf by apache.

the class XMLStreamDataWriterTest method testWriteRPCLit2.

@Test
public void testWriteRPCLit2() throws Exception {
    JAXBDataBinding db = getTestWriterFactory(MyComplexStruct.class);
    DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class);
    assertNotNull(dw);
    MyComplexStruct val = new MyComplexStruct();
    val.setElem1("This is element 1");
    val.setElem2("This is element 2");
    val.setElem3(1);
    QName elName = new QName("http://apache.org/hello_world_rpclit/types", "in");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    dw.write(val, part, 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_rpclit/types", "in"), reader.getName());
    StaxUtils.nextEvent(reader);
    StaxUtils.toNextElement(reader);
    assertEquals(new QName("http://apache.org/hello_world_rpclit/types", "elem1"), reader.getName());
    StaxUtils.nextEvent(reader);
    StaxUtils.toNextText(reader);
    assertEquals("This is element 1", 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) MyComplexStruct(org.apache.hello_world_rpclit.types.MyComplexStruct) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Test(org.junit.Test)

Example 3 with MyComplexStruct

use of org.apache.hello_world_rpclit.types.MyComplexStruct in project cxf by apache.

the class Client method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println("please specify wsdl");
        System.exit(1);
    }
    URL wsdlURL;
    File wsdlFile = new File(args[0]);
    if (wsdlFile.exists()) {
        wsdlURL = wsdlFile.toURI().toURL();
    } else {
        wsdlURL = new URL(args[0]);
    }
    SOAPServiceRPCLit service = new SOAPServiceRPCLit(wsdlURL, SERVICE_NAME);
    GreeterRPCLit greeter = (GreeterRPCLit) service.getPort(PORT_NAME, GreeterRPCLit.class);
    System.out.println("Invoking sayHi...");
    System.out.println("server responded with: " + greeter.sayHi());
    System.out.println();
    System.out.println("Invoking greetMe...");
    System.out.println("server responded with: " + greeter.greetMe(System.getProperty("user.name")));
    System.out.println();
    MyComplexStruct argument = new MyComplexStruct();
    MyComplexStruct retVal = null;
    String str1 = "this is element 1";
    String str2 = "this is element 2";
    int int1 = 42;
    argument.setElem1(str1);
    argument.setElem2(str2);
    argument.setElem3(int1);
    System.out.println("Invoking sendReceiveData...");
    retVal = greeter.sendReceiveData(argument);
    System.out.println("Response from sendReceiveData operation :");
    System.out.println("Element-1 : " + retVal.getElem1());
    System.out.println("Element-2 : " + retVal.getElem2());
    System.out.println("Element-3 : " + retVal.getElem3());
    System.out.println();
    System.exit(0);
}
Also used : SOAPServiceRPCLit(org.apache.hello_world_rpclit.SOAPServiceRPCLit) GreeterRPCLit(org.apache.hello_world_rpclit.GreeterRPCLit) MyComplexStruct(org.apache.hello_world_rpclit.types.MyComplexStruct) File(java.io.File) URL(java.net.URL)

Example 4 with MyComplexStruct

use of org.apache.hello_world_rpclit.types.MyComplexStruct in project cxf by apache.

the class ClientServerRPCLitTest method testComplexType.

@Test
public void testComplexType() throws Exception {
    SOAPServiceRPCLit service = new SOAPServiceRPCLit();
    assertNotNull(service);
    GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
    updateAddressPort(greeter, PORT);
    MyComplexStruct in = new MyComplexStruct();
    in.setElem1("elem1");
    in.setElem2("elem2");
    in.setElem3(45);
    try {
        ((BindingProvider) greeter).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
        MyComplexStruct out = greeter.sendReceiveData(in);
        assertNotNull("no response received from service", out);
        assertEquals(in.getElem1(), out.getElem1());
        assertEquals(in.getElem2(), out.getElem2());
        assertEquals(in.getElem3(), out.getElem3());
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
    try {
        in.setElem2("invalid");
        greeter.sendReceiveData(in);
    } catch (SOAPFaultException f) {
        assertTrue(f.getCause() instanceof UnmarshalException);
    }
}
Also used : SOAPServiceRPCLit(org.apache.hello_world_rpclit.SOAPServiceRPCLit) GreeterRPCLit(org.apache.hello_world_rpclit.GreeterRPCLit) UnmarshalException(javax.xml.bind.UnmarshalException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) MyComplexStruct(org.apache.hello_world_rpclit.types.MyComplexStruct) Test(org.junit.Test)

Aggregations

MyComplexStruct (org.apache.hello_world_rpclit.types.MyComplexStruct)4 Test (org.junit.Test)3 QName (javax.xml.namespace.QName)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2 JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)2 GreeterRPCLit (org.apache.hello_world_rpclit.GreeterRPCLit)2 SOAPServiceRPCLit (org.apache.hello_world_rpclit.SOAPServiceRPCLit)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 URL (java.net.URL)1 UnmarshalException (javax.xml.bind.UnmarshalException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)1 DepthXMLStreamReader (org.apache.cxf.staxutils.DepthXMLStreamReader)1