Day-8 Configuring Exception strategies

There are different types of strategies available in mule to configure exceptions.

exception-1

If we did not configure the exception strategy to the flow. then the exception will be handled by Mule Default Message exception strategy.

catchExceptionStrategy like similar to handling exception in Java using

try{

}catch(Exception ex){

}

exception-2

In flow:

<catch-exception-strategy doc:name=”CatchExceptionStrategy”>
<logger message=”Exception occured” level=”INFO” doc:name=”Logger”/>
</catch-exception-strategy>

 

It will handle all the exceptions.  if you want to handle each exception in a different manner then need to choose choiceExceptionStrategy.

exception-3

if you define exception strategy inside flow the scope of strategy is up to the flow. the flow won’t be available in other flows.

To make the flow available to al flows, the strategy need to declare exception on global scope rather flow scope. the refer the strategy in the flow using ReferenceExceptionStrategy.

exception-4

we can override Mule default exception strategy by declaring the exception strategy at global scope and marking it as default using configuration tag

  <configuration  defaultExceptionStrategy-ref=”myCatch”/> 

Code examples available at Day-8.zip at

https://drive.google.com/drive/folders/0B7kdTdRlWaF_TVhOaTk1cDVEYzQ

 

 

Day -7 Configuring SOAP web Services

In Mule ESB we can configure SOAP based web services through CXF component available in component palette.  we can develop services and clients for Simple and JAX-WS and proxy.

we can configure code first and contract first style web services.

  1. Exposing a method implementation as web service without JAX-WS
  2. Exposing a method implementation as web service with JAX-WS
  3. Exposing Contract first web service

Steps for Simple Service without JAX-WS.

  • configure HTTP component
  • Code the Service interface and implementation.

package simplesoap;
public interface WishService {
public String sayHello(String name);
}

package simplesoap;
public class WishServiceImpl implements WishService {
@Override
public String sayHello(String name) {
return “Hello” + name + “How are you ??” ;
}
}

  • Configure Java componentSOAP-1
  • Configure CXF component.SOAP-2
  • The configuration looks like
  • SOAP-3

2) Configuring service with JAX-WS

TO expose Jax-WS based web services, we need to annotate the service interface with @webservice

Steps are same as above service, only the service interface is annotated with @Webservice annotation

package jaxwssoap;
import javax.jws.WebService;
@WebService
public interface EmployeeService {
public SalaryDetails getEmpSalDetails(Employee emp);
}

  1. Exposing Contract first web service, Please refer
    •  https://dzone.com/articles/mulesoft-contract-first-web-service-development

Code examples find at Day-7.zip at

https://drive.google.com/drive/folders/0B7kdTdRlWaF_TVhOaTk1cDVEYzQ

Day-6 JMS and DB Insert

Configure JMS queue in Mule flow. we are using ActiveMQ JMS implementation for this demo.

  • Download  ActiveMQ from http://activemq.apache.org/download.html
  • Navigate to the path of activeMq
  • C:\xxxxx\apache-activemq-5.14.2-bin\apache-activemq-5.14.2\bin\win64
  • start ActiveMq messging server by giving command as >activemq
  • Configure ActiveMq to Anypoint studio
  • Drag and drop JMS icon to canvas
  • JMS
  • the properties as below. select the exchange pattern one-way or request-response based on requirement and provide queue namejms-2
  • Provide queue name and click on + icon
  • jms-3
  • provide username and password as admin/admin
  • Configuration complete

Demo-1: JMS as outbound endpoint.

send a request to mule flow where JMS queue configured as outbound endpoint

Jms-4

Import and execute the project, analyze the ActiveMQ console at

http://localhost:8161/admin/index.jsp

open the queues tab to see the queue details.

Demo-2 JMS as Inbound.

Design a flow that initiates from the JMS queue.

JMS-5

download and execute the project jmsreceiver.

Use ActiveMQ console to send the message to JMS queue. by clicking “Send” menu item on ActiveMQ home page

JMS-6

 

 

DB Insert Program:

Use Expression transformer to retrieve the fields from the payload. expression transformer will create new outbound endpoint properties. and populates them using Mule expression language.

DB_Insert1

DB-Insert-2

Import the project DBInsertDemo  to the Anypoint  and run the flow

Test the flow with Postman or SOAPUI using the payload

