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"));
}
Aggregations