You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2003/07/10 00:00:50 UTC

cvs commit: xml-axis/java/src/org/apache/axis/handlers/soap SOAPService.java

dims        2003/07/09 15:00:49

  Modified:    java/test/wsdl/jaxrpchandler build.xml ClientHandler.java
                        JAXRPCHandlerTestCase.java ServerHandler.java
                        StockQuoteImpl.java
               java/src/org/apache/axis/handlers/soap SOAPService.java
  Log:
  Fix and testcase for Bug 15181 - javax.xml.rpc.handler.Handler#handleFault method is not called
  from Pat Cogan (apache@dreamtimesolutions.com)
  
  Revision  Changes    Path
  1.5       +1 -1      xml-axis/java/test/wsdl/jaxrpchandler/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/jaxrpchandler/build.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- build.xml	10 Sep 2002 16:06:54 -0000	1.4
  +++ build.xml	9 Jul 2003 22:00:48 -0000	1.5
  @@ -53,7 +53,7 @@
   <target name="copy" depends="setenv"/>
   
   <target name="compile" depends="copy">
  -  <echo message="Compiling test.${componentName}"/>
  +  <echo message="Compiling ${componentName}"/>
       <!-- This is (OK, "will be") a comprehensive test of XML schema types -->
       <wsdl2java url="${axis.home}/test/wsdl/jaxrpchandler/jaxrpchandler.wsdl"
                  output="${build.dir}/work"
  
  
  
  1.3       +20 -1     xml-axis/java/test/wsdl/jaxrpchandler/ClientHandler.java
  
  Index: ClientHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/jaxrpchandler/ClientHandler.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ClientHandler.java	11 Dec 2002 22:40:21 -0000	1.2
  +++ ClientHandler.java	9 Jul 2003 22:00:48 -0000	1.3
  @@ -8,6 +8,7 @@
   import javax.xml.soap.Name;
   import javax.xml.soap.SOAPEnvelope;
   import javax.xml.soap.SOAPHeader;
  +import javax.xml.soap.SOAPBody;
   import javax.xml.soap.SOAPHeaderElement;
   import javax.xml.soap.SOAPMessage;
   import javax.xml.soap.SOAPPart;
  @@ -44,6 +45,7 @@
   			SOAPHeaderElement she = sh.addHeaderElement(name);
   			she.setActor(_actorURI);
   			she.addAttribute(se.createName("counter", "", ""), "1");
  +			she.addAttribute(se.createName("faultCounter", "", ""), "1");
   		} catch (Exception e) {
   			e.printStackTrace();
   		}
  @@ -58,11 +60,14 @@
   		System.out.println("Hey - in Handle response");
   		try {
   			String counter = null;
  +			String faultCounter = null;
  +
   			SOAPMessageContext smc = (SOAPMessageContext) context;
   			SOAPMessage msg = smc.getMessage();
   			SOAPPart sp = msg.getSOAPPart();
   			SOAPEnvelope se = sp.getEnvelope();
   			SOAPHeader sh = se.getHeader();
  +			SOAPBody sb = se.getBody();
   			Name name =
   			se.createName(
   						 "HeaderTest",
  @@ -75,10 +80,23 @@
   				she.getAttributeValue(se.createName("counter", "", ""));
   				System.out.println(
   								  "The counter in the element sent back is " + counter);
  +
  +				faultCounter =
  +				she.getAttributeValue(se.createName("faultCounter", "", ""));
  +				System.out.println(
  +								  "The faultCounter in the element sent back is " + faultCounter);
  +
   			}
   
  -			if (counter.equals("3"))
  +			if ((counter != null) && (counter.equals("3")) && (!sb.hasFault())) {
   				JAXRPCHandlerTestCase.completeRoundtrip();
  +			}
  +
  +			if ((faultCounter != null) && (faultCounter.equals("3")) && (sb.hasFault())) {
  +				JAXRPCHandlerTestCase.setFaultRoundtrip(Integer.parseInt(faultCounter));
  +			}
  +
  +
   		} catch (Exception e) {
   			e.printStackTrace();
   		}
  @@ -113,3 +131,4 @@
   	}
   
   }
  +
  
  
  
  1.3       +62 -1     xml-axis/java/test/wsdl/jaxrpchandler/JAXRPCHandlerTestCase.java
  
  Index: JAXRPCHandlerTestCase.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/jaxrpchandler/JAXRPCHandlerTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JAXRPCHandlerTestCase.java	11 Dec 2002 22:40:21 -0000	1.2
  +++ JAXRPCHandlerTestCase.java	9 Jul 2003 22:00:48 -0000	1.3
  @@ -16,10 +16,17 @@
   public class JAXRPCHandlerTestCase extends TestCase {
   
   	private static boolean _roundtrip = false;
  +	private static int _faultRoundtrip = 0;
  +
   	public static void completeRoundtrip() {
   		_roundtrip = true;
   	}
   
  +	public static void setFaultRoundtrip(int faultCount) {
  +		_faultRoundtrip = faultCount;
  +	}
  +
  +
   	/**
   	 * Default constructor for use as service
   	 */
  @@ -36,6 +43,11 @@
   	    goStockQuote(args);
   	}
   
  +	public void testHandleFail() throws Exception {
  +	    String[] args = {};
  +	    goFail(args);
  +	}
  +
   	public void goStockQuote(String[] args) throws Exception {
   		Options opts = new Options( args );
   		args = opts.getRemainingArgs();
  @@ -59,12 +71,40 @@
   
   	}
   
  +	public void goFail(String[] args) throws Exception {
  +		Options opts = new Options( args );
  +		args = opts.getRemainingArgs();
  +
  +		URL url = new URL(opts.getURL());
  +		String user = opts.getUser();
  +		String passwd = opts.getPassword();
  +		System.out.println("Fail URL is " + url);
  +
  +		_faultRoundtrip = 0;
  +		doTestDeploy();
  +		try {
  +			float val = getQuoteFail(url, true);
  +		} catch (Exception e) {
  +			// catch and ignore the exception
  +		}
  +
  +		assertTrue("Expected setting for config-based handlers should be 3"
  +			  + " (1 Request Client Handler increment, passed in header to Server Handler "
  +			  + " 1 Fault Server Handler increment, passed back in header to Response Client Handler "
  +			  + " 1 Response Client Handler increment)",
  +			  _faultRoundtrip == 3);
  +
  +		doTestClientUndeploy();
  +		doTestServerUndeploy();
  +
  +	}
  +
   	public float getQuote (URL url, boolean runJAXRPCHandler) throws Exception {
   		StockQuoteService  service = new StockQuoteServiceLocator();
   		if (runJAXRPCHandler) {
   			HandlerRegistry hr = service.getHandlerRegistry();
   			java.util.List lhi = new java.util.Vector();
  -			test.wsdl.jaxrpchandler.ClientHandler mh = new test.wsdl.jaxrpchandler.ClientHandler(); 
  +			test.wsdl.jaxrpchandler.ClientHandler mh = new test.wsdl.jaxrpchandler.ClientHandler();
   			Class myhandler = mh.getClass();
   			HandlerInfo hi = new HandlerInfo(myhandler,null,null);
   			lhi.add(hi);
  @@ -79,9 +119,30 @@
   		return res;
   	}
   
  +	public float getQuoteFail (URL url, boolean runJAXRPCHandler) throws Exception {
  +		StockQuoteService  service = new StockQuoteServiceLocator();
  +		if (runJAXRPCHandler) {
  +			HandlerRegistry hr = service.getHandlerRegistry();
  +			java.util.List lhi = new java.util.Vector();
  +			test.wsdl.jaxrpchandler.ClientHandler mh = new test.wsdl.jaxrpchandler.ClientHandler();
  +			Class myhandler = mh.getClass();
  +			HandlerInfo hi = new HandlerInfo(myhandler,null,null);
  +			lhi.add(hi);
  +			hr.setHandlerChain(new QName("","jaxrpchandler"),lhi);
  +		}
  +
  +		float res;
  +
  +		StockQuote sq = service.getjaxrpchandler(url);
  +		res = sq.getQuote("fail");
  +
  +		return res;
  +	}
  +
   	public static void main(String[] args) throws Exception {
   		JAXRPCHandlerTestCase test = new JAXRPCHandlerTestCase("test");
   		test.goStockQuote(args);
  +		test.goFail(args);
   	}
   
   	public void doTestClientUndeploy() throws Exception {
  
  
  
  1.4       +23 -1     xml-axis/java/test/wsdl/jaxrpchandler/ServerHandler.java
  
  Index: ServerHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/jaxrpchandler/ServerHandler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ServerHandler.java	11 Mar 2003 13:27:49 -0000	1.3
  +++ ServerHandler.java	9 Jul 2003 22:00:48 -0000	1.4
  @@ -18,7 +18,10 @@
   public class ServerHandler implements Handler {
   
   	private int _counter = 0;
  +	private int _faultCounter = 0;
  +
   	public final static String _actorURI = "myActorURI";
  +
   	/**
   	 * Constructor for ClientHandler.
   	 */
  @@ -44,6 +47,9 @@
   				SOAPHeaderElement she = (SOAPHeaderElement) iter.next();
   				String counter = she.getAttributeValue(se.createName("counter","",""));
   				_counter = Integer.parseInt(counter) + 1;
  +
  +				String faultCounter = she.getAttributeValue(se.createName("faultCounter","",""));
  +				_faultCounter = Integer.parseInt(faultCounter) + 1;			// Increment it to 2
   			}
   		} catch (Exception e) {
   			e.printStackTrace();
  @@ -79,7 +85,23 @@
   	 * @see javax.xml.rpc.handler.Handler#handleFault(MessageContext)
   	 */
   	public boolean handleFault(MessageContext context) {
  -		return false;
  +		try {
  +			SOAPMessageContext smc = (SOAPMessageContext) context;
  +			SOAPMessage msg = smc.getMessage();
  +			SOAPPart sp = msg.getSOAPPart();
  +			SOAPEnvelope se = sp.getEnvelope();
  +			SOAPHeader sh = se.getHeader();
  +			Name name = se.createName("HeaderTest", "AXIS",
  +									  "http://xml.apache.org/axis");
  +			SOAPHeaderElement she = sh.addHeaderElement(name);
  +
  +			she.addAttribute(se.createName("faultCounter","",""), new Integer(_faultCounter +1).toString());
  +			she.setActor(_actorURI);
  +		} catch (Exception e) {
  +			e.printStackTrace();
  +		}
  +
  +		return true;
   	}
   
   	/**
  
  
  
  1.3       +8 -4      xml-axis/java/test/wsdl/jaxrpchandler/StockQuoteImpl.java
  
  Index: StockQuoteImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/wsdl/jaxrpchandler/StockQuoteImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StockQuoteImpl.java	22 Apr 2003 19:37:09 -0000	1.2
  +++ StockQuoteImpl.java	9 Jul 2003 22:00:48 -0000	1.3
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights 
  + * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -18,7 +18,7 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:  
  + *    if any, must include the following acknowledgment:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgment may appear in the software itself,
  @@ -26,7 +26,7 @@
    *
    * 4. The names "AXIS" and "Apache Software Foundation" must
    *    not be used to endorse or promote products derived from this
  - *    software without prior written permission. For written 
  + *    software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache",
  @@ -62,6 +62,10 @@
   public class StockQuoteImpl {
   
     public float getQuote (String symbol) throws Exception {
  +
  +	if ( symbol.equals("fail") ) {
  +		throw new NullPointerException();
  +	}
   
       if ( symbol.equals("XXX") ) return( (float) 55.25 );
       else return( 0 );
  
  
  
  1.99      +13 -5     xml-axis/java/src/org/apache/axis/handlers/soap/SOAPService.java
  
  Index: SOAPService.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/soap/SOAPService.java,v
  retrieving revision 1.98
  retrieving revision 1.99
  diff -u -r1.98 -r1.99
  --- SOAPService.java	27 Jun 2003 18:35:05 -0000	1.98
  +++ SOAPService.java	9 Jul 2003 22:00:49 -0000	1.99
  @@ -58,6 +58,7 @@
   import org.apache.axis.AxisFault;
   import org.apache.axis.Constants;
   import org.apache.axis.Handler;
  +import org.apache.axis.Message;
   import org.apache.axis.MessageContext;
   import org.apache.axis.SimpleTargetedChain;
   import org.apache.axis.attachments.Attachments;
  @@ -70,6 +71,7 @@
   import org.apache.axis.handlers.HandlerChainImpl;
   import org.apache.axis.handlers.HandlerInfoChainFactory;
   import org.apache.axis.message.SOAPEnvelope;
  +import org.apache.axis.message.SOAPFault;
   import org.apache.axis.message.SOAPHeaderElement;
   import org.apache.axis.providers.BasicProvider;
   import org.apache.axis.soap.SOAPConstants;
  @@ -80,6 +82,7 @@
   import org.w3c.dom.Document;
   
   import javax.xml.namespace.QName;
  +import javax.xml.rpc.soap.SOAPFaultException;
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.IOException;
  @@ -89,10 +92,6 @@
   import java.util.Hashtable;
   import java.util.Vector;
   
  -import javax.xml.rpc.soap.SOAPFaultException;
  -import org.apache.axis.message.SOAPFault;
  -import org.apache.axis.Message;
  -
   /** A <code>SOAPService</code> is a Handler which encapsulates a SOAP
    * invocation.  It has an request chain, an response chain, and a pivot-point,
    * and handles the SOAP semantics when invoke()d.
  @@ -482,7 +481,16 @@
               }
   
               if (result) {
  -                super.invoke(msgContext);
  +                try {
  +                    super.invoke(msgContext);
  +                } catch (AxisFault e) {
  +                    msgContext.setPastPivot(true);
  +                    if (handlerImpl != null) {
  +                        handlerImpl.handleFault(msgContext);
  +                        handlerImpl.destroy();
  +                    }
  +                    throw e;
  +                }
               } else {
                   msgContext.setPastPivot(true);
               }