axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard Gruet (JIRA)" <j...@apache.org>
Subject [jira] Commented: (AXIS2-917) User guide should give explanation and examples of fault handling
Date Fri, 11 Aug 2006 13:31:14 GMT
    [ http://issues.apache.org/jira/browse/AXIS2-917?page=comments#action_12427519 ] 
            
Richard Gruet commented on AXIS2-917:
-------------------------------------

Latest news: I investigated further, and it appears that the org.apache.axiom.om.OMException:
java.lang.IllegalStateException I got was my fault (if I dare to say ;), I was passing an
incoorect param to the WS operation whose function is to raise my custom fault.

I am now able to raise a custom exception xxxFaultException in my implementation and to catch
it in my client (gotcha: 2 classes xxxFaultException exist, one in the skeleton, and the other
in the stubs - the client must use the latter !). However,  I find that  the detail of  my
fault are lost in the exception instance.

Here is my code (see the attached WS-tests_sampleService.wsdl for the details): I'm calling
an operation throwMiFault whose purpose is to raise a custom fault  'MiFault'  (see the attached
WS-tests_sampleService.wsdl).

* Here the structure of my custom fault (Mifault):

  <complexType name="MiFault">
        <sequence>
        <element name="error" minOccurs="0" maxOccurs="unbounded">
           <complexType>
             <sequence>
                <element name="errCode" type="tns:Ident" minOccurs="0" />
                <element name="errMsg" type="string" />
                <element name="parameter" type="tns:Ident" minOccurs="0" />
              </sequence>
           </complexType>
        </element>
      </sequence>
  </complexType>

(tns:ident is just a xsd:string)

 *  Implementation of  operation throwMiFault:

public EmptyResponseDocument throwMiFault(ThrowMiFaultDocument param)
	throws ThrowMiFaultFaultException {
		
	MiFault miFault = MiFault.Factory.newInstance();

	Error err1 = Error.Factory.newInstance();
	err1.setErrCode("CODE1");
	err1.setErrMsg("Error #1 message text");
	err1.setParameter("param#1");

	Error err2 = Error.Factory.newInstance();
	err2.setErrCode("CODE2");
	err2.setErrMsg("Error #2 message text");
	// 3rd parameter omitted since optional

	miFault .setErrorArray(new Error[] { err1, err2 });

	MiFaultDocument faultDoc = MiFaultDocument.Factory.newInstance();
	faultDoc.setMiFault(miFault );

	ThrowMiFaultFaultException e = new ThrowMiFaultFaultException();
	e.setFaultMessage(faultDoc);
	throw e;
}

* The CLIENT test case :

    public void test_op_throwMiFault() throws Exception {

		// Must create a document even if there are no IN params:
		ThrowMiFault in = ThrowMiFault.Factory.newInstance();
		ThrowMiFaultDocument req = ThrowMiFaultDocument.Factory.newInstance();
		req.setThrowMiFault(in);
		
		try {
			port.throwMiFault(req);
			fail("Expected a Fault");
		} catch (AxisFault e) {
			fail("AxisFault received");
		} catch (ThrowMiFaultFaultException e) {

			
MiFaultDocument doc = e.getFaultMessage();
			MiFault miFault = doc.getMiFault();

			System.out.println("\n(testError) OK, MiFault received");
                        assertEquals(miFault.sizeOfErrorArray(), 2); ///////// FAILS ! =>
0 instead of 2
			System.out.println("miFault XML:\n" + miFault.toString());

			System.out.println("Fault detail:");
			for (MiFault.Error error : miFault.getErrorArray()) {
				System.out.println();
				System.out.println("     code: " + error.getErrCode());
				System.out.println("      msg: " + error.getErrMsg());
				System.out.println("parameter: " + error.getParameter());
			}
		} catch (Exception e) {
			fail("Expected a ThrowMiFaultFaultException, received: " + e);
		}



> User guide should give explanation and examples of fault handling
> -----------------------------------------------------------------
>
>                 Key: AXIS2-917
>                 URL: http://issues.apache.org/jira/browse/AXIS2-917
>             Project: Apache Axis 2.0 (Axis2)
>          Issue Type: Wish
>          Components: samples, build,site  & docs
>    Affects Versions: 1.0
>            Reporter: Derek Foster
>         Assigned To: Eran Chinthaka
>            Priority: Critical
>         Attachments: sampleService-wsdl.rar
>
>
> The Axis2 user guide provides no examples of:
>   1) The WSDL to declare that a fault may be thrown from an operation (suitable for passing
into WSDL2Java)
>   2) The server-side code for a fault exception, as generated by WSDL2Java and modified
as a user might be expected to modify it.
>   3) The server-side code to throw the fault exception, including a tested example of
passing on a custom error message to be transmitted as part of a SOAP fault (in the faultDetail)
and received by the client.
>   4) The client-side code for receiving and handling a fault.
> Furthermore, what discussion of faults that there is seems fairly contradictory. For
instance, there are various suggestions that throwing an AxisFault exception from a service
is the way to issue a fault. However, WSDL2Java does not generate service methods that are
declared to throw AxisFault, and there seems to be no way to declare such a fault in WSDL.
(at least, none that I can find). Fault generation from a service that was not generated by
WSDL2Java should be treated as a separate section, since it is handled in a totally different
manner by server code. I think that both kinds of fault handling need to be documented clearly
in the user guide.
> I have been trying for weeks to figure out how this is supposed to work, and still haven't
gotten it to work quite right (my custom error message included in the thrown fault exception
is getting lost somewhere before the SOAP fault is transmitted). This is a basic feature that
should be documented clearly.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org


Mime
View raw message