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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
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

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • CI/CD Using Maven With Connected Applications in Anypoint Platform for Runtime Fabric
  • DGS GraphQL and Spring Boot
  • Maven Dependency Scope Applied
  • Building A Simple AI Application in 2023 for Fun and Profit

Trending

  • Rethinking Recruitment: A Journey Through Hiring Practices
  • Segmentation Violation and How Rust Helps Overcome It
  • Doris: Unifying SQL Dialects for a Seamless Data Query Ecosystem
  • Chaos Engineering for Microservices
  1. DZone
  2. Coding
  3. Java
  4. Mule Application Deployment to Cloudhub Using Connected App

Mule Application Deployment to Cloudhub Using Connected App

We will create a Mule application and deploy the same to the cloud hub using Connected App.

By 
Shyam Raj Prasad user avatar
Shyam Raj Prasad
·
May. 02, 22 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
7.8K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, we will create a Mule application and deploy the same to the cloud hub using Connected App. 

Connected APP

The Connected Apps feature provides a framework that enables an external application to integrate with the Anypoint Platform using APIs through OAuth 2.0 and OpenID Connect. Connected apps help users delegate their access without sharing sensitive credentials or giving complete control of their accounts to third parties. Actions taken by connected apps are audited, and users can also revoke access. Note that some products do not currently include client IDs of the Connected Apps features. The Connected Apps feature enables you to use secure authentication protocols and control an app’s access to user data. Additionally, end-users can authorize the app to access their Anypoint Platform data.

Create a Mule Application in Anypoint Studio

Let's first create a mule application, and below are the steps:

  • First, download a RAML zip file from https://anypoint.mulesoft.com/exchange/68ef9520-24e9-4cf2-b2f5-620025690913/covid19-data-tracking-api/.
  • Go to the design center and import this RAML file for creating API specifications. Give name as COVID-19 Data Tracking API.
  • Publish the same RAML file to exchange with version 1.0.0.
  • Go to Anypoint studio and create a new project as covid-data-tracking-api. Next, choose import a published API. It will prompt a new window and enter your Anypoint credentials. Next, search Covid and import the RAML you have posted from your organization account. 
  • Run the application in Anypoint studio and hope it will be successfully deployed. 

Configure Maven Settings Using Connected App

