Return-Path: Mailing-List: contact soap-dev-help@xml.apache.org; run by ezmlm Delivered-To: mailing list soap-dev@xml.apache.org Received: (qmail 15344 invoked from network); 10 Aug 2000 00:20:32 -0000 Received: from unknown (HELO enterprise.ezpricing.com) (63.140.186.62) by locus.apache.org with SMTP; 10 Aug 2000 00:20:32 -0000 Received: by enterprise.ezpricing.com with Internet Mail Service (5.5.2650.21) id ; Wed, 9 Aug 2000 18:24:15 -0400 Message-ID: <8F578FC15B1FD411ACBD000629EE6390047477@enterprise.ezpricing.com> From: "Simpson, Jeff" To: "Soap-Dev@Xml. Apache. Org (E-mail)" Subject: SOAPException changes to allow details Date: Wed, 9 Aug 2000 18:24:14 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C00250.8C87418C" X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C00250.8C87418C Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C00250.8C87418C" ------_=_NextPart_001_01C00250.8C87418C Content-Type: text/plain; charset="iso-8859-1" Here are some changes that I made that allow the Server Class to throw a SOAPException and return back a SOAP Fault detail. It has the happy side effect of allowing you to also send back your own fault codes. I added a vector, details, to SOAPException, and made getters and setter for it. I made some changes to rpcrouter.jsp. Here where the SOAPException is caught I test the targetException to see if it was a SOAPException and if it was I set the fault Details to the exceptions details. I think this clears up a few bugs. If you decide to use this use the details you should be careful that the Vector must be filled only with Elements. Jeffrey V. Simpson Senior Software Engineer http://www.ezpricing.com/ Tel: (202) 833-4949 x116 Cell: (202) 253-1302 Fax: (202) 833-3819 ------_=_NextPart_001_01C00250.8C87418C Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable SOAPException changes to allow details

Here are some changes that I made that allow the = Server Class to throw a SOAPException and return back a SOAP Fault = detail.  It has the happy side effect of allowing you to also send = back your own fault codes. 

I added a vector, details, to SOAPException, and made = getters and setter for it.

I made some changes to rpcrouter.jsp.  Here = where the SOAPException is caught I test the targetException to see if = it was a SOAPException and if it was I set the fault Details to the = exceptions details.  I think this clears up a few bugs.

If you decide to use this use the details you should = be careful that the Vector must be filled only with Elements.


