You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by du...@apache.org on 2001/08/21 23:25:57 UTC

cvs commit: xml-soap/java/src/org/apache/soap/server ExceptionFaultListener.java

duftler     01/08/21 14:25:57

  Modified:    java/src/org/apache/soap Fault.java
               java/src/org/apache/soap/server ExceptionFaultListener.java
  Log:
  Fixed the behavior of ExceptionFaultListener. It was previously not
  looking in the right place for the type of the detail entry to be
  unmarshalled. It was also not printing the encodingStyle attribute.
  Please see Bug #2345
  (http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2345) for more details.
  Submitted by: Richard Boehme (boehme@acm.jhu.edu)
  Reviewed by: Matthew J. Duftler
  
  Revision  Changes    Path
  1.9       +84 -47    xml-soap/java/src/org/apache/soap/Fault.java
  
  Index: Fault.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/Fault.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Fault.java	2001/05/22 21:59:16	1.8
  +++ Fault.java	2001/08/21 21:25:57	1.9
  @@ -64,6 +64,7 @@
   import org.apache.soap.util.xml.*;
   import org.apache.soap.encoding.*;
   import org.apache.soap.rpc.Parameter;
  +import org.apache.soap.rpc.RPCConstants;
   import org.apache.soap.rpc.SOAPContext;
   
   /**
  @@ -86,9 +87,10 @@
   
     public Fault() {}
   
  -  public Fault(SOAPException _soapException) {
  -	faultCode = _soapException.getFaultCode();
  -	faultString = _soapException.getMessage();
  +  public Fault(SOAPException _soapException)
  +  {
  +    faultCode = _soapException.getFaultCode();
  +    faultString = _soapException.getMessage();
     }
   
     public void setAttribute(QName attrQName, String value)
  @@ -165,6 +167,7 @@
                          XMLJavaMappingRegistry xjmr, SOAPContext ctx)
       throws IllegalArgumentException, IOException
     {
  +
       attrHandler.populateNSStack(nsStack);
   
       String faultCode      = getFaultCode();
  @@ -210,24 +213,49 @@
         // Serialize the detail entries within the <detail> element.
         for (Enumeration e = detailEntries.elements(); e.hasMoreElements();)
         {
  -	Object detailEntry = e.nextElement();
  -		
  -	//if the detail entry is an Element, just write it
  -	if (detailEntry instanceof Element) {
  -	        Element detailEntryEl = (Element)detailEntry;
  -        	Utils.marshallNode(detailEntryEl, sink);
  -        	sink.write(StringUtils.lineSeparator);
  -	}
  -	
  -	// if the detail entry is a Parameter, try to find a serializer, if there is an error, write nothing
  -	else if (detailEntry instanceof Parameter) {
  -		try {
  -			Parameter detailEntryParameter = (Parameter)detailEntry;
  -			xjmr.querySerializer(Parameter.class, inScopeEncStyle).marshall(inScopeEncStyle, Parameter.class, detailEntryParameter, Constants.ELEM_FAULT_DETAIL_ENTRY, sink, nsStack, xjmr, ctx);
  -			sink.write(StringUtils.lineSeparator);
  -		}
  -		catch (IllegalArgumentException iae) {}
  -	}
  +        Object detailEntry = e.nextElement();
  +
  +        // If the detail entry is an Element, just write it out.
  +        if (detailEntry instanceof Element)
  +        {
  +          Element detailEntryEl = (Element)detailEntry;
  +
  +          Utils.marshallNode(detailEntryEl, sink);
  +          sink.write(StringUtils.lineSeparator);
  +        }
  +        /*
  +          If the detail entry is a Parameter, try to find a serializer.
  +          If there is an error, write nothing.
  +        */
  +        else if (detailEntry instanceof Parameter)
  +        {
  +          try
  +          {
  +            Parameter detailEntryParameter = (Parameter)detailEntry;
  +            Serializer s = xjmr.querySerializer(Parameter.class, inScopeEncStyle);
  +
  +            if (s != null)
  +            {
  +              s.marshall(null,
  +                         Parameter.class,
  +                         detailEntryParameter,
  +                         Constants.ELEM_FAULT_DETAIL_ENTRY,
  +                         sink,
  +                         nsStack,
  +                         xjmr,
  +                         ctx);
  +              sink.write(StringUtils.lineSeparator);
  +            }
  +            else
  +            {
  +              throw new IllegalArgumentException("Could not find Parameter " +
  +                                                 "serializer.");
  +            }
  +          }
  +          catch (IllegalArgumentException iae)
  +          {
  +          }
  +        }
         }
   
         sink.write("</" + Constants.ELEM_DETAIL + '>' +
  @@ -261,6 +289,7 @@
       Element root  = (Element)src;
       Fault   fault = new Fault();
   
  +
       if (Constants.Q_ELEM_FAULT.matches(root))
       {
         Element faultCodeEl   = null;
  @@ -366,30 +395,28 @@
                        el != null;
                        el = DOMUtils.getNextSiblingElement(el))
           {
  +          // Try to deserialize. If it fails, just add element to list.
  +          try
  +          {
  +            String declEncStyle =
  +              DOMUtils.getAttributeNS(el,
  +                                      Constants.NS_URI_SOAP_ENV,
  +                                      Constants.ATTR_ENCODING_STYLE);
  +            String actualEncStyle = declEncStyle != null
  +                                    ? declEncStyle
  +                                    : inScopeEncStyle;
  +            Bean paramBean = xjmr.unmarshall(declEncStyle,
  +                                             RPCConstants.Q_ELEM_PARAMETER,
  +                                             el,
  +                                             ctx);
  +            Parameter param = (Parameter)paramBean.value;
   
  -	
  -		//try to deserialize, if fails, just add element to list
  -		try {
  -  
  -			//find the declared encoding style
  -			String declEncStyle = el.getAttributeNS(Constants.NS_URI_SOAP_ENV, Constants.ATTR_ENCODING_STYLE);
  -
  -			//determine the enc style to use based on this order: declared in element, inscope, SOAP encoding
  -			String encStyle = declEncStyle != null ? declEncStyle : (inScopeEncStyle != null ? inScopeEncStyle : Constants.NS_URI_SOAP_ENC);
  -
  -			QName qn = new QName(el);
  -
  -			//Get a deserializer 
  -			Deserializer deser = xjmr.queryDeserializer( qn, encStyle); 
  -
  -			Bean detailEntryBean = deser.unmarshall(encStyle, qn, el, xjmr, ctx);
  -
  -			detailEntries.addElement(detailEntryBean.value); 
  -		} 
  -		catch (Exception e) {   
  -			detailEntries.addElement(el); 
  -		}
  -		
  +            detailEntries.addElement(param);
  +          }
  +          catch (Exception e)
  +          {
  +            detailEntries.addElement(el);
  +          }
           }
   
           fault.setDetailEntries(detailEntries);
  @@ -429,9 +456,19 @@
   
         for (int i = 0; i < detailEntries.size(); i++)
         {
  -        pw.println("[(" + i + ")=" +
  -               DOM2Writer.nodeToString((Element)detailEntries.elementAt(i)) +
  -               "]");
  +        Object detailEl = detailEntries.elementAt(i);
  +
  +        if (detailEl instanceof Parameter)
  +        {
  +          Parameter param = (Parameter)detailEl;
  +
  +          pw.println("[(" + i + ")=" + param +"]");
  +        }
  +        else
  +        {
  +          pw.println("[(" + i + ")=" +
  +                     DOM2Writer.nodeToString((Element)detailEl) + "]");
  +        }
         }
       }
   
  
  
  
  1.2       +6 -1      xml-soap/java/src/org/apache/soap/server/ExceptionFaultListener.java
  
  Index: ExceptionFaultListener.java
  ===================================================================
  RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/server/ExceptionFaultListener.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExceptionFaultListener.java	2000/10/17 12:11:13	1.1
  +++ ExceptionFaultListener.java	2001/08/21 21:25:57	1.2
  @@ -78,7 +78,12 @@
   	public void fault(SOAPFaultEvent _faultEvent) {
   		Vector tmp = new Vector();
   		
  -		Parameter param = new Parameter(Constants.ELEM_FAULT_DETAIL_ENTRY, _faultEvent.getSOAPException().getRootException().getClass(), _faultEvent.getSOAPException().getRootException(), null); 
  +		Parameter param =
  +      new Parameter(Constants.ELEM_FAULT_DETAIL_ENTRY,
  +                    _faultEvent.getSOAPException().getRootException().getClass(),
  +                    _faultEvent.getSOAPException().getRootException(),
  +                    Constants.NS_URI_SOAP_ENC);
  +
   		tmp.addElement(param);
   		_faultEvent.getFault().setDetailEntries(tmp);