dlr 2005/04/28 15:38:23
Modified: src/java/org/apache/xmlrpc XmlRpcClientResponseProcessor.java XmlRpcClientWorker.java Log: * src/java/org/apache/xmlrpc/XmlRpcClientWorker.java Corrected @since tag in header JavaDoc. (PROCESSING_ERROR): New constant which is Used as an internal marker value in the execute() method. (execute): Rewrote exception handling changes introduced in CVS rev 1.3 to avoid masking root cause exceptions when completing a request. (canReUse): Improved JavaDoc and suggested better method name. * src/java/org/apache/xmlrpc/XmlRpcClientResponseProcessor.java Corrected @since tag in header JavaDoc. (decodeResponse, decodeException): Improved JavaDoc. Revision Changes Path 1.3 +12 -12 ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpcClientResponseProcessor.java Index: XmlRpcClientResponseProcessor.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpcClientResponseProcessor.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -u -r1.2 -r1.3 --- XmlRpcClientResponseProcessor.java 22 Apr 2005 10:25:57 -0000 1.2 +++ XmlRpcClientResponseProcessor.java 28 Apr 2005 22:38:23 -0000 1.3 @@ -31,7 +31,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Hannes Wallnoefer</a> * @author <a href="mailto:[EMAIL PROTECTED]">Andrew Evers</a> * @version $Id$ - * @since 1.2 + * @since 2.0 */ public class XmlRpcClientResponseProcessor extends XmlRpc { @@ -42,16 +42,15 @@ protected boolean fault; /** - * Decode an XML-RPC response from the specified InputStream. This - * method will parse the input and return an Object. The result - * will be an XmlRpcException if the server returned a fault, or - * an Object if the server returned a result. + * Decode an XML-RPC response from the specified InputStream. * - * @param is the stream to read from. - * @return Object an XmlRpcException if an error occured, or the response. + * @param is The stream from which to read the response. + * @return The response, which will be a XmlRpcException if an + * error occured. + * @exception XmlRpcClientException */ public Object decodeResponse(InputStream is) - throws XmlRpcClientException + throws XmlRpcClientException { result = null; fault = false; @@ -80,12 +79,13 @@ * it throws an exception then an exception occured locally when decoding * the response * - * @param result the result from the remote XML-RPC server. - * @throws XmlRpcClientException if the result could not be processed. + * @param result The response from the remote XML-RPC server. + * @return A XmlRpcException describing the error which occurred. + * @exception XmlRpcClientException if the result could not be processed. * @return XmlRpcException the processed response from the server. */ protected XmlRpcException decodeException(Object result) - throws XmlRpcClientException + throws XmlRpcClientException { Hashtable exceptionData; 1.5 +55 -34 ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpcClientWorker.java Index: XmlRpcClientWorker.java =================================================================== RCS file: /home/cvs/ws-xmlrpc/src/java/org/apache/xmlrpc/XmlRpcClientWorker.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -u -r1.4 -r1.5 --- XmlRpcClientWorker.java 22 Apr 2005 10:25:57 -0000 1.4 +++ XmlRpcClientWorker.java 28 Apr 2005 22:38:23 -0000 1.5 @@ -25,13 +25,19 @@ * a request serially in a single thread. * * @author <a href="mailto:[EMAIL PROTECTED]">Andrew Evers</a> - * @since 1.2 + * @since 2.0 */ public class XmlRpcClientWorker { protected XmlRpcClientRequestProcessor requestProcessor; protected XmlRpcClientResponseProcessor responseProcessor; + /** + * Used as an internal marker value in [EMAIL PROTECTED] + * #execute(XmlRpcClientRequest, XmlRpcTransport)}. + */ + private static final Object PROCESSING_ERROR = new Object(); + public XmlRpcClientWorker() { this(new XmlRpcClientRequestProcessor(), @@ -46,33 +52,25 @@ this.responseProcessor = responseProcessor; } - public Object execute(XmlRpcClientRequest xmlRpcRequest, XmlRpcTransport transport) - throws XmlRpcException, XmlRpcClientException, IOException + public Object execute(XmlRpcClientRequest xmlRpcRequest, + XmlRpcTransport transport) + throws XmlRpcException, XmlRpcClientException, IOException { long now = 0; - Object response; + Object response = PROCESSING_ERROR; if (XmlRpc.debug) { now = System.currentTimeMillis(); } - boolean endClientDone = false; try { - byte [] request = requestProcessor.encodeRequestBytes(xmlRpcRequest, responseProcessor.getEncoding()); + byte[] request = requestProcessor.encodeRequestBytes + (xmlRpcRequest, responseProcessor.getEncoding()); InputStream is = transport.sendXmlRpc(request); response = responseProcessor.decodeResponse(is); - if (response instanceof XmlRpcException) - { - throw (XmlRpcException) response; - } - else - { - endClientDone = true; - transport.endClientRequest(); - return response; - } + return response; } catch (IOException ioe) { @@ -82,35 +80,57 @@ { throw xrce; } - catch (XmlRpcException xre) - { - throw xre; - } - catch (Exception x) + catch (RuntimeException x) { if (XmlRpc.debug) { x.printStackTrace(); } - throw new XmlRpcClientException("Unexpected exception in client processing.", x); + throw new XmlRpcClientException + ("Unexpected exception in client processing", x); } finally { if (XmlRpc.debug) { - System.out.println("Spent " + (System.currentTimeMillis() - now) + System.err.println("Spent " + (System.currentTimeMillis() - now) + " millis in request/process/response"); } - if (!endClientDone) - { - try - { - transport.endClientRequest(); - } - catch (Throwable ignore) - { - } - } + + // End the transport's session, handling any problem while + // avoiding hiding of any earlier exception. + try + { + transport.endClientRequest(); + } + catch (Throwable t) + { + // Don't clobber an earlier exception. + boolean haveFault = response instanceof XmlRpcException; + if (haveFault || response == PROCESSING_ERROR) + { + System.err.println("Avoiding obscuring previous error " + + "by supressing error encountered " + + "while ending request: " + t); + if (haveFault) + { + throw (XmlRpcException) response; + } + // else we've already thrown an exception + } + else + { + if (t instanceof XmlRpcException) + { + throw (XmlRpcException) t; + } + else + { + throw new XmlRpcClientException + ("Unable to end request", t); + } + } + } } } @@ -119,8 +139,9 @@ * re-used. Must attempt to clean up any state, and return true if it can * be re-used. * - * @return boolean true if this worker has been cleaned up and may be re-used. + * @return Whether this worker has been cleaned up and may be re-used. */ + // ### isReusable() would be a better name for this set of methods protected boolean canReUse() { return responseProcessor.canReUse() && requestProcessor.canReUse();