Java Code Examples for org.apache.cxf.jaxb.JAXBDataBinding#createWriter()
The following examples show how to use
org.apache.cxf.jaxb.JAXBDataBinding#createWriter() .
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: XMLStreamDataWriterTest.java From cxf with Apache License 2.0 | 6 votes |
@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); } }
Example 2
Source File: XMLStreamDataWriterTest.java From cxf with Apache License 2.0 | 5 votes |
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; }
Example 3
Source File: XMLStreamDataWriterTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testWriteRPCLit1() throws Exception { JAXBDataBinding db = getTestWriterFactory(); DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class); assertNotNull(dw); String val = new String("TESTOUTPUTMESSAGE"); 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.toNextText(reader); assertEquals("TESTOUTPUTMESSAGE", reader.getText()); }
Example 4
Source File: XMLStreamDataWriterTest.java From cxf with Apache License 2.0 | 5 votes |
@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()); }
Example 5
Source File: XMLStreamDataWriterTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testWriteBare() throws Exception { JAXBDataBinding db = getTestWriterFactory(TradePriceData.class); DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class); assertNotNull(dw); TradePriceData val = new TradePriceData(); val.setTickerSymbol("This is a symbol"); val.setTickerPrice(1.0f); 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); 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_doc_lit_bare/types", "inout"), reader.getName()); StaxUtils.nextEvent(reader); StaxUtils.toNextElement(reader); assertEquals(new QName("http://apache.org/hello_world_doc_lit_bare/types", "tickerSymbol"), reader.getName()); StaxUtils.nextEvent(reader); StaxUtils.toNextText(reader); assertEquals("This is a symbol", reader.getText()); }
Example 6
Source File: XMLStreamDataWriterTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testWriteWrapper() throws Exception { JAXBDataBinding db = getTestWriterFactory(GreetMe.class); DataWriter<XMLStreamWriter> dw = db.createWriter(XMLStreamWriter.class); assertNotNull(dw); GreetMe val = new GreetMe(); val.setRequestType("Hello"); dw.write(val, 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", "greetMe"), reader.getName()); StaxUtils.nextEvent(reader); StaxUtils.toNextElement(reader); assertEquals(new QName("http://apache.org/hello_world_soap_http/types", "requestType"), reader.getName()); StaxUtils.nextEvent(reader); StaxUtils.toNextText(reader); assertEquals("Hello", reader.getText()); }
Example 7
Source File: XMLStreamDataWriterTest.java From cxf with Apache License 2.0 | 5 votes |
@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()); }
Example 8
Source File: XMLStreamDataWriterTest.java From cxf with Apache License 2.0 | 5 votes |
@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()); }