Search in sources :

Example 16 with GreetMe

use of org.apache.hello_world_soap_http.types.GreetMe in project cxf by apache.

the class JAXBEncoderDecoderTest method testMarshallIntoStaxStreamWriter.

@Test
public void testMarshallIntoStaxStreamWriter() throws Exception {
    GreetMe obj = new GreetMe();
    obj.setRequestType("Hello");
    QName elName = new QName(wrapperAnnotation.targetNamespace(), wrapperAnnotation.localName());
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
    opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
    FixNamespacesXMLStreamWriter writer = new FixNamespacesXMLStreamWriter(opFactory.createXMLStreamWriter(baos));
    assertNull(writer.getMarshaller());
    Marshaller m = context.createMarshaller();
    JAXBEncoderDecoder.marshall(m, obj, part, writer);
    assertEquals(m, writer.getMarshaller());
    writer.flush();
    writer.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    XMLInputFactory ipFactory = XMLInputFactory.newInstance();
    XMLEventReader reader = ipFactory.createXMLEventReader(bais);
    Unmarshaller um = context.createUnmarshaller();
    Object val = um.unmarshal(reader, GreetMe.class);
    assertTrue(val instanceof JAXBElement);
    val = ((JAXBElement<?>) val).getValue();
    assertTrue(val instanceof GreetMe);
    assertEquals(obj.getRequestType(), ((GreetMe) val).getRequestType());
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) Marshaller(javax.xml.bind.Marshaller) QName(javax.xml.namespace.QName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JAXBElement(javax.xml.bind.JAXBElement) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLEventReader(javax.xml.stream.XMLEventReader) Unmarshaller(javax.xml.bind.Unmarshaller) XMLInputFactory(javax.xml.stream.XMLInputFactory) Test(org.junit.Test)

Example 17 with GreetMe

use of org.apache.hello_world_soap_http.types.GreetMe in project cxf by apache.

the class JAXBEncoderDecoderTest method testUnmarshallFromStaxStreamReader.

@Test
public void testUnmarshallFromStaxStreamReader() throws Exception {
    QName elName = new QName(wrapperAnnotation.targetNamespace(), wrapperAnnotation.localName());
    MessagePartInfo part = new MessagePartInfo(elName, null);
    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq.xml");
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader reader = factory.createXMLStreamReader(is);
    QName[] tags = { SOAP_ENV, SOAP_BODY };
    StaxStreamFilter filter = new StaxStreamFilter(tags);
    FixNamespacesXMLStreamReader filteredReader = new FixNamespacesXMLStreamReader(factory.createFilteredReader(reader, filter));
    assertNull(filteredReader.getUnmarshaller());
    // Remove START_DOCUMENT & START_ELEMENT pertaining to Envelope and Body Tags.
    part.setTypeClass(GreetMe.class);
    Unmarshaller um = context.createUnmarshaller();
    Object val = JAXBEncoderDecoder.unmarshall(um, filteredReader, part, true);
    assertEquals(um, filteredReader.getUnmarshaller());
    assertNotNull(val);
    assertTrue(val instanceof GreetMe);
    assertEquals("TestSOAPInputPMessage", ((GreetMe) val).getRequestType());
    is.close();
}
Also used : StaxStreamFilter(org.apache.cxf.staxutils.StaxStreamFilter) GreetMe(org.apache.hello_world_soap_http.types.GreetMe) XMLStreamReader(javax.xml.stream.XMLStreamReader) QName(javax.xml.namespace.QName) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Unmarshaller(javax.xml.bind.Unmarshaller) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) XMLInputFactory(javax.xml.stream.XMLInputFactory) Test(org.junit.Test)

Example 18 with GreetMe

use of org.apache.hello_world_soap_http.types.GreetMe in project cxf by apache.

the class TestBase method setUp.

@Before
public void setUp() throws Exception {
    bus = BusFactory.newInstance().createBus();
    BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class);
    IMocksControl control = createNiceControl();
    BindingFactory bf = control.createMock(BindingFactory.class);
    Binding binding = control.createMock(Binding.class);
    expect(bf.createBinding(null)).andStubReturn(binding);
    expect(binding.getInFaultInterceptors()).andStubReturn(new ArrayList<Interceptor<? extends Message>>());
    expect(binding.getOutFaultInterceptors()).andStubReturn(new ArrayList<Interceptor<? extends Message>>());
    bfm.registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bf);
    String ns = "http://apache.org/hello_world_soap_http";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource("/org/apache/cxf/jaxb/resources/wsdl/hello_world.wsdl").toString(), new QName(ns, "SOAPService"));
    service = factory.create();
    endpointInfo = service.getEndpointInfo(new QName(ns, "SoapPort"));
    endpoint = new EndpointImpl(bus, service, endpointInfo);
    JAXBDataBinding db = new JAXBDataBinding();
    db.setContext(JAXBContext.newInstance(new Class[] { GreetMe.class, GreetMeResponse.class }));
    service.setDataBinding(db);
    operation = endpointInfo.getBinding().getOperation(new QName(ns, "greetMe"));
    operation.getOperationInfo().getInput().getMessagePartByIndex(0).setTypeClass(GreetMe.class);
    operation.getOperationInfo().getOutput().getMessagePartByIndex(0).setTypeClass(GreetMeResponse.class);
    message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    exchange.put(Service.class, service);
    exchange.put(Endpoint.class, endpoint);
    exchange.put(Binding.class, endpoint.getBinding());
}
Also used : Binding(org.apache.cxf.binding.Binding) GreetMe(org.apache.hello_world_soap_http.types.GreetMe) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) IMocksControl(org.easymock.IMocksControl) Exchange(org.apache.cxf.message.Exchange) Interceptor(org.apache.cxf.interceptor.Interceptor) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) BindingFactory(org.apache.cxf.binding.BindingFactory) Before(org.junit.Before)

Example 19 with GreetMe

use of org.apache.hello_world_soap_http.types.GreetMe in project cxf by apache.

the class XMLStreamDataWriterTest method testWriteWrapper.

@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());
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) 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) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) Test(org.junit.Test)

Aggregations

GreetMe (org.apache.hello_world_soap_http.types.GreetMe)19 Test (org.junit.Test)14 QName (javax.xml.namespace.QName)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 XMLStreamReader (javax.xml.stream.XMLStreamReader)6 GreetMeResponse (org.apache.hello_world_soap_http.types.GreetMeResponse)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Unmarshaller (javax.xml.bind.Unmarshaller)5 XMLInputFactory (javax.xml.stream.XMLInputFactory)5 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)5 JAXBElement (javax.xml.bind.JAXBElement)4 JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)4 InputStream (java.io.InputStream)3 Marshaller (javax.xml.bind.Marshaller)3 XMLEventReader (javax.xml.stream.XMLEventReader)3 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)3 EndpointImpl (org.apache.cxf.endpoint.EndpointImpl)3 Exchange (org.apache.cxf.message.Exchange)3 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)3 MessageImpl (org.apache.cxf.message.MessageImpl)3