We will create a global Maven settings.xml that allows a Maven build outside of Studio to retrieve artifacts — such as the COVID-19 Data Tracking API  specification — from your Anypoint Platform organization’s Exchange.

  • Maven-build: In a command-line interface, navigate to the base directory of covid-data-tracking-api and run a Maven build of this Mule app; this should succeed:
     
     
    mvn clean verify


  • Delete local Maven repo: Now, go to the directory \.m2\repository and run the below command to delete all artifacts downloaded from any exchange.
     
    rm -rf ~/.m2/repository/*-*-*-*-*
    


  • Maven-build: Re-run the Maven build from a command-line interface; this should now fail due to unresolvable dependencies   
    [ERROR] Failed to execute goal on project covid-data-tracking-api: Could not resolve dependencies for project com.mycompany:covid-data-tracking-api:mule-application:1.0.0-SNAPSHOT: Failed to collect dependencies at 4dfec539-dc02-40fe-8618-8747d32cfc66:covid-19-data-tracking-api:zip:raml:1.0.0: Failed to read artifact descriptor for 4dfec539-dc02-40fe-8618-8747d32cfc66:covid-19-data-tracking-api:zip:raml:1.0.0: Could not transfer artifact 4dfec539-dc02-40fe-8618-8747d32cfc66:covid-19-data-tracking-api:pom:1.0.0 from/to anypoint-exchange-v2 (https://maven.anypoint.mulesoft.com/api/v2/maven): authentication failed for https://maven.anypoint.mulesoft.com/api/v2/maven/4dfec539-dc02-40fe-8618-8747d32cfc66/covid-19-data-tracking-api/1.0.0/covid-19-data-tracking-api-1.0.0.pom, status: 401 Unauthorized -> [Help 1]

  • Create Exchange Viewer Connected App: In Anypoint Access Management, create a new Connected App that acts on its behalf (client credentials) for reading assets from Exchange, adding the Exchange Viewer scope, and retrieving its client ID secret. client ID and secret will be used in the password section of settings.xml
  • Create settings.xml: In a text editor, create settings.xml in ~/.m2/ with credentials for reading from your Anypoint Platform organization’s Exchange as a Maven repository:  
    XML
     
    <settings>
     <servers>
     	<server>
     		<id>anypoint-exchange-v2</id>
     		<username>~~~Client~~~</username>
     		<password>clientID~?~clientSecret</password>
     	</server>
     </servers>
    </settings>
  • To use Connected App authentication, provide basic authentication and define the username  ~~~Client~~~ and the password as clientID~?~clientSecret. Replace clientID with the client ID and clientSecret with the client secret from the Connected App.
  • Maven-build: In a command-line interface, re-run a Maven build of covid-data-tracking-api as before; this should now succeed

Deploy to CloudHub Using the Mule Maven Plugin

This section will use the existing Maven build configuration to perform automated deployments to CloudHub. First, we need to create a Connected App for authentication for deployment. We will deploy the mule application covid-data-tracking-api to the CloudHub prod environment from the Maven command-line interface, passing the client ID and secret.

  • Configure CloudHub deployment: Add the below configuration to the Mule Maven plugin configuration for a simple deployment to CloudHub, utilizing Object Store v2, and using your initials as the hostname prefix as before, such as shyam2603-:
    XML
     
    <configuration>
              <cloudHubDeployment>
                <businessGroup/>
                <environment>dev</environment>
                <region>us-east-2</region>
                <muleVersion>4.4.0</muleVersion>
                <applyLatestRuntimePatch>true</applyLatestRuntimePatch>
                <workers>1</workers>
                <workerType>MICRO</workerType>
                <objectStoreV2>true</objectStoreV2>
                <applicationName>shyam2603-${project.artifactId}</applicationName>
                <deploymentTimeout>600000</deploymentTimeout>
                <connectedAppClientId>${ap.ca.client_id}</connectedAppClientId>
                <connectedAppClientSecret> ${ap.ca.client_secret}</connectedAppClientSecret>
                <connectedAppGrantType>client_credentials</connectedAppGrantType>
                <properties>
                  <anypoint.platform.client_id> ${ap.client_id}</anypoint.platform.client_id>
                  <anypoint.platform.client_secret> ${ap.client_secret}</anypoint.platform.client_secret>
                </properties>
              </cloudHubDeployment>
            </configuration>


  • Create CloudHub Deployment Connected App: In Anypoint Access Management, create a new Connected App that acts on its behalf (client credentials) for deployment to CH, adding the Cloudhub Organization Admin, Create Applications, Delete Applications, Read Applications, View Environment, and View Organization scopes and applying to all environments and retrieve its client ID and secret. These client Id and secret will be used in the above configuration as ap.ca.client_id and ap.ca.client_secret 
  • Create Environment: In Anypoint Access Management, create a new environment dev in the sandbox and retrieves its client ID and secret. These client ID and secrets will be used in the above configuration as ap.client_id and ap.client_secret
  • Maven-deploy: In a command-line interface, deploy to CloudHub using the Mule Maven plugin, supplying the same client ID and secret of your Anypoint Platform organization as previously and the client ID and secret of your Connected App; this should result in a successful build:
     
    mvn -DmuleDeploy deploy -Dap.client_id=<insert-envirnoment-client-id> -
    Dap.client_secret=<insert-environment-client-secret>
     -Dap.ca.client_id=<insert-connected-app-client-id> -Dap.ca.client_secret
    =<insert-connected-app-client-secret>
    


  • Wait and observe: In Runtime Manager, verify the successful deployment of covid-data-tracking-api with your chosen hostname prefix to the dev environment, resulting in the same fully qualified domain name and endpoint URL.
  • Invoke: Invoke the API using this endpoint URL; this should return an HTTP 200 OK response with body:
     
    curl --location --request GET 'http://shyam2603-covid-data-tracking-api.us-e2.cloudhub.io/api/covid19/v1/locations?zipCode=01011' 
  • Note: The hostname will be different for you. The above endpoint URL will not be accessible after some time, as I am using a trial account.


Apache Maven app application

Opinions expressed by DZone contributors are their own.

Related

  • CI/CD Using Maven With Connected Applications in Anypoint Platform for Runtime Fabric
  • DGS GraphQL and Spring Boot
  • Maven Dependency Scope Applied
  • Building A Simple AI Application in 2023 for Fun and Profit

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • 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:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!