Author: ajaypaibir
Date: Tue Jan 23 05:41:49 2007
New Revision: 499019
URL: http://svn.apache.org/viewvc?view=rev&rev=499019
Log:
CXF-385 Fix related to handling of fault detail element.
Added:
incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptorTest.java
(with props)
Modified:
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptor.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=499019&r1=499018&r2=499019
==============================================================================
---
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
Tue Jan 23 05:41:49 2007
@@ -18,25 +18,22 @@
*/
package org.apache.cxf.binding.xml.interceptor;
-import java.lang.reflect.Method;
-import java.util.Iterator;
import java.util.ResourceBundle;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
+import org.w3c.dom.Node;
+
import org.apache.cxf.binding.xml.XMLConstants;
import org.apache.cxf.binding.xml.XMLFault;
import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.helpers.NSStack;
import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.Phase;
-import org.apache.cxf.service.model.BindingOperationInfo;
-import org.apache.cxf.service.model.FaultInfo;
-import org.apache.cxf.service.model.MessagePartInfo;
import org.apache.cxf.staxutils.StaxUtils;
public class XMLFaultOutInterceptor extends AbstractOutDatabindingInterceptor {
@@ -67,37 +64,14 @@
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 (t != null && bop != null) {
- if (bop.isUnwrapped()) {
- bop = bop.getWrappedOperation();
- }
- Iterator<FaultInfo> it =
bop.getOperationInfo().getFaults().iterator();
- MessagePartInfo part = null;
- while (it.hasNext()) {
- FaultInfo fi = it.next();
- for (MessagePartInfo mpi : fi.getMessageParts()) {
- Class cls = mpi.getTypeClass();
- 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.
- }
- }
- }
- if (part != null) {
- StaxUtils.writeStartElement(writer, prefix,
XMLFault.XML_FAULT_DETAIL,
- XMLConstants.NS_XML_FORMAT);
- DataWriter<Message> dataWriter =
getMessageDataWriter(message);
- dataWriter.write(getFaultInfo(t), part, message);
- writer.writeEndElement();
- }
+ // call StaxUtils to write Fault detail.
+
+ if (xmlFault.getDetail() != null) {
+ StaxUtils.writeStartElement(writer, prefix,
XMLFault.XML_FAULT_DETAIL,
+ XMLConstants.NS_XML_FORMAT);
+ StaxUtils.writeNode(DOMUtils.getChild(xmlFault.getDetail(),
Node.ELEMENT_NODE),
+ writer, false);
+ writer.writeEndElement();
}
// fault root
writer.writeEndElement();
@@ -105,17 +79,5 @@
} catch (XMLStreamException xe) {
throw new Fault(new
org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), xe);
}
- }
-
- private static Object getFaultInfo(Throwable fault) {
- try {
- Method faultInfoMethod =
fault.getClass().getMethod("getFaultInfo");
- if (faultInfoMethod != null) {
- return faultInfoMethod.invoke(fault);
- }
- } catch (Exception ex) {
- throw new RuntimeException("Could not get faultInfo out of
Exception", ex);
- }
- return null;
}
}
Added:
incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptorTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptorTest.java?view=auto&rev=499019
==============================================================================
---
incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptorTest.java
(added)
+++
incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptorTest.java
Tue Jan 23 05:41:49 2007
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.binding.xml.interceptor;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.w3c.dom.Element;
+
+import org.apache.cxf.binding.xml.XMLConstants;
+import org.apache.cxf.binding.xml.XMLFault;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.staxutils.DepthXMLStreamReader;
+import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.hello_world_doc_lit.PingMeFault;
+import org.apache.hello_world_doc_lit.types.FaultDetail;
+
+public class XMLFaultOutInterceptorTest extends TestBase {
+
+ XMLFaultOutInterceptor out = new XMLFaultOutInterceptor();
+
+ public void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testFault() throws Exception {
+ FaultDetail detail = new FaultDetail();
+ detail.setMajor((short)2);
+ detail.setMinor((short)1);
+ PingMeFault fault = new PingMeFault("TEST_FAULT", detail);
+
+ XMLFault xmlFault = XMLFault.createFault(new Fault(fault));
+ Element el = xmlFault.getOrCreateDetail();
+ JAXBContext ctx = JAXBContext.newInstance(FaultDetail.class);
+ Marshaller m = ctx.createMarshaller();
+ m.marshal(detail, el);
+
+ OutputStream outputStream = new ByteArrayOutputStream();
+ xmlMessage.setContent(OutputStream.class, outputStream);
+ XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(outputStream);
+ xmlMessage.setContent(XMLStreamWriter.class, writer);
+ xmlMessage.setContent(Exception.class, xmlFault);
+
+ out.handleMessage(xmlMessage);
+ outputStream.flush();
+
+ XMLStreamReader reader = getXMLReader();
+ DepthXMLStreamReader dxr = new DepthXMLStreamReader(reader);
+
+ dxr.nextTag();
+ StaxUtils.toNextElement(dxr);
+ assertEquals(XMLConstants.NS_XML_FORMAT, dxr.getNamespaceURI());
+ assertEquals(XMLFault.XML_FAULT_ROOT, dxr.getLocalName());
+
+ dxr.nextTag();
+ StaxUtils.toNextElement(dxr);
+ assertEquals(XMLFault.XML_FAULT_STRING, dxr.getLocalName());
+ assertEquals(fault.toString(), dxr.getElementText());
+
+ dxr.nextTag();
+ StaxUtils.toNextElement(dxr);
+ assertEquals(XMLFault.XML_FAULT_DETAIL, dxr.getLocalName());
+
+ dxr.nextTag();
+ StaxUtils.toNextElement(dxr);
+ assertEquals("faultDetail", dxr.getLocalName());
+ }
+
+ private XMLStreamReader getXMLReader() throws Exception {
+ ByteArrayOutputStream o = (ByteArrayOutputStream)
xmlMessage.getContent(OutputStream.class);
+ InputStream in = new ByteArrayInputStream(o.toByteArray());
+ return StaxUtils.createXMLStreamReader(in);
+ }
+}
Propchange:
incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/rt/bindings/xml/src/test/java/org/apache/cxf/binding/xml/interceptor/XMLFaultOutInterceptorTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date