Search in sources :

Example 1 with GreetMe

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

the class BareInInterceptorTest method setUpUsingHelloWorld.

private void setUpUsingHelloWorld() throws Exception {
    String ns = "http://apache.org/hello_world_soap_http";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource("/wsdl/jaxb/hello_world.wsdl").toString(), new QName(ns, "SOAPService"));
    service = factory.create();
    endpointInfo = service.getServiceInfos().get(0).getEndpoint(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 : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) Exchange(org.apache.cxf.message.Exchange) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 2 with GreetMe

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

the class JAXBEncoderDecoderTest method testMarshallIntoStaxEventWriter.

@Test
public void testMarshallIntoStaxEventWriter() 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);
    FixNamespacesXMLEventWriter writer = new FixNamespacesXMLEventWriter(opFactory.createXMLEventWriter(baos));
    assertNull(writer.getMarshaller());
    // STARTDOCUMENT/ENDDOCUMENT is not required
    // writer.add(eFactory.createStartDocument("utf-8", "1.0"));
    Marshaller m = context.createMarshaller();
    JAXBEncoderDecoder.marshall(m, obj, part, writer);
    assertEquals(m, writer.getMarshaller());
    // writer.add(eFactory.createEndDocument());
    writer.flush();
    writer.close();
    // System.out.println(baos.toString());
    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 3 with GreetMe

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

the class JAXBEncoderDecoderTest method testMarshallWithoutQNameInfo.

@Test
public void testMarshallWithoutQNameInfo() throws Exception {
    GreetMe obj = new GreetMe();
    obj.setRequestType("Hello");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
    opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
    XMLEventWriter writer = opFactory.createXMLEventWriter(baos);
    // STARTDOCUMENT/ENDDOCUMENT is not required
    // writer.add(eFactory.createStartDocument("utf-8", "1.0"));
    JAXBEncoderDecoder.marshall(context.createMarshaller(), obj, null, writer);
    // writer.add(eFactory.createEndDocument());
    writer.flush();
    writer.close();
    // System.out.println(baos.toString());
    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) XMLEventWriter(javax.xml.stream.XMLEventWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLEventReader(javax.xml.stream.XMLEventReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) XMLInputFactory(javax.xml.stream.XMLInputFactory) Test(org.junit.Test)

Example 4 with GreetMe

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

the class DocLiteralInInterceptorTest method setUpUsingHelloWorld.

private void setUpUsingHelloWorld() throws Exception {
    String ns = "http://apache.org/hello_world_soap_http";
    WSDLServiceFactory factory = new WSDLServiceFactory(bus, getClass().getResource("/wsdl/jaxb/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 : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) Exchange(org.apache.cxf.message.Exchange) WSDLServiceFactory(org.apache.cxf.wsdl11.WSDLServiceFactory) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 5 with GreetMe

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

the class DocLiteralInInterceptorTest method testInterceptorInboundWrapped.

@Test
public void testInterceptorInboundWrapped() throws Exception {
    setUpUsingHelloWorld();
    // WrappedInInterceptor interceptor = new WrappedInInterceptor();
    DocLiteralInInterceptor interceptor = new DocLiteralInInterceptor();
    message.setContent(XMLStreamReader.class, XMLInputFactory.newInstance().createXMLStreamReader(getTestStream(getClass(), "resources/GreetMeDocLiteralReq.xml")));
    XMLStreamReader reader = message.getContent(XMLStreamReader.class);
    // skip the start element of soap body
    StaxUtils.skipToStartOfElement(reader);
    message.put(Message.INBOUND_MESSAGE, Message.INBOUND_MESSAGE);
    interceptor.handleMessage(message);
    assertNull(message.getContent(Exception.class));
    List<?> parameters = message.getContent(List.class);
    assertEquals(1, parameters.size());
    Object obj = parameters.get(0);
    assertTrue(obj instanceof GreetMe);
    GreetMe greet = (GreetMe) obj;
    assertEquals("TestSOAPInputPMessage", greet.getRequestType());
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) XMLStreamReader(javax.xml.stream.XMLStreamReader) DocLiteralInInterceptor(org.apache.cxf.wsdl.interceptors.DocLiteralInInterceptor) 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