DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Commonly Occurring Errors in Microsoft Graph Integrations and How To Troubleshoot Them (Part 4)
  • High-Performance Java Serialization to Different Formats
  • Step-by-Step Guide to Use Anypoint MQ: Part 1
  • Introduction to JSON With Java

Trending

  • Exploring Sorting Algorithms: A Comprehensive Guide
  • How To Deploy Helidon Application to Kubernetes With Kubernetes Maven Plugin
  • A Better Web3 Experience: Account Abstraction From Flow (Part 2)
  • DevSecOps: Integrating Security Into Your DevOps Workflow
  1. DZone
  2. Coding
  3. Languages
  4. Mule Dismantle, Component Mule Example

Mule Dismantle, Component Mule Example

Kasi Ramanathan user avatar by
Kasi Ramanathan
·
Feb. 02, 15 · Interview
Like (1)
Save
Tweet
Share
1.38K Views

Join the DZone community and get the full member experience.

Join For Free

The component is program that has some part of logic which we can use in mule flow. We can use programming language like java, Expression language, java script, python etc., for a component.

Create a mule flow, add http end point to it, with the below configuration

Host: localhost

Port: 8082(port should be unique in the flows)

Create a java class inside src/main/java folder of the mule project

public class PrintPayload {
     public void method1(String args) {
         System.out.println("String as args");
         System.out.println(args);
     }
     public void method2(byte[] values) {
         System.out.println("byte as args");
         System.out.println(values);
     }
}

In the flow add a java component, refer the PrintPayload class in the class name: property of the java component.

Add string to bytearray transformer

Again add the java component, refer the PrintPayload class in the class name property.

The flow will look like below

And the flow will have the below configuration.

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" 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" version="EE-3.5.0" 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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
      <flow name="ComponentFlow1" doc:name="ComponentFlow1">
          <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8082" doc:name="HTTP"/>
          <component class="com.classes.PrintPayload" doc:name="Java"/>
          <string-to-byte-array-transformer doc:name="String to Byte Array"/>
          <component class="com.classes.PrintPayload" doc:name="Java"/>
      </flow>
</mule>

Run the application.

In the browser hit the url:

http://localhost:8082/?name=kasi

you will get the following output:

String as args

/?name=kasi

byte as args

[B@23a1f067

Mule calls the appropriate method based on payload type.

Java (programming language) Flow (web browser) Property (programming) application Host (Unix) Python (language) Strings Payload (computing) Data Types

Opinions expressed by DZone contributors are their own.

Related

  • Commonly Occurring Errors in Microsoft Graph Integrations and How To Troubleshoot Them (Part 4)
  • High-Performance Java Serialization to Different Formats
  • Step-by-Step Guide to Use Anypoint MQ: Part 1
  • Introduction to JSON With Java

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: