[ 
https://issues.apache.org/jira/browse/CXF-1434?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12858373#action_12858373
 ] 

Eric Pederson edited comment on CXF-1434 at 4/19/10 2:24 PM:
-------------------------------------------------------------

      var f = new Fault(new AuthorizationError("Error - Missing apiKey"), 
Fault.FAULT_CODE_CLIENT)
      var element = 
f.getOrCreateDetail().getOwnerDocument().createElementNS("http://ws.nyx.com";, 
"ae:errorCode")
      element.setTextContent("MissingApiKey");
      f.getDetail().appendChild(element)
      throw f

results in this response:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Error - Missing apiKey</faultstring>
         <detail>
            <ae:errorCode 
xmlns:ae="http://ws.nyx.com";>MissingApiKey</ae:errorCode>
            <ns1:AuthorizationError xmlns:ns1="http://ws.nyx.com/"/>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

      was (Author: ericacm):
    My bad regarding the faultcode.  You can throw a 
org.apache.cxf.interceptor.Fault, constructing it with your own Exception and 
faultCode.   You cannot customize the <detail> without using either a Java 
static nested inner class faultbean or by using a FaultInterceptor.

For example:

throw new Fault(new AuthorizationError("Error - Missing apiKey"),  new 
QName("http://ws.foo.com";, "InvalidApiKey"))

will result in this response:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>
   <soap:Body>
      <soap:Fault>
         <faultcode xmlns:ns1="http://ws.foo.com";>ns1:InvalidApiKey</faultcode>
         <faultstring>Error - Missing apiKey</faultstring>
         <detail>
            <ns1:AuthorizationError xmlns:ns1="http://ws.foo.com/"/>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>
  
> Better Fault handling demo
> --------------------------
>
>                 Key: CXF-1434
>                 URL: https://issues.apache.org/jira/browse/CXF-1434
>             Project: CXF
>          Issue Type: Wish
>          Components: Samples
>         Environment: this should run on any servlet container. Java >= 5
>            Reporter: David Castaneda
>            Priority: Minor
>         Attachments: CXFTest.rar, java_first_spring_support_fault.tar, 
> java_first_spring_support_faults.zip
>
>
> Sample application showing how to create custom Soap Faults.
> The target is to show a functional example of how to transform Exceptions 
> (Checked and Unchecked) to SoapFaults, that can contain Server or Client 
> fault and a custom detail part.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to