Java Code Examples for org.apache.cxf.jaxb.JAXBDataBinding#createReader()

The following examples show how to use org.apache.cxf.jaxb.JAXBDataBinding#createReader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLStreamDataReaderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private DataReaderImpl<XMLStreamReader> newDataReader(ValidationEventHandler handler) throws Exception {
    JAXBDataBinding db = getDataBinding(GreetMe.class);

    reader = getTestReader("../resources/SetPropertyValidationFailureReq.xml");
    assertNotNull(reader);

    DataReaderImpl<XMLStreamReader> dr = (DataReaderImpl<XMLStreamReader>)db.createReader(XMLStreamReader.class);
    assertNotNull(dr);

    // Build message to set custom event handler
    org.apache.cxf.message.Message message = new org.apache.cxf.message.MessageImpl();
    message.put(JAXBDataBinding.READER_VALIDATION_EVENT_HANDLER, handler);
    message.put("unwrap.jaxb.element", true);

    dr.setProperty("org.apache.cxf.message.Message", message);

    return dr;
}
 
Example 2
Source File: XMLStreamDataReaderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadWrapperReturn() throws Exception {
    JAXBDataBinding db = getDataBinding(GreetMeResponse.class);

    reader = getTestReader("../resources/GreetMeDocLiteralResp.xml");
    assertNotNull(reader);

    DataReader<XMLStreamReader> dr = db.createReader(XMLStreamReader.class);
    assertNotNull(dr);

    Object retValue = dr.read(reader);

    assertNotNull(retValue);
    assertTrue(retValue instanceof GreetMeResponse);
    assertEquals("TestSOAPOutputPMessage", ((GreetMeResponse)retValue).getResponseType());
}
 
Example 3
Source File: XMLStreamDataReaderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 4
Source File: XMLStreamDataReaderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadBare() throws Exception {
    JAXBDataBinding db = getDataBinding(TradePriceData.class);

    reader = getTestReader("../resources/sayHiDocLitBareReq.xml");
    assertNotNull(reader);

    DataReader<XMLStreamReader> dr = db.createReader(XMLStreamReader.class);
    assertNotNull(dr);
    QName elName = new QName("http://apache.org/hello_world_doc_lit_bare/types", "inout");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    part.setTypeClass(TradePriceData.class);
    Object val = dr.read(part, reader);

    assertNotNull(val);
    assertTrue(val instanceof TradePriceData);
    assertEquals("CXF", ((TradePriceData)val).getTickerSymbol());
    assertEquals(Float.valueOf(1.0f), new Float(((TradePriceData)val).getTickerPrice()));
}
 
Example 5
Source File: XMLStreamDataReaderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@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());
}