public void testSoapFault12() throws Exception {
TransformComponentSupport echo = new TransformComponentSupport() {
protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out)
throws MessagingException {
Fault f = exchange.createFault();
f.setContent(new StringSource("<hello xmlns='myuri'>this is a fault</hello>"));
f.setProperty(JBIMarshaler.SOAP_FAULT_REASON, "My reason");
throw new FaultException(null, exchange, f);
}
};
echo.setService(new QName("urn:test", "echo"));
echo.setEndpoint("echo");
container.activateComponent(echo, "echo");
HttpEndpoint ep1 = createInOutEndpoint("ep1");
ep1.setTargetService(new QName("urn:test", "echo"));
ep1.setTargetEndpoint("echo");
ep1.setLocationURI("http://localhost:8193/ep1/");
ep1.setRoleAsString("consumer");
ep1.setSoap(true);
HttpEndpoint ep2 = createInOutEndpoint("ep2");
ep2.setTargetService(new QName("urn:test", "http"));
ep2.setTargetEndpoint("ep3");
ep2.setLocationURI("http://localhost:8193/ep2/");
ep2.setRoleAsString("consumer");
ep2.setSoap(true);
HttpEndpoint ep3 = createInOutEndpoint("ep3");
ep3.setLocationURI("http://localhost:8193/ep1/");
ep3.setRoleAsString("provider");
ep3.setDefaultMep(URI.create("http://www.w3.org/2004/08/wsdl/in-out"));
ep3.setSoap(true);
HttpComponent http = new HttpComponent();
http.setEndpoints(new HttpEndpoint[] {ep1, ep2, ep3});
container.activateComponent(http, "http1");
container.start();
PostMethod method = new PostMethod("http://localhost:8193/ep2/");
method.setRequestEntity(new InputStreamRequestEntity(getClass().getResourceAsStream("soap-request-12.xml")));
int state = new HttpClient().executeMethod(method);
assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, state);
SourceTransformer st = new SourceTransformer();
Node node = st.toDOMNode(new StreamSource(method.getResponseBodyAsStream()));
logger.info(st.toString(node));
Element e = ((Document) node).getDocumentElement();
assertEquals(new QName(SoapMarshaler.SOAP_12_URI, SoapMarshaler.ENVELOPE), DOMUtil.getQName(e));
e = DOMUtil.getFirstChildElement(e);
assertEquals(new QName(SoapMarshaler.SOAP_12_URI, SoapMarshaler.BODY), DOMUtil.getQName(e));
e = DOMUtil.getFirstChildElement(e);
assertEquals(new QName(SoapMarshaler.SOAP_12_URI, SoapMarshaler.FAULT), DOMUtil.getQName(e));
method = new PostMethod("http://localhost:8193/ep2/");
method.setRequestBody("hello");
state = new HttpClient().executeMethod(method);
String str = method.getResponseBodyAsString();
logger.info(str);
assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, state);
node = st.toDOMNode(new StringSource(str));
e = ((Document) node).getDocumentElement();
assertEquals(new QName(SoapMarshaler.SOAP_12_URI, SoapMarshaler.ENVELOPE), DOMUtil.getQName(e));
e = DOMUtil.getFirstChildElement(e);
assertEquals(new QName(SoapMarshaler.SOAP_12_URI, SoapMarshaler.BODY), DOMUtil.getQName(e));
e = DOMUtil.getFirstChildElement(e);
assertEquals(new QName(SoapMarshaler.SOAP_12_URI, SoapMarshaler.FAULT), DOMUtil.getQName(e));
method = new PostMethod("http://localhost:8193/ep2/");
method.setRequestBody("<hello/>");
state = new HttpClient().executeMethod(method);
str = method.getResponseBodyAsString();
logger.info(str);
assertEquals(HttpServletResponse.SC_BAD_REQUEST, state);
node = st.toDOMNode(new StringSource(str));
e = ((Document) node).getDocumentElement();
assertEquals(new QName(SoapMarshaler.SOAP_12_URI, SoapMarshaler.ENVELOPE), DOMUtil.getQName(e));
e = DOMUtils.getFirstChildElement(e);
assertEquals(new QName(SoapMarshaler.SOAP_12_URI, SoapMarshaler.BODY), DOMUtil.getQName(e));
e = DOMUtils.getFirstChildElement(e);