You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@ws.apache.org by "Eric M. Dashofy" <ed...@ics.uci.edu> on 2000/08/21 22:26:23 UTC

[PATCH] Ability to serialize parameters (specifically, exceptions) in a Fault

--- Fault.java.orig	Fri Aug 18 13:25:32 2000
+++ Fault.java	Mon Aug 21 11:28:56 2000
@@ -60,6 +60,7 @@
 import java.io.*;
 import java.util.*;
 import org.w3c.dom.*;
+import org.apache.soap.rpc.Parameter;
 import org.apache.soap.util.*;
 import org.apache.soap.util.xml.*;
 import org.apache.soap.encoding.*;
@@ -70,6 +71,7 @@
  *
  * @author Matthew J. Duftler (duftler@us.ibm.com)
  * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
+ * @author Eric M. Dashofy (edashofy@ics.uci.edu)
  */
 public class Fault
 {
@@ -199,11 +201,35 @@
       // Serialize the detail entries within the <detail> element.
       for (Enumeration e = detailEntries.elements(); e.hasMoreElements();)
       {
-        Element detailEntryEl = (Element)e.nextElement();
-
-        Utils.marshallNode(detailEntryEl, sink);
-
-        sink.write(StringUtils.lineSeparator);
+        Object detailEntryObject = e.nextElement();
+
+				if(detailEntryObject instanceof Element){
+					Element detailEntryEl = (Element)detailEntryObject;
+
+	        Utils.marshallNode(detailEntryEl, sink);
+
+	        sink.write(StringUtils.lineSeparator);
+				}
+				else if(detailEntryObject instanceof Parameter)
+				{
+					try{
+						Parameter detailEntryParameter = (Parameter)detailEntryObject;
+	          Serializer ser = xjmr.querySerializer(Parameter.class,
+	                                                inScopeEncStyle);
+
+	          ser.marshall(inScopeEncStyle, Parameter.class,
detailEntryParameter,
+	                       Constants.ELEM_FAULT_DETAIL_TARGET, sink, nsStack,
xjmr);
+
+	          sink.write(StringUtils.lineSeparator);
+					}
+					catch(IllegalArgumentException iae){
+						//The XmlJavaMappingRegistry may not have a mapping for the
particular
+						//exception type we've received.  That's OK...if it doesn't, we
+						//will just not serialize the exception--the client will have to
+						//get by with just the fault code and the fault string.
+						iae.printStackTrace();
+					}
+				}
       }

       sink.write("</" + Constants.ELEM_DETAIL + '>' +
@@ -342,7 +368,24 @@
                      el != null;
                      el = DOMUtils.getNextSiblingElement(el))
         {
-          detailEntries.addElement(el);
+					if(el.getTagName().equals(Constants.ELEM_FAULT_DETAIL_TARGET)){
+						//The target exception is marshalled up in this element.
+
+						//We have to choose a default encoding style
+						//if one is not provided
+						String encStyle = inScopeEncStyle != null ?
+							inScopeEncStyle : Constants.NS_URI_SOAP_ENC;
+						//Get a parameter deserializer
+						Deserializer deser = xjmr.queryDeserializer(
+							org.apache.soap.rpc.RPCConstants.Q_ELEM_PARAMETER, encStyle);
+						Bean paramBean = deser.unmarshall(encStyle,
+							org.apache.soap.rpc.RPCConstants.Q_ELEM_PARAMETER, el, xjmr);
+						Parameter exceptionParam = (Parameter)paramBean.value;
+						detailEntries.addElement(exceptionParam);
+					}
+					else{
+	          detailEntries.addElement(el);
+					}
         }

         fault.setDetailEntries(detailEntries);
@@ -406,4 +449,5 @@

     return sw.toString();
   }
-}
\ No newline at end of file
+}
+
--- Constants.java.orig	Fri Aug 18 13:25:32 2000
+++ Constants.java	Mon Aug 21 10:10:52 2000
@@ -115,6 +115,7 @@
   public static String ELEM_FAULT_STRING = "faultstring";
   public static String ELEM_FAULT_ACTOR = "faultactor";
   public static String ELEM_DETAIL = "detail";
+	public static String ELEM_FAULT_DETAIL_TARGET = "target";

   // Qualified element names.
   public static QName  Q_ELEM_ENVELOPE =
--- RPCRouterServlet.java.orig	Fri Aug 18 13:25:32 2000
+++ RPCRouterServlet.java	Mon Aug 21 11:27:32 2000
@@ -75,6 +75,7 @@
  * @author Sanjiva Weerawarana <sa...@watson.ibm.com>
  * @author Mat
  * @author Steven McDowall <sj...@aptest.com>
+ * @author Eric M. Dashofy (edashofy@ics.uci.edu)
  */

 public class RPCRouterServlet extends HttpServlet {
@@ -307,6 +308,18 @@
       String faultCode = e.getFaultCode ();
       String faultString = e.getMessage ();

+			Throwable targetException = e.getTargetException();
+			if(targetException != null){
+				Parameter param = new Parameter(Constants.ELEM_FAULT_DETAIL_TARGET,
+					targetException.getClass(), targetException,
+					null);
+				Vector faultDetailEntries = fault.getDetailEntries();
+				if(faultDetailEntries == null){
+					faultDetailEntries = new Vector();
+				}
+				faultDetailEntries.addElement(param);
+				fault.setDetailEntries(faultDetailEntries);
+			}
       if (faultCode == null ||
 	  faultCode.startsWith (Constants.FAULT_CODE_SERVER)) {
 	res.setStatus (ServerConstants.SC_INTERNAL_SERVER_ERROR);
@@ -319,7 +332,12 @@
       fault.setFaultString (faultString);
       fault.setFaultActorURI (req.getRequestURI ());

-      resp = new Response (null, null, fault, null, null, null);
+			String respEncStyle = call.getEncodingStyleURI();
+			if(respEncStyle == null){
+				respEncStyle = Constants.NS_URI_SOAP_ENC;
+			}
+
+      resp = new Response (null, null, fault, null, null, respEncStyle);

     } catch (Throwable t) {