<?xml version=”1.0″ encoding=”UTF-8″?>
<MovieDetail>
<movieCode>robo</movieCode>
<movieName>robo</movieName>
<director>Raj</director>
<hero>HYD</hero>
<releaseDate>2017-05-28</releaseDate>
<status>HYD</status>
</MovieDetail>

makesure you selected mime type as application/xml while sending the request.

4) Analyze the Iterating the ResultSet and sending each record as JMS message in DBdemo projectDB-Iterate

The Demo projects available at Day-6.zip

https://drive.google.com/drive/folders/0B7kdTdRlWaF_TVhOaTk1cDVEYzQ

Day-5 Database connectivity and Sync & Async FLow concept

Concepts discussed today

  • Database connectivity and retrieving information
  • Sync-Async flows

Database connectivity:  MySql database has out of box support for Mule platform.

create Maven based mule project in order to manage database dependent jars. else create normal Mule project add mysql driver jar file to the build path.

DB setup:

created DB schema as :

CREATE DATABASE `mulesupport` /*!40100 DEFAULT CHARACTER SET utf8 */;

Created table in DB moviedetails in mulesupport schema as

CREATE TABLE `moviedetails` (
`movieCode` varchar(7) NOT NULL,
`movieName` varchar(50) DEFAULT NULL,
`director` varchar(45) DEFAULT NULL,
`hero` varchar(45) DEFAULT NULL,
`releaseDate` date DEFAULT NULL,
`status` varchar(14) DEFAULT NULL,
PRIMARY KEY (`movieCode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

inserted few records in to database as

INSERT INTO `mulesupport`.`moviedetails`
(`movieCode`,
`movieName`,
`director`,
`hero`,
`releaseDate`,
`status`)
VALUES
(<{movieCode: }>,
<{movieName: }>,
<{director: }>,
<{hero: }>,
<{releaseDate: }>,
<{status: }>);

insert the date format as yyyy-MM-dd for release date field .

Application execution:

Design a flow that contains DB as message processor

db_select

execute the 3 modes of query processing.  execute the shared project and try to run the similar requirement in a customized way.

Sync and Async Flows:

Incase of Async caller won’t wait for the response from the calle. whereas in Sync mode caller blocks till the response received from the called flow.

execute the analyze the project and try to create your own customized implementation.

<?xml version=”1.0″ encoding=”UTF-8″?>

<mule xmlns:http=”http://www.mulesoft.org/schema/mule/http&#8221; xmlns:tracking=”http://www.mulesoft.org/schema/mule/ee/tracking&#8221; xmlns=”http://www.mulesoft.org/schema/mule/core&#8221; xmlns:doc=”http://www.mulesoft.org/schema/mule/documentation&#8221;
xmlns:spring=”http://www.springframework.org/schema/beans&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd”&gt;
<http:listener-config name=”HTTP_Listener_Configuration” host=”localhost” port=”8081″ doc:name=”HTTP Listener Configuration”/>
<flow name=”Flow-1″>
<http:listener config-ref=”HTTP_Listener_Configuration” path=”/” doc:name=”HTTP”/>
<logger message=”got request” level=”INFO” doc:name=”Logger”/>
<async doc:name=”Async”>
<flow-ref name=”flow-2″ doc:name=”flow1″/>
</async>
<logger message=”In Flow1 after referncing flow2″ level=”INFO” doc:name=”Logger”/>
</flow>
<flow name=”flow-2″>
<component class=”syncasync.MyObj” doc:name=”Java”/>
<logger message=”In Flow2 executing the flow” level=”INFO” doc:name=”Logger”/>
</flow>
</mule>

Please find the demo projects available  at day-5 zip

https://drive.google.com/drive/folders/0B7kdTdRlWaF_TVhOaTk1cDVEYzQ

Day-4 Flows and Variables

Discussed concepts

  • Connecting Flows
  • Passing properties between flows
  • Flow and session Variables
  • Flows, sub flows and private flows
  • Synchronous and Asynchronous flows

Connecting Flows:

Capture

Points to observe:

  • VM endpoint configuration
  • Properties flowing from first flow to second flow
  • what need to do if we want to copy all inbound properties of first flow to the second flow
  • download execute the project “connectingflows” in Anypoint studio
  • Test from the browser:  http://localhost:8081?name=abc&age=22
  • How to copy selected inbound properties to outbound. execute the demo project  “usingmessagetransformer”  to analyze this.

Using Flow-reference 

flow-ref

Debug the project and test with browser http://localhost:8085?name=abc&age=22

2. Flow and Session Variables:

flowSession

Points to observe

  • Import the project and analyze how the flow and session variables are created.
  • Debug the demo and understand scope of flow and session variables

The projects available at Day-4.zip https://drive.google.com/drive/folders/0B7kdTdRlWaF_TVhOaTk1cDVEYzQ

Mule Exercises( Day 1,2 and 3)

Please find course contents and demo projects  here https://drive.google.com/drive/folders/0B7kdTdRlWaF_TVhOaTk1cDVEYzQ

Lab -1:  Mule Basics

  • 1) Develop a flow that will display “HelloWorld”  to the browser.
  • 2) Install Postman plug-in to google  chrome and  send HTTP POST request,

“Hello World”  as Payload, print payload using logger component and observe Inbound and outbound properties in debug mode.

Lab-2: Configuring Java component to Mule Flow

  • 1) Configure component with Method Entry point resolver
  • 2) Configure Java component with three different types of method arguments with the Help of Invoke activity
  • 3) What is the difference between Configuring java component as Spring bean and configuring component as non-spring based?
  • 4) Develop a component implementing Callable Interface
  • 5) Develop a Java component using Annotations.

 

Lab-3: Mule Expression Language:

  • 1) What is syntax of retrieving inboundProperties of  Mule Message
  • 2) What is Mule Expression to Retrieve Http method? In how many ways we can define this expression?
  • 3) Develop  Xpath expression to extract data from payload
  • 4) Develop regular expression to extract data from Payload

Lab-4: Connecting Flows

  • 1) Connecting the flows using VM endpoints and flowref, observe inbound and outbound properties in both scenarios

 

 

 

 

 

 

MuleSoft: REST web Service Development

Learn about how to expose and consume simple RESTful web service in Mule Anypoint.

 

Steps required to execute:

  1. Configure Http endpoint in Anypoint studio
  2. Create Java implementation for service
  3. Configure the REST component
  4. Test the Rest Service

Configure Http endpoint in Anypoint studio:

create a Flow with Http endpoint, configure the HTTP endpoint with Host and port as localhost and 8081.

HTTP-endpointhttp-configure

create a package com.javamirchi.rest under source folder src/main/java

package

 

Create Java implementation for service

package com.javamirchi.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path(“/users”)
public class SimpleRestTest {

@GET
@Path(“{name}”)
public Response getWishes(@PathParam(“name”)String name){
String output = “Hi ” + name;
return Response.status(200).entity(output).build();
}

}

Configure the REST component

Drag and drop REST component from component pallette, and  configure the developed Java implementation as Spring bean.

Rest-configure

Rest-configure-2

Click ok, Finish and Finish.

Configuration is complete and ready to deploy the flow file as below

<?xml version=”1.0″ encoding=”UTF-8″?>

<mule xmlns:jersey=”http://www.mulesoft.org/schema/mule/jersey&#8221; xmlns:http=”http://www.mulesoft.org/schema/mule/http&#8221; xmlns=”http://www.mulesoft.org/schema/mule/core&#8221; xmlns:doc=”http://www.mulesoft.org/schema/mule/documentation&#8221;
xmlns:spring=”http://www.springframework.org/schema/beans&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd”&gt;
<http:listener-config name=”HTTP_Listener_Configuration” host=”localhost” port=”8081″ doc:name=”HTTP Listener Configuration”/>
<spring:beans>
<spring:bean id=”Bean” name=”Bean” class=”com.javamirchi.rest.SimpleRestTest” scope=”singleton”/>
<spring:bean id=”simpleRest” name=”simpleRest” class=”com.javamirchi.rest.SimpleRestTest”/>
</spring:beans>
<flow name=”restdemoFlow”>
<http:listener config-ref=”HTTP_Listener_Configuration” path=”/*” doc:name=”HTTP”/>
<jersey:resources doc:name=”REST”>
<component>
<spring-object bean=”Bean”/>
</component>
</jersey:resources>
</flow>
</mule>

Test the Rest Service:

Deploy the Flow to Mule runtime from AnyPoint studio, Make sure the flow deployed properly

Open browser and hit the Url:  http://localhost:8081/users/sai

You can watch Response as Hi Sai in the browser:

Congragulations ! you configured simple Rest service in Mule Flow.