use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.
the class XMLStreamDataWriterTest method newDataWriter.
private DataWriterImpl<XMLStreamWriter> newDataWriter(ValidationEventHandler handler) throws Exception {
JAXBDataBinding db = getTestWriterFactory();
DataWriterImpl<XMLStreamWriter> dw = (DataWriterImpl<XMLStreamWriter>) db.createWriter(XMLStreamWriter.class);
assertNotNull(dw);
// Build message to set custom event handler
org.apache.cxf.message.Message message = new org.apache.cxf.message.MessageImpl();
message.put(JAXBDataBinding.WRITER_VALIDATION_EVENT_HANDLER, handler);
dw.setProperty("org.apache.cxf.message.Message", message);
return dw;
}
use of org.apache.cxf.jaxb.JAXBDataBinding 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());
}
use of org.apache.cxf.jaxb.JAXBDataBinding 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());
}
use of org.apache.cxf.jaxb.JAXBDataBinding 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());
}
use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.
the class XMLStreamDataReaderTest method testReadWrapperReturn.
@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());
}
Aggregations