Search in sources :

Example 1 with TransientMessageException

use of org.apache.cxf.tools.fortest.exception.TransientMessageException in project cxf by apache.

the class JavaToProcessorTest method testTransientMessage.

@Test
public void testTransientMessage() throws Exception {
    // CXF-5744
    env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/transient_message.wsdl");
    env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.exception.Echo4");
    env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
    try {
        processor.setEnvironment(env);
        processor.process();
    } catch (Exception e) {
        e.printStackTrace();
    }
    File wsdlFile = new File(output, "transient_message.wsdl");
    assertTrue(wsdlFile.exists());
    Document doc = StaxUtils.read(wsdlFile);
    // StaxUtils.print(doc);
    Map<String, String> map = new HashMap<>();
    map.put("xsd", "http://www.w3.org/2001/XMLSchema");
    map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/");
    map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
    map.put("tns", "http://cxf.apache.org/test/HelloService");
    XPathUtils util = new XPathUtils(map);
    String path = "//xsd:complexType[@name='TransientMessageException']//xsd:sequence/xsd:element[@name='message']";
    Element nd = (Element) util.getValueNode(path, doc);
    assertNull(nd);
    // ok, we didn't map it into the schema.  Make sure the runtime won't write it out.
    List<ServiceInfo> sl = CastUtils.cast((List<?>) env.get("serviceList"));
    FaultInfo mi = sl.get(0).getInterface().getOperation(new QName("http://cxf.apache.org/test/HelloService", "echo")).getFault(new QName("http://cxf.apache.org/test/HelloService", "TransientMessageException"));
    MessagePartInfo mpi = mi.getMessagePart(0);
    JAXBContext ctx = JAXBContext.newInstance(String.class, Integer.TYPE);
    StringWriter sw = new StringWriter();
    XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(sw);
    TransientMessageException tme = new TransientMessageException(12, "Exception Message");
    Marshaller ms = ctx.createMarshaller();
    ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
    JAXBEncoderDecoder.marshallException(ms, tme, mpi, writer);
    writer.flush();
    writer.close();
    assertEquals(-1, sw.getBuffer().indexOf("Exception Message"));
}
Also used : FaultInfo(org.apache.cxf.service.model.FaultInfo) Marshaller(javax.xml.bind.Marshaller) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) JAXBContext(javax.xml.bind.JAXBContext) Document(org.w3c.dom.Document) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) TransientMessageException(org.apache.cxf.tools.fortest.exception.TransientMessageException) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) TransientMessageException(org.apache.cxf.tools.fortest.exception.TransientMessageException) StringWriter(java.io.StringWriter) XPathUtils(org.apache.cxf.helpers.XPathUtils) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) File(java.io.File) Test(org.junit.Test)

Aggregations

File (java.io.File)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 QName (javax.xml.namespace.QName)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 XPathUtils (org.apache.cxf.helpers.XPathUtils)1 FaultInfo (org.apache.cxf.service.model.FaultInfo)1 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)1 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)1 TransientMessageException (org.apache.cxf.tools.fortest.exception.TransientMessageException)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1