How to use Spring Rest Service with REST Component in Mule - mule

Hi I am working with Mule Studio and I want to use Spring Rest Service with REST component in the Mule. So how can I access Spring REST features with REST Component I don't want to use Jersey way of creating REST service with Mule.
I just want to declare one REST controller with spring annotation that will automatically invoke.

Mules Rest Component is a Jersey implementation of JAX-RS which loads the resource classes so that they can be accesses as Rest URLs.
Spring Rest Controller is the Spring way of creating a Rest service which runs ona web-container.
If you want to run the SpringRestController based rest service on Mule you can package and deploy it directly on Mule standalone. Mule can run a web applicaiton as it contains an embedded Jetty container.
Unfortunately you cannot include a Spring RestController into the Mules's REST component(which is a Jersey implementation). Controller's purpose is not to serve as a component.
By the way in Mule also you just need to specify the annotations and provide the resource class to the REST component. Mule takes care of the rest.
Hope this helps.

Related

How to use request and session scopes in spring-webflux (as of latest releases)

I am developing a rest web service using reactive programming through spring-webflux(Spring Boot 2.1 and Spring Framework 5.1). I need to create components having request level scope. #Scope annotation is suggested for spring MVC applications. But I found that the same doesn't work with webflux application.
Is there an equivalent feature available in webflux, as of latest release?
If not, what shall be the workaround here to create a new instance of a component on every incoming request?
I am trying to avoid use of new operator.
Thank you for the suggestions.
Unfortunately you cannot use request scopes in spring-webflux like in spring MVC applications. The main reason being, they use ThreadLocals which cannot be used by spring-webflux as work can be done on any thread at any time.
Spring webflux uses project-reactor at its core. So you can use Reactor Context which allows you to share data in your reactive pipeline.

Mule API AutoDiscovery vs Mule API GatewayProxy

When should we use API Proxy against API AutoDiscovery. After implementing both, I found AutoDiscovery can also apply policies, analytics which API Gateway does, only thing is I cannot use a different url if using AutoDiscovery. Main advantage of API Proxy would be if my Gateway application and Mule Implementation Project is in different subnet, so if we are my Gateway server is compromised, no one can get to my implementation network.
But if both interface and implementation is in the same network, and purpose is just to call a REST Endpoint, should we not go with API AutoDiscovery.
Problems with Mule API Gateway Proxy
No defined way of Exception Handling, if we are not able to reach the Implementation Server.
No defined way of moving the Proxy Application across environments (CI/CD)
Extra HTTP Hops, can be acceptable if the above 2 issues have a defined way
Mule API AutoDiscovery
Since this is in the Mule Application, standard Exception Handling.
CI/CD is defined as it is the Mule Implementation Project.
No Extra HTTP Hop.
Only thing here is, we cannot change the implementation URL, that is only tightly coupled thing.
Can someone provide insight on when should we go for API Gateway vs AutoDiscovery. Also currently is there a way of doing Exception Handling in API Gateway Project and also CI / CD ?
API Autodiscovery is required if you plan to apply/unapply a policy to a particular endpoint, and/or take advantage of usage statistics in the context of API Platform. Api Autodiscovery is kind of metadata that links a HTTP(s) listener to its counterpart API version on API Manager.
For example:
<api-platform-gw:api id="api.basic.path" apiName="My API" version="1.0.0" flowRef="basic.path">
</api-platform-gw:api>
<flow name="basic.path">
<http:listener config-ref="a.http.config" />
<set-payload value="Endpoint successfully called." />
</flow>
Autogenerated Mule Proxies do have autodiscovery defined. You can also develop your own project and define the corresponding autodiscovery either by using the Studio UI, or handling the XML config directly.
The proxies are mean to be used in the case that your implementation backend is not a Mule application (for example, an existing REST based API hosted in a Tomcat server). You can enrich the logic with custom exception handling among other things on the Mule side. If you'd like better exception handling on the implementation backend, you will have to implement it there.
If your implementation backend is a Mule based application, using a proxy is not required. For most use cases, adding the corresponding autodiscovery element in the configuration file will do the trick.

How to Deploy Mule as a REST Service

Hi I am working with Mule Studio and i am successfully running my flow in Mule Studio. I have certain issues related to implementation level since i have multiple flows in the one project.
How to deploy Mule as a REST Service with the existing flow.
If i am deploying my Mule as a REST Service what are the inputs i have to provide to make it run from the external HTTP Client based program.
When to use HTTP Client and when to use Mule Client. Which one fits where.
you can make use of RAML
1.create a RAML and generate the flows which internally referes your current flows
you can configure the Http details in generated flows
why you want to use http client and Mule client in your flows?

Using Swagger for documenting RESTful services in Mule

I want to use swagger for documenting our RESTful APIs. Our Jersey classes will be consumed from the mule flow. To use swagger for documenting my API I need to use the servlet configuration as mentioned in here - https://github.com/wordnik/swagger-core/wiki/Java-JAXRS-Quickstart
As the Jersey classes are deployed in mule, there is no web.XML.
If you know how to configure swagger with Mule please let me know how to do that. I truly appreciate your feedback and suggestions.
I see two possible options, the latter being the one with the highest chance of success:
Run a Servlet container inside Mule, as demonstrated by the bookstore example provided with the standalone distribution, configuring web.xml as indicated and making sure you're using servlet not http inbound endpoints in your Mule configuration.
Generate at build time a static Swagger configuration using https://github.com/ryankennedy/swagger-jaxrs-doclet and serve it using the static resource message processor from the HTTP transport.

axis2 vs spring-ws vs jersey

My friend asked to explain me what's the difference between Spring, axis2 and Jersey. Here I listed down a few differences that I'm aware of. Please comment/respond if you know more differences
Spring webservices:
A java web application with a servlet configured in
web.xml(org.springframework.ws.transport.http.MessageDispatcherServlet).
You can use spring annotated POJOs for creating web services
Supports both RESTful and SOAP based web services.
Since it’s a web application you can use http authentication mechanisms
for enabling security
Axis2:
The webservice application is a .aar file that will be deployed in
axis2.war
Use AXIOM for using non-primitive type arguments to web service calls
You can use JSR181 annotations to create webservices
You can use spring-dependency injection using axis2 extensions.
Supports both RESTful and SOAP based web services.
I guess you have to use ws-security implementation for
providing security
to your web services>
They claim hot deployment of webservices works but I haven’t seen
it working.
Jersey:
A regular web application with a servlet configured in web.xml.
Write custom message readers/writers for using
non-primitive type arguments to web
service calls
Since it’s a web application you can use http authentication mechanisms
for enabling security
Supports only RESTful implementation of web services
I have seen hot deployment working may be because it’s a web application
and the container can do hot
deployment
I'm not familiar with Jersey and Axis, but I can tell you something about Spring-WS.
You cannot use Spring-WS for restful webservices. Spring-WS is intended to be used for contract first webservices. You can however use the features of Spring 3.x and Spring-MVC for REST services.
As for authorization, you can easily wire in any sort of security (with Spring-Security for instance).
I'm a big fan of the 'automatic' (de) marshalling features of Spring-WS. Just annotate your methods with the correct types and it'll know what to do.