CXF custom validation and FaultOutInterceptors for manage Errors -


i have developed web service using cxf. in case of error due request doesn't respect xsd schema asociated custom error sent client. that:

1- have added specific eventhandlervalidator , specific faultoutinterceptor in web-services.xml

<jaxws:endpoint id="getnewcustomerorderid" implementor="#getnewcustomerorderidws" address="/getnewcustomerorderid">     <jaxws:properties>         <entry key="jaxb-validation-event-handler">             <ref bean="getnewcustomerorderideventhandlervalidator"/>         </entry>         <entry key="schema-validation-enabled" value="in"/>         <entry key="set-jaxb-validation-event-handler" value="true"/>     </jaxws:properties>     <jaxws:outfaultinterceptors>         <ref bean="getnewcustomerorderidcxffaultoutinterceptor"/>     </jaxws:outfaultinterceptors> </jaxws:endpoint>`enter code here 

2 - have implemented these classes:

in handlevalidator throw own exception code , message

public class getnewcustomerorderideventhandlervalidator implements validationeventhandler {  @override public boolean handleevent(validationevent event) {     throw new myexception(myexceptioncode.ercc_gncoi_100, event.getmessage());  } 

}

faultexceptioninterceptor runs every exception thrown during webservice call. want catch myexception code ercc_gncoi_100 customizing it, so:

public class getnewcustomerorderidcxffaultoutinterceptor extends abstractsoapinterceptor {  private static final logger logger = loggerfactory.getlogger(createcustomerordercxffaultoutinterceptor.class);  @inject private createcustomerorderfaultexceptionservice createcustomerorderfaultexceptionservice;  private static final jaxbcontext jaxbcontext;  static {     try {         jaxbcontext = jaxbcontext.newinstance(createcustomerorderexception.class);     } catch (jaxbexception e) {         logger.error(cormoranmarker.tech, "error during jaxbcontext instantiation");         throw new runtimeexception(e);     } }  public getnewcustomerorderidcxffaultoutinterceptor() {     super(phase.marshal); }   @override public void handlemessage(soapmessage message) throws fault {     fault exceptionfault = (fault) message.getcontent(exception.class);     exceptionfault.setmessage("my custom message");     if (exceptionfault.getcause() instanceof myexception) {         myexception myexception = (myexception) exceptionfault                 .getcause();          if (myexception.getcode().equals(myexception.ercc_gncoi_100)) {// validation                                                                                                             // schema                                                                                                             // errors             element elt = buildexceptionfaultdetail(cormoranfunctionalexception);             exceptionfault.setdetail(elt);         }      }  }  private element buildexceptionfaultdetail(cormoranfunctionalexception cormoranfunctionalexception) {     // build custom response  } 

}

however, in interceptor i'm not able catch exception:

fault exceptionfault = (fault) message.getcontent(exception.class); 

this line gets unmarshalling exception:

unmarshalling error: cvc-complex-type.2.4.a: invalid content found starting element 'customerordertype1'. 1 of '{customerorderid, version, customerordertype, depositdate}' expected.  

in logs see exception has been thrown:

12:32:27.338 [qtp200426125-38] error c.o.c.c.e.myexception - [] - myexception : non-respect du schéma (xsd) du webservice exposé par cormoran : cvc-complex-type.2.4.a: invalid content found starting element 'customerordertype1'. 1 of '{customerorderid, version, customerordertype, depositdate}' expected. 

could me?

thank in advance!

auri

there 2 problems interceptor written.

first, need set new content message after make changes. that, can add following handlemessage method after code

message.setcontent(exception.class, exceptionfault);

second, phase chose late make changes fault object. looks pre_stream latest phase allows change. cxf interceptor documentation has full list of phases.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -