Search in sources :

Example 11 with GreetMe

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

the class BareInInterceptorTest method testInterceptorInbound.

@Test
public void testInterceptorInbound() throws Exception {
    setUpUsingHelloWorld();
    BareInInterceptor interceptor = new BareInInterceptor();
    message.setContent(XMLStreamReader.class, XMLInputFactory.newInstance().createXMLStreamReader(getTestStream(getClass(), "resources/GreetMeDocLiteralReq.xml")));
    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) BareInInterceptor(org.apache.cxf.wsdl.interceptors.BareInInterceptor) Test(org.junit.Test)

Example 12 with GreetMe

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

the class BareOutInterceptorTest method testWriteInbound.

@Test
public void testWriteInbound() throws Exception {
    GreetMe greetMe = new GreetMe();
    greetMe.setRequestType("requestType");
    message.setContent(List.class, Arrays.asList(greetMe));
    message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
    interceptor.handleMessage(message);
    writer.close();
    assertNull(message.getContent(Exception.class));
    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_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());
}
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) QName(javax.xml.namespace.QName) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) Test(org.junit.Test)

Example 13 with GreetMe

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

the class JAXBEncoderDecoderTest method testMarshallIntoDOM.

@Test
public void testMarshallIntoDOM() throws Exception {
    String str = new String("Hello");
    QName inCorrectElName = new QName("http://test_jaxb_marshall", "requestType");
    MessagePartInfo part = new MessagePartInfo(inCorrectElName, null);
    part.setElement(true);
    part.setElementQName(inCorrectElName);
    Document doc = DOMUtils.createDocument();
    Element elNode = doc.createElementNS(inCorrectElName.getNamespaceURI(), inCorrectElName.getLocalPart());
    assertNotNull(elNode);
    Node node;
    try {
        JAXBEncoderDecoder.marshall(context.createMarshaller(), null, part, elNode);
        fail("Should have thrown a Fault");
    } catch (Fault ex) {
    // expected - not a valid object
    }
    GreetMe obj = new GreetMe();
    obj.setRequestType("Hello");
    QName elName = new QName(wrapperAnnotation.targetNamespace(), wrapperAnnotation.localName());
    part.setElementQName(elName);
    JAXBEncoderDecoder.marshall(context.createMarshaller(), obj, part, elNode);
    node = elNode.getLastChild();
    // The XML Tree Looks like
    // <GreetMe><requestType>Hello</requestType></GreetMe>
    assertEquals(Node.ELEMENT_NODE, node.getNodeType());
    Node childNode = node.getFirstChild();
    assertEquals(Node.ELEMENT_NODE, childNode.getNodeType());
    childNode = childNode.getFirstChild();
    assertEquals(Node.TEXT_NODE, childNode.getNodeType());
    assertEquals(str, childNode.getNodeValue());
    // Now test schema validation during marshaling
    StringStruct stringStruct = new StringStruct();
    // Don't initialize one of the structure members.
    // stringStruct.setArg0("hello");
    stringStruct.setArg1("world");
    // Marshal without the schema should work.
    JAXBEncoderDecoder.marshall(context.createMarshaller(), stringStruct, part, elNode);
    try {
        Marshaller m = context.createMarshaller();
        m.setSchema(schema);
        // Marshal with the schema should get an exception.
        JAXBEncoderDecoder.marshall(m, stringStruct, part, elNode);
        fail("Marshal with schema should have thrown a Fault");
    } catch (Fault ex) {
    // expected - not a valid object
    }
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) Marshaller(javax.xml.bind.Marshaller) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) ObjectWithQualifiedElementElement(org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) Fault(org.apache.cxf.interceptor.Fault) StringStruct(org.apache.hello_world_soap_http.types.StringStruct) Document(org.w3c.dom.Document) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Test(org.junit.Test)

Example 14 with GreetMe

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

the class JAXBEncoderDecoderTest method testUnmarshallFromStaxEventReader.

@Test
public void testUnmarshallFromStaxEventReader() 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();
    FixNamespacesXMLEventReader reader = new FixNamespacesXMLEventReader(factory.createXMLEventReader(is));
    assertNull(reader.getUnmarshaller());
    part.setTypeClass(GreetMe.class);
    Unmarshaller um = context.createUnmarshaller();
    Object val = JAXBEncoderDecoder.unmarshall(um, reader, part, true);
    assertEquals(um, reader.getUnmarshaller());
    assertNotNull(val);
    assertTrue(val instanceof GreetMe);
    assertEquals("TestSOAPInputPMessage", ((GreetMe) val).getRequestType());
    is.close();
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) 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 15 with GreetMe

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

the class JAXBEncoderDecoderTest method setUp.

@Before
public void setUp() throws Exception {
    context = JAXBContext.newInstance(new Class[] { GreetMe.class, GreetMeResponse.class, StringStruct.class, ObjectWithQualifiedElementElement.class });
    Method method = getMethod("greetMe");
    wrapperAnnotation = method.getAnnotation(RequestWrapper.class);
    InputStream is = getClass().getResourceAsStream("resources/StringStruct.xsd");
    StreamSource schemaSource = new StreamSource(is);
    assertNotNull(schemaSource);
    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    schema = factory.newSchema(schemaSource);
    assertNotNull(schema);
}
Also used : GreetMe(org.apache.hello_world_soap_http.types.GreetMe) SchemaFactory(javax.xml.validation.SchemaFactory) ObjectWithQualifiedElementElement(org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) RequestWrapper(javax.xml.ws.RequestWrapper) StringStruct(org.apache.hello_world_soap_http.types.StringStruct) Method(java.lang.reflect.Method) GreetMeResponse(org.apache.hello_world_soap_http.types.GreetMeResponse) Before(org.junit.Before)

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