Jeffrey V. Simpson
Senior Software Engineer
http://www.ezpricing.com/
Tel:    (202)  833-4949 x116
Cell:   (202) 253-1302
Fax:    (202) 833-3819

  ------_=_NextPart_001_01C00250.8C87418C-- ------_=_NextPart_000_01C00250.8C87418C Content-Type: application/octet-stream; name="SOAPException.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="SOAPException.java" /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2000 The Apache Software Foundation. All rights=20 * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer.=20 * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: =20 * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software = itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "SOAP" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written=20 * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 2000, International * Business Machines, Inc., http://www.apache.org. For more * information on the Apache Software Foundation, please see * . */ package org.apache.soap; import java.util.Vector; /** * SOAP Exceptions. * * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com) * @author Matthew J. Duftler (duftler@us.ibm.com) * Jeffrey Simpson (jsimpson@ezpricing.com) Changed to add details */ public class SOAPException extends Exception { private String faultCode; private Throwable targetException; private Vector details; public SOAPException (String faultCode, String msg) { super (msg); this.faultCode =3D faultCode; } public SOAPException (String faultCode, String msg, Vector details) { super (msg); this.faultCode =3D faultCode; this.details =3D details; } public SOAPException (String faultCode, String msg, Throwable targetException) { this (faultCode, msg); this.targetException =3D targetException; } public void setFaultCode (String faultCode) { this.faultCode =3D faultCode; } public String getFaultCode () { return faultCode; } public void setDetails(Vector details) { this.details =3D details; } public Vector getDetails() { return details; } public void setTargetException (Throwable targetException) { this.targetException =3D targetException; } public Throwable getTargetException () { return targetException; } public String getMessage () { String superMsg =3D super.getMessage (); String targetMsg =3D (targetException !=3D null) ? targetException.getMessage () : null; String msg =3D ((superMsg =3D=3D null || superMsg.equals ("")) && (targetMsg !=3D null && !targetMsg.equals (""))) ? targetMsg : superMsg; if (msg =3D=3D null || msg.equals ("")) { msg =3D (targetException !=3D null) ? targetException.toString() : this.toString(); } return msg; } public String toString () { return "[SOAPException: faultCode=3D" + faultCode + "; msg=3D" + super.getMessage () + ((targetException !=3D null) ? ("; targetException=3D" + targetException) : "") + "]"; } } ------_=_NextPart_000_01C00250.8C87418C Content-Type: application/octet-stream; name="rpcrouter.jsp" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="rpcrouter.jsp" <%@ page language=3D"java" %> <%@ page import=3D"java.io.*" %> <%@ page import=3D"java.util.*" %> <%@ page import=3D"java.lang.reflect.*" %> <%@ page import=3D"org.w3c.dom.*" %> <%@ page import=3D"org.apache.soap.util.Bean" %> <%@ page import=3D"org.apache.soap.util.MethodUtils" %> <%@ page import=3D"org.apache.soap.util.IOUtils" %> <%@ page import=3D"org.apache.soap.util.StringUtils" %> <%@ page import=3D"org.apache.soap.util.xml.XMLParserLiaison" %> <%@ page import=3D"org.apache.soap.util.xml.XercesParserLiaison" %> <%@ page import=3D"org.apache.soap.*" %> <%@ page import=3D"org.apache.soap.encoding.*" %> <%@ page import=3D"org.apache.soap.rpc.*" %> <%@ page import=3D"org.apache.soap.server.*" %> <% // this should be done like this: // // but I get an internal servlet exception from tomcat for it .. rpcRouter.setServiceManager (serviceManager); Response resp =3D null; String targetID =3D null; // Query the relevant header fields. String requestMethod =3D request.getMethod (); String contentType =3D request.getContentType (); int contentLength =3D request.getContentLength (); Call call =3D null; try { if (requestMethod =3D=3D null || !requestMethod.equals (Constants.HEADER_POST)) { throw new SOAPException (Constants.FAULT_CODE_PROTOCOL, "Can only respond to '" + Constants.HEADER_POST + "' requests."); } else if (contentType =3D=3D null || !contentType.equals (Constants.HEADERVAL_CONTENT_TYPE)) { throw new SOAPException (Constants.FAULT_CODE_PROTOCOL, "Content type must be: '" + Constants.HEADERVAL_CONTENT_TYPE + "'."); } else if (contentLength < 0) { throw new SOAPException (Constants.FAULT_CODE_PROTOCOL, "Content length must be specified."); } else { System.err.println (">>(" + new Date() + ") Processing SOAP request..."); response.setContentType (Constants.HEADERVAL_CONTENT_TYPE); Reader requestReader =3D request.getReader (); char[] payload =3D new char[contentLength]; int offset =3D 0; while (offset < contentLength) { offset +=3D requestReader.read (payload, offset, contentLength - = offset); } // Parse the incoming request stream. org.apache.soap.util.xml.XMLParserLiaison xpl =3D new = XercesParserLiaison (); Document callDoc =3D xpl.read("- SOAP HTTP RPC Call Envelope -", new CharArrayReader (payload)); Element payloadEl =3D null; if (callDoc =3D=3D null) { throw new SOAPException(Constants.FAULT_CODE_PROTOCOL, "DOM parsing error: " + payload); } // get the call out try { payloadEl =3D callDoc.getDocumentElement (); Envelope callEnv =3D Envelope.unmarshall (payloadEl); call =3D rpcRouter.extractCallFromEnvelope (callEnv); targetID =3D call.getTargetObjectURI (); } catch (IllegalArgumentException e) { String msg =3D e.getMessage (); String faultCode =3D (msg !=3D null && = msg.equals(Constants.ERR_MSG_VERSION_MISMATCH)) ? Constants.FAULT_CODE_VERSION_MISMATCH : Constants.FAULT_CODE_CLIENT; throw new SOAPException (faultCode, msg, e); } // call on a valid method name? if (!rpcRouter.validCall (call)) { throw new SOAPException (Constants.FAULT_CODE_SERVER, "Method '" + call.getMethodName () +=20 "' is not supported."); } // lifecycle stuff of target object: what's the class to = instantiate? DeploymentDescriptor dd =3D serviceManager.query (targetID); int scope =3D dd.getScope (); byte providerType =3D dd.getProviderType (); String className; Object targetObject =3D null; if (providerType =3D=3D DeploymentDescriptor.PROVIDER_JAVA) { className =3D dd.getProviderClass (); } else { // for scripts, we need a new BSF manager basically className =3D "com.ibm.bsf.BSFManager"; } // determine the scope and lock object to use to manage the = lifecycle // of the service providing object int[] iScopes =3D {PageContext.PAGE_SCOPE, = PageContext.REQUEST_SCOPE, PageContext.SESSION_SCOPE, PageContext.APPLICATION_SCOPE}; int iScope =3D iScopes[scope]; Object[] scopeLocks =3D {pageContext, request, session, = application}; Object scopeLock =3D scopeLocks[scope]; boolean freshObject =3D false; // find the target object on which the requested method should // be invoked if (targetID.equals (ServerConstants.SERVICE_MANAGER_SERVICE_NAME)) = { targetObject =3D serviceManager; } else { // locate (or create) the target object and invoke the method synchronized (scopeLock) { targetObject =3D pageContext.getAttribute (targetID, iScope); if (targetObject =3D=3D null) { try { Class c =3D Class.forName (className); if (dd.getIsStatic ()) { targetObject =3D c; } else { targetObject =3D c.newInstance (); } freshObject =3D true; } catch (Exception e) { String msg; if (providerType =3D=3D DeploymentDescriptor.PROVIDER_JAVA) { msg =3D "Unable to resolve target object: " + e.getMessage (); } else { msg =3D "Unable to load BSF: script services not available " + "without BSF: " + e.getMessage (); } throw new SOAPException ( RPCConstants.FAULT_CODE_SERVER_BAD_TARGET_OBJECT_URI, msg, e); } } pageContext.setAttribute (targetID, targetObject, iScope); } } =20 // if script provider type and first time to it, then load and // exec the script if (providerType !=3D DeploymentDescriptor.PROVIDER_JAVA && freshObject) { // find the class that provides the BSF services (done // this way via reflection to avoid a static dependency on BSF) Class bc =3D Class.forName ("org.apache.soap.server.InvokeBSF"); // get the script string to exec String script =3D dd.getScriptFilenameOrString (); if (providerType =3D=3D = DeploymentDescriptor.PROVIDER_SCRIPT_FILE) { String fileName =3D getServletContext().getRealPath (script); script =3D IOUtils.getStringFromReader (new FileReader (fileName)); } =20 // exec it Class[] sig =3D {DeploymentDescriptor.class, Object.class, String.class}; Method m =3D MethodUtils.getMethod (bc, "init", sig, true); m.invoke (null, new Object[] {dd, targetObject, script}); } // invoke the method on the target object resp =3D rpcRouter.invoke (call, targetObject); } } catch (SOAPException e) { Fault fault =3D new Fault (); String faultCode =3D e.getFaultCode (); String faultString =3D e.getMessage (); boolean returnSOAPResponse =3D true; Vector entries =3D null; if (e.getTargetException() !=3D null && (e.getTargetException() = instanceof SOAPException)) { SOAPException targetE =3D (SOAPException)e.getTargetException(); faultCode =3D targetE.getFaultCode (); faultString =3D targetE.getMessage (); entries =3D targetE.getDetails(); } if (faultCode =3D=3D null || faultCode.startsWith = (Constants.FAULT_CODE_SERVER)) { response.setStatus (ServerConstants.SC_INTERNAL_SERVER_ERROR); } else if (faultCode.startsWith (Constants.FAULT_CODE_CLIENT)) { response.setStatus (ServerConstants.SC_BAD_REQUEST); } else if (faultCode.startsWith (Constants.FAULT_CODE_PROTOCOL)) { response.setStatus (ServerConstants.SC_BAD_REQUEST); returnSOAPResponse =3D false; } if (returnSOAPResponse) { fault.setFaultCode (faultCode); fault.setFaultString (faultString); fault.setFaultActorURI (request.getRequestURI ()); fault.setDetailEntries(entries); resp =3D new Response (null, null, fault, null, null, null); } else { out.println (faultString); } } catch (Throwable t) { t.printStackTrace (); t.printStackTrace (new PrintWriter (out)); } // Send it out. if (resp !=3D null) { try { // Build an envelope containing the response. Envelope respEnvelope =3D resp.buildEnvelope (); SOAPMappingRegistry smr =3D (call !=3D null ? call.getSOAPMappingRegistry () : new SOAPMappingRegistry()); respEnvelope.marshall (out, smr); out.println (StringUtils.lineSeparator); } catch (IllegalArgumentException e) { throw new SOAPException (Constants.FAULT_CODE_SERVER, = e.getMessage(), e); } catch (IOException e) { throw new SOAPException (Constants.FAULT_CODE_SERVER, = e.getMessage(), e); } } %> ------_=_NextPart_000_01C00250.8C87418C--