You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by tl...@apache.org on 2006/11/03 07:41:18 UTC
svn commit: r470688 - in /incubator/cxf/trunk:
rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java
systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLWrapTest.java
Author: tli
Date: Thu Nov 2 22:41:17 2006
New Revision: 470688
URL: http://svn.apache.org/viewvc?view=rev&rev=470688
Log:
CXF-196 applied Ajay's patch and modify xml wrap systest to include this scenario
Modified:
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLWrapTest.java
Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java?view=diff&rev=470688&r1=470687&r2=470688
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java (original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.java Thu Nov 2 22:41:17 2006
@@ -59,19 +59,17 @@
try {
nsStack.add(XMLConstants.NS_XML_FORMAT);
String prefix = nsStack.getPrefix(XMLConstants.NS_XML_FORMAT);
-
- StaxUtils.writeStartElement(writer, prefix, XMLFault.XML_FAULT_ROOT, XMLConstants.NS_XML_FORMAT);
-
- StaxUtils
- .writeStartElement(writer, prefix, XMLFault.XML_FAULT_STRING, XMLConstants.NS_XML_FORMAT);
- Throwable t = xmlFault.getCause();
+ StaxUtils.writeStartElement(writer, prefix, XMLFault.XML_FAULT_ROOT,
+ XMLConstants.NS_XML_FORMAT);
+ StaxUtils.writeStartElement(writer, prefix, XMLFault.XML_FAULT_STRING,
+ XMLConstants.NS_XML_FORMAT);
+ Throwable t = xmlFault.getCause();
writer.writeCharacters(t == null ? xmlFault.getMessage() : t.toString());
// fault string
writer.writeEndElement();
-
// call data writer to marshal exception
BindingOperationInfo bop = message.getExchange().get(BindingOperationInfo.class);
- if (bop != null) {
+ if (t != null && bop != null) {
if (!bop.isUnwrappedCapable()) {
bop = bop.getUnwrappedOperation();
}
@@ -81,11 +79,15 @@
FaultInfo fi = it.next();
for (MessagePartInfo mpi : fi.getMessageParts()) {
Class cls = mpi.getTypeClass();
- Method method = t.getClass().getMethod("getFaultInfo", new Class[0]);
- Class sub = method.getReturnType();
- if (cls != null && cls.equals(sub)) {
- part = mpi;
- break;
+ try {
+ Method method = t.getClass().getMethod("getFaultInfo", new Class[0]);
+ Class sub = method.getReturnType();
+ if (cls != null && cls.equals(sub)) {
+ part = mpi;
+ break;
+ }
+ } catch (NoSuchMethodException ne) {
+ // Ignore as it is not a User Defined Fault.
}
}
}
@@ -96,18 +98,13 @@
dataWriter.write(getFaultInfo(t), part, message);
writer.writeEndElement();
}
- }
+ }
// fault root
writer.writeEndElement();
-
writer.flush();
-
- } catch (NoSuchMethodException ne) {
- throw new Fault(new org.apache.cxf.common.i18n.Message("UNKNOWN_EXCEPTION", BUNDLE), ne);
} catch (XMLStreamException xe) {
throw new Fault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), xe);
}
-
}
private static Object getFaultInfo(Throwable fault) {
@@ -119,7 +116,6 @@
} catch (Exception ex) {
throw new RuntimeException("Could not get faultInfo out of Exception", ex);
}
-
return null;
}
}
Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLWrapTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLWrapTest.java?view=diff&rev=470688&r1=470687&r2=470688
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLWrapTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerXMLWrapTest.java Thu Nov 2 22:41:17 2006
@@ -35,6 +35,7 @@
import org.apache.cxf.systest.common.ClientServerSetupBase;
import org.apache.cxf.systest.common.TestServerBase;
import org.apache.hello_world_xml_http.wrapped.Greeter;
+import org.apache.hello_world_xml_http.wrapped.GreeterFaultImpl;
import org.apache.hello_world_xml_http.wrapped.GreeterImpl;
import org.apache.hello_world_xml_http.wrapped.PingMeFault;
import org.apache.hello_world_xml_http.wrapped.XMLService;
@@ -55,6 +56,10 @@
Object implementor = new GreeterImpl();
String address = "http://localhost:9032/XMLService/XMLPort";
Endpoint.publish(address, implementor);
+
+ Object faultImplementor = new GreeterFaultImpl();
+ String faultAddress = "http://localhost:9033/XMLService/XMLFaultPort";
+ Endpoint.publish(faultAddress, faultImplementor);
}
public static void main(String[] args) {
@@ -116,7 +121,7 @@
String response1 = new String("Hello ");
String response2 = new String("Bonjour");
Greeter greeter = service.getPort(fakePortName, Greeter.class);
- try {
+ try {
String username = System.getProperty("user.name");
String reply = greeter.greetMe(username);
@@ -132,10 +137,10 @@
} catch (UndeclaredThrowableException ex) {
throw (Exception) ex.getCause();
}
- BindingProvider bp = (BindingProvider)greeter;
+ BindingProvider bp = (BindingProvider) greeter;
Map<String, Object> responseContext = bp.getResponseContext();
- Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
- assertEquals(200, responseCode.intValue());
+ Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
+ assertEquals(200, responseCode.intValue());
}
public void testXMLFault() throws Exception {
@@ -143,19 +148,28 @@
this.getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl"), serviceName);
assertNotNull(service);
Greeter greeter = service.getPort(portName, Greeter.class);
- try {
+ try {
greeter.pingMe();
fail("did not catch expected PingMeFault exception");
} catch (PingMeFault ex) {
assertEquals("minor value", 1, ex.getFaultInfo().getMinor());
assertEquals("major value", 2, ex.getFaultInfo().getMajor());
-
- BindingProvider bp = (BindingProvider)greeter;
+
+ BindingProvider bp = (BindingProvider) greeter;
Map<String, Object> responseContext = bp.getResponseContext();
String contentType = (String) responseContext.get(Message.CONTENT_TYPE);
assertEquals("text/xml", contentType);
Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
- assertEquals(500, responseCode.intValue());
+ assertEquals(500, responseCode.intValue());
+ }
+
+ Greeter greeterFault = service.getXMLFaultPort();
+ try {
+ greeterFault.pingMe();
+ fail("did not catch expected runtime exception");
+ } catch (Exception ex) {
+ assertTrue("check expected message of exception", ex.getMessage().indexOf(
+ GreeterFaultImpl.RUNTIME_EXCEPTION_MESSAGE) >= 0);
}
}
}