Return-Path: X-Original-To: apmail-cxf-users-archive@www.apache.org Delivered-To: apmail-cxf-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DC949107FA for ; Wed, 6 Nov 2013 14:31:13 +0000 (UTC) Received: (qmail 54770 invoked by uid 500); 6 Nov 2013 14:28:43 -0000 Delivered-To: apmail-cxf-users-archive@cxf.apache.org Received: (qmail 54484 invoked by uid 500); 6 Nov 2013 14:28:15 -0000 Mailing-List: contact users-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@cxf.apache.org Delivered-To: mailing list users@cxf.apache.org Received: (qmail 53808 invoked by uid 99); 6 Nov 2013 14:26:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Nov 2013 14:26:43 +0000 X-ASF-Spam-Status: No, hits=1.3 required=5.0 tests=SPF_PASS,URI_HEX X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [64.85.173.253] (HELO server.dankulp.com) (64.85.173.253) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Nov 2013 14:26:37 +0000 Received: by server.dankulp.com (Postfix, from userid 5000) id 92106185DB0; Wed, 6 Nov 2013 09:26:15 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on server.dankulp.com X-Spam-Level: X-Msg-File: /tmp/mailfilter-users@cxf.apache.org.pybyg4vWcV Received: from [172.18.4.223] (unknown [145.253.125.210]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by server.dankulp.com (Postfix) with ESMTPSA id 12B2C185DA9; Wed, 6 Nov 2013 09:26:09 -0500 (EST) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.0 \(1816\)) Subject: Re: HandleFault in CXF From: Daniel Kulp In-Reply-To: <1383218968274-5735813.post@n5.nabble.com> Date: Wed, 6 Nov 2013 15:26:07 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: References: <1383218968274-5735813.post@n5.nabble.com> To: users@cxf.apache.org, Faz X-Mailer: Apple Mail (2.1816) X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Status: No, score=-2.4 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, URIBL_BLOCKED,URI_HEX shortcircuit=no autolearn=no version=3.3.2 On Oct 31, 2013, at 12:29 PM, Faz = wrote: > Hi ALL, >=20 > I'm using CXf's fault out interceptor to intercept the exception from = the > web services method. That works fine within the handleMessage method.. = Now I > have two queries, >=20 > 1. How do I had extra information to the Fault object apart from = setting the > faultcode.? Most likely, what you would need/want to do is take the Exception/Fault = out of the message, create a new SoapFault with the new information, and = set that back in the message and let the rest of CXF=92s chain do it=92s = thing: public void handleMessage(SoapMessage message) throws Fault { Fault f =3D (Fault) message.getContent(Exception.class); SoapFault fault =3D SoapFault.createFault(f, = message.getVersion()); //modify the SoapFault or create a new one or something message.setContent(Exception.class, fault); } The default Soap[12|11]FaultOutInterceptor will then grab that SoapFault = from the message and output it correctly. > 2. Say if there is any error in the handleMessage method, the control = goes > to handleFault method but in the handle fault method it simply unwinds = and > logs something like - *GetMth has thrown exception, unwinding now: > java.lang.Exception:*. But the fault message(in xml format) is not = being > sent to the client as Output mesasage, How do I make sure that the = fault > message is sent as SOAPfault to the clinet? Do not throw any exceptions from the Fault chain. If there is a fault = thrown from the fault chain, there is really no way for us to be able to = know what can be done about, how to fix the situation, etc=85 The = assumption is that if a fault is thrown from the fault chain, then = something seriously has gone wrong and we cannot write anything out to = the client. The normal case that this occurs is if we cannot write to = the OutputStream due to the network closing the connection or similar. = In that case, there is nothing we can do except log the issue and move = on. Dan > [in the hanldeMessage bleow, i have place *f=3Dnull *to introduce the = fault ] >=20 > Handle message and handleFault methods: >=20 >=20 > *public class SimpleSOAPFaultInterceptor extends > AbstractSoapInterceptor { > private static Logger log =3D Logger.getLogger("org.apache"); > =09 > public SimpleSOAPFaultInterceptor() { > super(Phase.MARSHAL); > } > =09 > public void handleMessage(SoapMessage message) throws Fault { > // TODO Auto-generated method stub > try { > =09 > Fault f =3D (Fault) = message.getContent(Exception.class); > //f=3Dnull; /[Introduing an excpetion so that = handleFault is called]/ =09 > log.debug(" f ::::: "+ f.getCode()); > Throwable cause =3D f.getCause(); > if (cause instanceof MyServiceException) { > f.setFaultCode(new QName("", = String.valueOf("100000"))); > } else { > log.warn("!!!!!!Unexpected Exception = thrown ", cause); > } > } catch (SOAPException e) { > // TODO Auto-generated catch block > System.out.println("CAUGHT HERE "+e); > e.printStackTrace(); > } catch (Exception e) { > // TODO Auto-generated catch block > System.out.println("CAUGHT HERE = Exception "+e); > throw new Fault(new Exception( > "Exception....")); > } > } > =09 > =09 > =09 > @Override > public void handleFault(SoapMessage message) { > // TODO Auto-generated method stub > super.handleFault(message); > =09 > System.out.println("**handleFault the message ** = "+message); > Fault f =3D (Fault) message.getContent(Exception.class); > System.out.println("**the f ** "+f); > //f.setFaultCode(new QName("", String.valueOf("8"))); > //SoapFault sf =3D new SoapFault("message",new QName("", > String.valueOf("99000"))); > //SoapFault.createFault(f, message.getVersion()) > // .setMessage("INSIDE DIUDE"); > =09 > }* >=20 >=20 >=20 > -- > View this message in context: = http://cxf.547215.n5.nabble.com/HandleFault-in-CXF-tp5735813.html > Sent from the cxf-user mailing list archive at Nabble.com. --=20 Daniel Kulp dkulp@apache.org - http://dankulp.com/blog Talend Community Coder - http://coders.talend.com