Using Swagger for documenting RESTful services in Mule - 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.

Related

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.

Mule:How to connect Mule ESB with Hybris?

I have a requirement to connect Mule ESB with Hybris. I didnt find Hybris connector provided by Mule( Also didnt find sample examples as well). This is the 1st time going to try Mule with Hybris..Please let me know the steps or efficient procedural way to connect Hybris.
Is the hybris URL enough to connect?. Please suggest me with your thoughts to implement. Thanks in advance.
Hybris has many ways to integrate with their platform. If you have a login you can access their docs which details examples of integration with the platform including JMS and the Platform Web Services.
There is no connector supplied by Mule, but you can access their Platform Web Services which are implemented with a HTTP Restful API using the Mule http transport or by building your own connector using the Mule DevKit.
The hybris wiki has pages dedicated to most of the endpoints and the request/response formats. You can view this here if you have a login: https://wiki.hybris.com/display/release5/WebService+API+-+Reference
Also, in your hybris installation there are a bunch of examples in /bin/ext-platform-optional/platformwebservices/src...
and /bin/ext-platform-optional/platformwebservices/testsrc which show the actual web service implementations and their test cases using Jersey client.

How to use Spring Rest Service with REST Component in 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.

Generate SOAP service in mule using WSDL file

i am trying to create a soap service in mule using a wsdl file. but i am getting following error -
Error generating from WSDL
Could not find velocity template file
org/apache/cxf/tools/wsdlto/frontend/jaxws/template/client.vm
Another thing:
In mule is there any tool to create WSDL file.
Is it necessary in mule that for every WSDL file it will create java classes.
I am facing little difficulties while doing top down(wsdl first) development. Please suggest me if there is any tutorial.
Mule's SOAP web service stack is based on CXF so use the code generator from CXF to generate client classes from each of your WSDLs.
This is described here: http://cxf.apache.org/docs/maven-cxf-codegen-plugin-wsdl-to-java.html
Also note that it's possible to call remote web services without generating client classes but it's very limited (only simple types can be used, no complex ones), see: http://www.mulesoft.org/documentation/display/current/WSDL+Connectors

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.