Handling errors from Java Validator in REST binding
mimer May 7, 2014 5:40 AMHi
I was wondering what the best practice for for handling errors from custom JavaValidators is? If a validation fails, and i haven't written a custom MessageComposer, it gets to the client as a HTTP 500, which obviously isn't what i want, but do i have to do all the error message handling myself? Unfortunately the documentation and quickstarts aren't much help, and looking at the Message Trace , it looks like i have to dig everything out of a CamelExceptionCaught.
What would be the correct way to handle validation errors?
------- Begin Message Trace -------
Consumer -> {urn:com.dtgroup.mobilebranch.switchyard:MobileBranchSwitchyardServices:1.0}InventoryBalanceService
Provider -> {urn:com.dtgroup.mobilebranch.switchyard:MobileBranchSwitchyardServices:1.0}InventoryBalanceService
Operation -> getInventoryBalance
MEP -> IN_OUT
Phase -> OUT
State -> FAULT
Exchange Context ->
CamelCreatedTimestamp ............................: Wed May 07 11:03:16 CEST 2014
CamelExceptionCaught .............................: org.switchyard.HandlerException: SWITCHYARD014000: Validator 'org.switchyard.validate.internal.ValidatorUtil$1' failed: ItemSKUGroup is not defined [null].
CamelFailureEndpoint .............................: direct://%7Burn:com.dtgroup.mobilebranch.switchyard:MobileBranchSwitchyardServices:1.0%7DInventoryBalanceService
CamelFailureHandled ..............................: true
CamelFilterMatched ...............................: true
CamelToEndpoint ..................................: direct://%7Burn:com.dtgroup.mobilebranch.switchyard:MobileBranchSwitchyardServices:1.0%7DInventoryBalanceService
org.switchyard.bus.camel.consumer ................: ServiceReference [name={urn:com.dtgroup.mobilebranch.switchyard:MobileBranchSwitchyardServices:1.0}InventoryBalanceService, interface=SWITCHYARD010007: BaseServiceInterface [type=java, operations=[SWITCHYARD010008: isAlive : IN_OUT : [null, java:java.lang.String, null], SWITCHYARD010008: getInventoryBalance : IN_OUT : [java:com.dtgroup.services.inventory.InventoryBalanceRequest, java:com.dtgroup.services.inventory.InventoryBalanceListResponse, null]]], domain=ServiceDomain [name=null]]
org.switchyard.bus.camel.contract ................: org.switchyard.metadata.BaseExchangeContract@12488bd
org.switchyard.bus.camel.dispatcher ..............: org.switchyard.bus.camel.ExchangeDispatcher@18d3e36
org.switchyard.bus.camel.fault ...................: true
org.switchyard.bus.camel.labels ..................: {org.switchyard.exchangeGatewayName=[org.switchyard.label.behavior.transient], org.switchyard.exchangeInitiatedNS=[org.switchyard.label.behavior.transient], org.switchyard.security.context.SecurityContext=[org.switchyard.label.behavior.transient], org.switchyard.exchange.transaction.beforeInvoked=[org.switchyard.label.behavior.transient]}
org.switchyard.bus.camel.phase ...................: OUT
org.switchyard.bus.camel.provider ................: Service [name={urn:com.dtgroup.mobilebranch.switchyard:MobileBranchSwitchyardServices:1.0}InventoryBalanceService, interface=SWITCHYARD010007: BaseServiceInterface [type=java, operations=[SWITCHYARD010008: getInventoryBalance : IN_OUT : [java:com.dtgroup.services.inventory.InventoryBalanceRequest, java:com.dtgroup.services.inventory.InventoryBalanceListResponse, null], SWITCHYARD010008: isAlive : IN_OUT : [null, java:java.lang.String, null]]], domain=ServiceDomain [name=null], metadata=org.switchyard.metadata.ServiceMetadataBuilder$ServiceMetadataImpl@1e98cd2]
org.switchyard.bus.camel.replyHandler ............: org.switchyard.component.common.SynchronousInOutHandler@1ef8a98
org.switchyard.exchange.transaction.beforeInvoked : true
org.switchyard.exchangeGatewayName ...............: InventoryBalanceRestService
org.switchyard.exchangeInitiatedNS ...............: 1399453396740738000
org.switchyard.rollbackOnFault ...................: true
Message Context ->
org.switchyard.bus.camel.labels .....: {org.switchyard.bus.camel.messageSent=[org.switchyard.label.behavior.transient], org.switchyard.exchangeDurationMS=[org.switchyard.label.behavior.transient]}
org.switchyard.bus.camel.messageSent : true
org.switchyard.exchangeDurationMS ...: 42
org.switchyard.messageId ............: ID-McDennis-local-51041-1399452748164-5-3
org.switchyard.relatesTo ............: ID-McDennis-local-51041-1399452748164-5-1
------ End Message Trace -------
Thanks!
/Dennis