Search in sources :

Example 11 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class JAXBEncoderDecoderTest method testUnMarshall.

@Test
public void testUnMarshall() throws Exception {
    // Hello World Wsdl generated namespace
    QName elName = new QName(wrapperAnnotation.targetNamespace(), wrapperAnnotation.localName());
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    part.setTypeClass(Class.forName(wrapperAnnotation.className()));
    Document doc = DOMUtils.getEmptyDocument();
    Element elNode = doc.createElementNS(elName.getNamespaceURI(), elName.getLocalPart());
    Element rtEl = doc.createElementNS(elName.getNamespaceURI(), "requestType");
    elNode.appendChild(rtEl);
    rtEl.appendChild(doc.createTextNode("Hello Test"));
    Object obj = JAXBEncoderDecoder.unmarshall(context.createUnmarshaller(), elNode, part, true);
    assertNotNull(obj);
    // Add a Node and then test
    assertEquals(GreetMe.class, obj.getClass());
    assertEquals("Hello Test", ((GreetMe) obj).getRequestType());
    part.setTypeClass(String.class);
    Node n = null;
    try {
        JAXBEncoderDecoder.unmarshall(context.createUnmarshaller(), n, part, true);
        fail("Should have received a Fault");
    } catch (Fault pe) {
    // Expected Exception
    } catch (Exception ex) {
        fail("Should have received a Fault, not: " + ex);
    }
    // Now test schema validation during unmarshaling
    elName = new QName(wrapperAnnotation.targetNamespace(), "stringStruct");
    // Create an XML Tree of
    // <StringStruct><arg1>World</arg1></StringStruct>
    // elNode = soapElFactory.createElement(elName);
    // elNode.addNamespaceDeclaration("", elName.getNamespaceURI());
    part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    part.setTypeClass(Class.forName("org.apache.hello_world_soap_http.types.StringStruct"));
    doc = DOMUtils.getEmptyDocument();
    elNode = doc.createElementNS(elName.getNamespaceURI(), elName.getLocalPart());
    rtEl = doc.createElementNS(elName.getNamespaceURI(), "arg1");
    elNode.appendChild(rtEl);
    rtEl.appendChild(doc.createTextNode("World"));
    // Should unmarshal without problems when no schema used.
    obj = JAXBEncoderDecoder.unmarshall(context.createUnmarshaller(), elNode, part, true);
    assertNotNull(obj);
    assertEquals(StringStruct.class, obj.getClass());
    assertEquals("World", ((StringStruct) obj).getArg1());
    try {
        // unmarshal with schema should raise exception.
        Unmarshaller m = context.createUnmarshaller();
        m.setSchema(schema);
        JAXBEncoderDecoder.unmarshall(m, elNode, part, true);
        fail("Should have thrown a Fault");
    } catch (Fault ex) {
    // expected - schema validation should fail.
    }
}
Also used : 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) Document(org.w3c.dom.Document) Unmarshaller(javax.xml.bind.Unmarshaller) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Test(org.junit.Test)

Example 12 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class JAXBEncoderDecoderTest method testMarshalRPCLit.

@Test
public void testMarshalRPCLit() throws Exception {
    QName elName = new QName("http://test_jaxb_marshall", "in");
    MessagePartInfo part = new MessagePartInfo(elName, null);
    part.setElement(true);
    part.setElementQName(elName);
    Document doc = DOMUtils.createDocument();
    Element elNode = doc.createElementNS(elName.getNamespaceURI(), elName.getLocalPart());
    JAXBEncoderDecoder.marshall(context.createMarshaller(), new String("TestSOAPMessage"), part, elNode);
    assertEquals("TestSOAPMessage", elNode.getFirstChild().getFirstChild().getNodeValue());
}
Also used : QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) ObjectWithQualifiedElementElement(org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Test(org.junit.Test)

Example 13 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class JAXBEncoderDecoderTest method testMarshallExceptionWithOrder.

@Test
public void testMarshallExceptionWithOrder() throws Exception {
    Document doc = DOMUtils.getEmptyDocument();
    Element elNode = doc.createElementNS("http://cxf.apache.org", "ExceptionRoot");
    OrderException exception = new OrderException("Mymessage");
    exception.setAValue("avalue");
    exception.setDetail("detail");
    exception.setInfo1("info1");
    exception.setInfo2("info2");
    exception.setIntVal(10000);
    QName elName = new QName("http://cxf.apache.org", "OrderException");
    ServiceInfo serviceInfo = new ServiceInfo();
    InterfaceInfo interfaceInfo = new InterfaceInfo(serviceInfo, null);
    OperationInfo op = interfaceInfo.addOperation(new QName("http://cxf.apache.org", "operation"));
    MessageInfo message = new MessageInfo(op, null, null);
    MessagePartInfo part = new MessagePartInfo(elName, message);
    part.setElement(true);
    part.setElementQName(elName);
    part.setTypeClass(OrderException.class);
    // just need a simple generic context to handle the exceptions internal primitives
    JAXBContext exceptionContext = JAXBContext.newInstance(new Class[] { String.class });
    JAXBEncoderDecoder.marshallException(exceptionContext.createMarshaller(), exception, part, elNode);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    StaxUtils.writeTo(elNode, bout);
    int a = bout.toString().lastIndexOf("aValue");
    int b = bout.toString().lastIndexOf("detail");
    int c = bout.toString().lastIndexOf("info1");
    int d = bout.toString().lastIndexOf("info2");
    int e = bout.toString().lastIndexOf("intVal");
    assertTrue(a < b);
    assertTrue(b < c);
    assertTrue(c < d);
    assertTrue(d < e);
    assertTrue(bout.toString().indexOf("transientValue") < 0);
    assertTrue(bout.toString(), bout.toString().indexOf("mappedField=\"MappedField\"") > 0);
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement) ObjectWithQualifiedElementElement(org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement) Element(org.w3c.dom.Element) JAXBContext(javax.xml.bind.JAXBContext) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) Test(org.junit.Test)

Example 14 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class XMLStreamDataWriterTest method testWriteRPCLit1.

@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());
}
Also used : 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) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Test(org.junit.Test)

Example 15 with MessagePartInfo

use of org.apache.cxf.service.model.MessagePartInfo in project cxf by apache.

the class XMLStreamDataWriterTest method testSetProperty.

@Test
public void testSetProperty() throws Exception {
    MyCustomHandler handler = new MyCustomHandler();
    DataWriterImpl<XMLStreamWriter> dw = newDataWriter(handler);
    // Write Stuff
    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();
    // Test MyCustomHandler
    assertTrue(handler.getUsed());
}
Also used : XMLStreamWriter(javax.xml.stream.XMLStreamWriter) QName(javax.xml.namespace.QName) TradePriceData(org.apache.hello_world_doc_lit_bare.types.TradePriceData) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) Test(org.junit.Test)

Aggregations

MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)163 QName (javax.xml.namespace.QName)99 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)60 OperationInfo (org.apache.cxf.service.model.OperationInfo)46 MessageInfo (org.apache.cxf.service.model.MessageInfo)38 Test (org.junit.Test)38 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)29 Fault (org.apache.cxf.interceptor.Fault)21 Service (org.apache.cxf.service.Service)21 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)21 BindingInfo (org.apache.cxf.service.model.BindingInfo)20 ArrayList (java.util.ArrayList)19 Endpoint (org.apache.cxf.endpoint.Endpoint)18 MessageContentsList (org.apache.cxf.message.MessageContentsList)18 SoapOperationInfo (org.apache.cxf.binding.soap.model.SoapOperationInfo)16 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)15 XMLStreamReader (javax.xml.stream.XMLStreamReader)13 Exchange (org.apache.cxf.message.Exchange)13 XmlSchemaElement (org.apache.ws.commons.schema.XmlSchemaElement)13 Method (java.lang.reflect.Method)12