Java Code Examples for org.apache.cxf.staxutils.StaxUtils#toNextText()
The following examples show how to use
org.apache.cxf.staxutils.StaxUtils#toNextText() .
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: XMLMessageOutInterceptorTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testWrapOut() throws Exception { GreetMe greetMe = new GreetMe(); greetMe.setRequestType("tli"); params.add(greetMe); common("/wsdl/hello_world_xml_wrapped.wsdl", new QName(wrapNs, "XMLPort"), GreetMe.class); BindingInfo bi = super.serviceInfo.getBinding(new QName(wrapNs, "Greeter_XMLBinding")); BindingOperationInfo boi = bi.getOperation(new QName(wrapNs, "greetMe")); xmlMessage.getExchange().put(BindingOperationInfo.class, boi); out.handleMessage(xmlMessage); XMLStreamReader reader = getXMLReader(); DepthXMLStreamReader dxr = new DepthXMLStreamReader(reader); StaxUtils.nextEvent(dxr); StaxUtils.toNextElement(dxr); assertEquals(wrapGreetMeQName.getNamespaceURI(), dxr.getNamespaceURI()); assertEquals(wrapGreetMeQName.getLocalPart(), dxr.getLocalName()); StaxUtils.toNextElement(dxr); StaxUtils.toNextText(dxr); assertEquals(greetMe.getRequestType(), dxr.getText()); }
Example 2
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 3
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 4
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 5
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 6
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 7
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()); }
Example 8
Source File: XMLMessageOutInterceptorTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testBareOutSingle() throws Exception { MyComplexStructType myComplexStruct = new MyComplexStructType(); myComplexStruct.setElem1("elem1"); myComplexStruct.setElem2("elem2"); myComplexStruct.setElem3(45); params.add(myComplexStruct); common("/wsdl/hello_world_xml_bare.wsdl", new QName(bareNs, "XMLPort"), MyComplexStructType.class); BindingInfo bi = super.serviceInfo.getBinding(new QName(bareNs, "Greeter_XMLBinding")); BindingOperationInfo boi = bi.getOperation(new QName(bareNs, "sendReceiveData")); xmlMessage.getExchange().put(BindingOperationInfo.class, boi); out.handleMessage(xmlMessage); XMLStreamReader reader = getXMLReader(); DepthXMLStreamReader dxr = new DepthXMLStreamReader(reader); StaxUtils.nextEvent(dxr); StaxUtils.toNextElement(dxr); assertEquals(bareMyComplexStructTypeQName.getLocalPart(), dxr.getLocalName()); StaxUtils.toNextElement(dxr); StaxUtils.toNextText(dxr); assertEquals(myComplexStruct.getElem1(), dxr.getText()); }
Example 9
Source File: RPCOutInterceptorTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testWriteOutbound() throws Exception { RPCOutInterceptor interceptor = new RPCOutInterceptor(); soapMessage.setContent(XMLStreamWriter.class, XMLOutputFactory.newInstance().createXMLStreamWriter( baos)); soapMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE); interceptor.handleMessage(soapMessage); assertNull(soapMessage.getContent(Exception.class)); soapMessage.getContent(XMLStreamWriter.class).flush(); baos.flush(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); XMLStreamReader xr = StaxUtils.createXMLStreamReader(bais); DepthXMLStreamReader reader = new DepthXMLStreamReader(xr); StaxUtils.toNextElement(reader); assertEquals(new QName("http://apache.org/hello_world_rpclit", "sendReceiveData"), reader.getName()); StaxUtils.nextEvent(reader); StaxUtils.toNextElement(reader); assertEquals(new QName(null, "in"), reader.getName()); StaxUtils.toNextText(reader); assertEquals("elem1", reader.getText()); }
Example 10
Source File: RPCOutInterceptorTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testWriteInbound() throws Exception { RPCOutInterceptor interceptor = new RPCOutInterceptor(); soapMessage.setContent(XMLStreamWriter.class, XMLOutputFactory.newInstance().createXMLStreamWriter( baos)); interceptor.handleMessage(soapMessage); assertNull(soapMessage.getContent(Exception.class)); soapMessage.getContent(XMLStreamWriter.class).flush(); baos.flush(); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); XMLStreamReader xr = StaxUtils.createXMLStreamReader(bais); DepthXMLStreamReader reader = new DepthXMLStreamReader(xr); StaxUtils.toNextElement(reader); assertEquals(new QName("http://apache.org/hello_world_rpclit", "sendReceiveDataResponse"), reader .getName()); StaxUtils.nextEvent(reader); StaxUtils.toNextElement(reader); assertEquals(new QName(null, "out"), 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("elem1", reader.getText()); }
Example 11
Source File: XMLMessageOutInterceptorTest.java From cxf with Apache License 2.0 | 4 votes |
@Test public void testBareOutMultiWithRoot() throws Exception { MyComplexStructType myComplexStruct = new MyComplexStructType(); myComplexStruct.setElem1("elem1"); myComplexStruct.setElem2("elem2"); myComplexStruct.setElem3(45); params.add("tli"); params.add(myComplexStruct); common("/wsdl/hello_world_xml_bare.wsdl", new QName(bareNs, "XMLPort"), MyComplexStructType.class); BindingInfo bi = super.serviceInfo.getBinding(new QName(bareNs, "Greeter_XMLBinding")); BindingOperationInfo boi = bi.getOperation(new QName(bareNs, "testMultiParamPart")); xmlMessage.getExchange().put(BindingOperationInfo.class, boi); out.handleMessage(xmlMessage); XMLStreamReader reader = getXMLReader(); DepthXMLStreamReader dxr = new DepthXMLStreamReader(reader); StaxUtils.nextEvent(dxr); StaxUtils.toNextElement(dxr); assertEquals(bareNs, dxr.getNamespaceURI()); assertEquals("multiParamRootReq", dxr.getLocalName()); StaxUtils.nextEvent(dxr); StaxUtils.toNextElement(dxr); assertEquals(bareRequestTypeQName, dxr.getName()); StaxUtils.nextEvent(dxr); if (StaxUtils.toNextText(dxr)) { assertEquals("tli", dxr.getText()); } boolean foundRequest = false; while (true) { StaxUtils.nextEvent(dxr); StaxUtils.toNextElement(dxr); QName requestType = new QName(dxr.getNamespaceURI(), dxr.getLocalName()); if (requestType.equals(bareMyComplexStructQName)) { foundRequest = true; break; } } assertTrue("found request type", foundRequest); }