reference exception strategy

11
Reference Exception Strategy

Upload: sivachandra-mandalapu

Post on 12-Jan-2017

23 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Reference exception strategy

Reference Exception Strategy

Page 2: Reference exception strategy

Abstract

• The main motto of this PPT is How to use Reference Exception Strategy in our applications.

Page 3: Reference exception strategy

Introduction

• You can create one or more global exception strategies to reuse in flows throughout your entire Mule application. First, create a global exception strategy, then add a Reference Exception Strategy to a flow to apply the error handling behavior of a specific global exception strategy.

Page 4: Reference exception strategy

Example

Page 5: Reference exception strategy

.mflow• <?xml version="1.0" encoding="UTF-8"?>

• <mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"

• xmlns:spring="http://www.springframework.org/schema/beans" • xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"• xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-current.xsd• http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd• http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd• http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">• <http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8087" doc:name="HTTP Listener

Configuration"/>• <flow name="JsonSchemaValidatorFlow">• <http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>• <json:validate-schema schemaLocation="Schema.json" doc:name="Validate JSON Schema"/>• <logger message="--Valid input" level="INFO" doc:name="Logger"/>• <exception-strategy ref="JsonSchemaValidatorCatch_Exception_Strategy" doc:name="Reference Exception Strategy"/>• </flow>• <catch-exception-strategy name="JsonSchemaValidatorCatch_Exception_Strategy">• <set-property propertyName="http.status" value="400" doc:name="Property"/>• <set-payload value="Invalid input request" doc:name="Set Payload"/>• </catch-exception-strategy>• </mule>

Page 6: Reference exception strategy

• Place the schema file in src/main/resources

Schema.json

Page 7: Reference exception strategy

• Output:• If the input is valid input:• INFO 2016-12-22 09:23:32,157

[[JsonSchemaValidator].HTTP_Listener_Configuration.worker.02] org.mule.api.processor.LoggerMessageProcessor: --Valid input

Page 8: Reference exception strategy

• If the input is invalid input:

• ERROR 2016-12-22 09:23:15,139 [[JsonSchemaValidator].HTTP_Listener_Configuration.worker.02] org.mule.exception.DefaultMessagingExceptionStrategy: • ********************************************************************************• Message : Json content is not compliant with schema• com.github.fge.jsonschema.core.report.ListProcessingReport: failure• --- BEGIN MESSAGES ---• error: object has missing required properties (["firstName"])• level: "error"• schema: {"loadingURI":"file:/C:/Users/sivachandra.mandalap/AnypointStudio/workspace1/.mule/apps/JsonSchemaValidator/classes/Schema.json#","pointer":""}• instance: {"pointer":""}• domain: "validation"• keyword: "required"• required: ["firstName","lastName"]• missing: ["firstName"]• --- END MESSAGES ---

• Payload : {"lastName":"def","age":10}• Payload Type : java.lang.String• Element : /JsonSchemaValidatorFlow/processors/0 @ JsonSchemaValidator• --------------------------------------------------------------------------------• Root Exception stack trace:• org.mule.module.json.validation.JsonSchemaValidationException: Json content is not compliant with schema• com.github.fge.jsonschema.core.report.ListProcessingReport: failure• --- BEGIN MESSAGES ---• error: object has missing required properties (["firstName"])• level: "error"• schema: {"loadingURI":"file:/C:/Users/sivachandra.mandalap/AnypointStudio/workspace1/.mule/apps/JsonSchemaValidator/classes/Schema.json#","pointer":""}• instance: {"pointer":""}• domain: "validation"• keyword: "required"• required: ["firstName","lastName"]• missing: ["firstName"]• --- END MESSAGES ---

• at org.mule.module.json.validation.JsonSchemaValidator.validate(JsonSchemaValidator.java:286)• at org.mule.module.json.validation.ValidateJsonSchemaMessageProcessor.process(ValidateJsonSchemaMessageProcessor.java:46)• at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)• at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:108)• at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)

Page 9: Reference exception strategy

• Flow of execution:1. URL to trigger the service from browserValid Request:

Page 10: Reference exception strategy

• Invalid Request: