Search in sources :

Example 1 with ObjectWithQualifiedElementElement

use of org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement in project cxf by apache.

the class JAXBEncoderDecoderTest method testMarshallWithFormQualifiedElement.

@Test
public void testMarshallWithFormQualifiedElement() throws Exception {
    ObjectWithQualifiedElementElement testObject = new ObjectWithQualifiedElementElement();
    testObject.setString1("twine");
    testObject.setString2("cord");
    QName elName = new QName(wrapperAnnotation.targetNamespace(), wrapperAnnotation.localName());
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    StringWriter stringWriter = new StringWriter();
    XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
    opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
    XMLEventWriter writer = opFactory.createXMLEventWriter(stringWriter);
    JAXBEncoderDecoder.marshall(context.createMarshaller(), testObject, part, writer);
    writer.flush();
    writer.close();
    String xmlResult = stringWriter.toString();
    // the following is a bit of a crock, but, to tell the truth, this test case most exists
    // so that it could be examined inside the debugger to see how JAXB works.
    assertTrue(xmlResult.contains(":string2>cord</ns"));
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) ObjectWithQualifiedElementElement(org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement) StringWriter(java.io.StringWriter) XMLEventWriter(javax.xml.stream.XMLEventWriter) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Test(org.junit.Test)

Example 2 with ObjectWithQualifiedElementElement

use of org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement in project cxf by apache.

the class JAXBEncoderDecoderTest method testCustomNamespaces.

@Test
public void testCustomNamespaces() throws Exception {
    Map<String, String> mapper = new HashMap<>();
    mapper.put("http://apache.org/hello_world_soap_http/types", "Omnia");
    mapper.put("http://cxf.apache.org/jaxb_form", "Gallia");
    ObjectWithQualifiedElementElement testObject = new ObjectWithQualifiedElementElement();
    testObject.setString1("twine");
    testObject.setString2("cord");
    QName elName = new QName(wrapperAnnotation.targetNamespace(), wrapperAnnotation.localName());
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    StringWriter stringWriter = new StringWriter();
    XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
    opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
    XMLEventWriter writer = opFactory.createXMLEventWriter(stringWriter);
    Marshaller m = context.createMarshaller();
    JAXBUtils.setNamespaceMapper(mapper, m);
    JAXBEncoderDecoder.marshall(m, testObject, part, writer);
    writer.flush();
    writer.close();
    String xmlResult = stringWriter.toString();
    // the following is a bit of a crock, but, to tell the truth, this test case most exists
    // so that it could be examined inside the debugger to see how JAXB works.
    assertTrue(xmlResult.contains("Gallia:string2"));
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) Marshaller(javax.xml.bind.Marshaller) ObjectWithQualifiedElementElement(org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) XMLEventWriter(javax.xml.stream.XMLEventWriter) QName(javax.xml.namespace.QName) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Test(org.junit.Test)

Aggregations

StringWriter (java.io.StringWriter)2 QName (javax.xml.namespace.QName)2 XMLEventWriter (javax.xml.stream.XMLEventWriter)2 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)2 ObjectWithQualifiedElementElement (org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement)2 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Marshaller (javax.xml.bind.Marshaller)1