How to write a Munit test case for an integration that is using a common HTTP request connector for calling 5 different resources of the system layer? - mulesoft

I am calling a system layer from process layer as
first get: /abc
get: /xyz
post: /efg
for all these 3 calls using a common http requestor by setting path, method and host before calling this http requestor.
how to mock this http requestor for each call that give me different responses?

You can just add 3 mock when's to your Munit. Each of them will have the processor 'http:request', but with attributes specific to the call. So in each mock you will provide the AttributeName="method" and AttributeName="path" where the values correspond to the specific call you want to mock. See an example of two mocks below.
<munit-tools:mock-when doc:name="Mock when POST" doc:id="8e3b66fe-b5bb-4f96-97b5-8970c1635b12" processor="http:request">
<munit-tools:with-attributes >
<munit-tools:with-attribute whereValue="POST" attributeName="method" />
<munit-tools:with-attribute whereValue="/post" attributeName="path" />
</munit-tools:with-attributes>
<munit-tools:then-return >
<munit-tools:payload value='#[{"data": "post"}]' mediaType="application/json" />
</munit-tools:then-return>
</munit-tools:mock-when>
<munit-tools:mock-when doc:name="Mock when GET" doc:id="4797dd50-8bc2-428a-9aba-7d03692fc1a2" processor="http:request" >
<munit-tools:with-attributes >
<munit-tools:with-attribute whereValue="GET" attributeName="method" />
<munit-tools:with-attribute whereValue="/get" attributeName="path" />
</munit-tools:with-attributes>
<munit-tools:then-return >
<munit-tools:payload value='#[{"data": "get"}]' mediaType="application/json" />
</munit-tools:then-return>
</munit-tools:mock-when>

Related

FileConnector with Start Delay

Hi is there any option to provide start Delay with file:inbound-endpoint?(FileConnector)
(I can see quartz is the alternate solution for this)
<flow name="ReadingFlow" processingStrategy="synchronous">
<file:inbound-endpoint path="{file.incoming.files}"
connector-ref="DefaultNoStreamingConnector"
pollingFrequency="${file.polling.frequency}">
</file:inbound-endpoint>
Switch to fixed frequency. It has such parameter tp delay at first check
<ftp:listener doc:name="On New or Updated File" >
<scheduling-strategy >
<fixed-frequency startDelay="123" />
</scheduling-strategy>
</ftp:listener>
No, there isn't. You could use a Poll scope as an alternative to start the flow, but an inbound endpoint can not be used in the middle of a flow because it is a message source (starts a flow), not an operation. You can use the Mule Requester Module to reference an inbound endpoint inside the flow, after the Poll started the flow.
I didn't mention the Quartz endpoint because it has been deprecated for years. The Poll scope replaces it.

<authorizationEntry queue="queue.>" read="test" write="test" admin="test" />

Hi earlier we were using below authorizationEntry to access(read/write) queues starting with "queue.".
Corresponding entry from activemq.xml
<authorizationEntry queue="queue.>"
read="test" write="test" admin="test" />
As per the latest requirement from client(External system), is there a possibility to access queues starting with "queue.".without credentials(username/password)
please let us know what changes we have to make in activemq.xml or configuration to achieve the same i.e., access queues without credentials
These queues are used in routes created using apache-camel ,spring DSL language
as said in doc :
To allow anonymous access to the broker, use anonymousAccessAllowed
attribute and set it to true as shown above. Now, when the client
connects without username and password provided, a default username
(anonymous) and group (anonymous) will be assigned to its security
context. You can use this username and password to authorize client's
access to appropriate broker resources (see the next section). You can
also change username and group that will be assigned to anonymous
users by using anonymousUser and anonymousGroup attributes.
src http://activemq.apache.org/security.html#Security-Anonymousaccess
so i think this can do the stuff
<simpleAuthenticationPlugin anonymousAccessAllowed="true">
<users>
<authenticationUser username="system" password="manager" groups="users,admins" />
<authenticationUser username="user" password="password" groups="users" />
<authenticationUser username="guest" password="password" groups="guests" />
<authenticationUser username="test" password="test" groups="test" />
</users>
</simpleAuthenticationPlugin>
<authorizationEntry queue="queue.>" read="test,anonymous" write="test,anonymous" admin="test,anonymous" />
if you use Advisory you have to add authorized groups to create Advisory topics :
<authorizationEntry topic="ActiveMQ.Advisory.>" read="anonymous" write="anonymous" admin="anonymous"/>

Angular Put request not working with Laravel 5.3 hosted on azure

I am sending PUT request on my Laravel 5.3 application that is hosted on azure webapps. But I receive a delayed response 504 (Gateway Timeout). While It is working on POSTman (chrome extension).
this is my angular code:
put : function (id, params) {
params.api_token = TOKEN;
return $http.put(url+'/lead/'+id, params);
},
And running this would give me 504 (Gateway Timeout) after 1 min
I have also setup web.config to handle PUT & DELETE. Described here in detail.
<handlers>
<remove name="PHP54_via_FastCGI" />
<add name="PHP54_via_FastCGI" path="*.php" verb="GET, PUT, POST, HEAD, OPTIONS, TRACE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK" modules="FastCgiModule" scriptProcessor="D:\Program Files (x86)\PHP\v5.4\php-cgi.exe" resourceType="Either" requireAccess="Script" />
</handlers>
So, Because Apache and IIS servers are different. IIS does not handle PUT and DELETE by default. It also handles params for PUT request differently.
Instead of body, you need to send it in a query string like ../resource?param1=value1. AKA x-www-form-urlencoded This article explains it thoroughly
As of angular, this worked for me.
function (id, params) {
params.api_token = TOKEN;
var params = $httpParamSerializerJQLike(params);
return $http.put(url+'/lead/'+id+'?'+params);
}
NOTE: In addition, your web.config does require <handler> tags to be able to handle these requests. which is defined here

Spring AOP is being invoked unexpectedly

I have configured Spring AOP for 2 different packages in our application to log exceptions.
There are 2 different configurations for each package:
<aop:config>
<aop:aspect id="aspectLoggging" ref="abcExceptionAspect">
<aop:pointcut id="pointCut"
expression="execution(* com.abc.*.*(..))" />
<aop:before method="logBefore" pointcut-ref="pointCut" />
<aop:after-throwing method="logExceptionABC"
throwing="error" pointcut-ref="pointCut" />
<aop:after method="logAfter" pointcut-ref="pointCut" />
</aop:aspect>
</aop:config>
<aop:config>
<aop:aspect id="aspectLoggging" ref="xyzlogAspect">
<aop:pointcut id="pointCut"
expression="execution(* com.xyz.*.*(..))" />
<aop:before method="logBefore" pointcut-ref="pointCut" />
<aop:after method="logAfter" pointcut-ref="pointCut" />
<aop:after-throwing method="logExceptionXYZ"
throwing="error" pointcut-ref="pointCut" />
</aop:aspect>
</aop:config>
In a service method call, there are calls to the methods of the classes belonging to each of these packages:
public void method()
{
method1(); -> package abc
method2(); -> package xyz
}
Some exception occurs in method2 which invokes logExceptionXYZ method where we are wrapping it in a generic exception, say ExceptionXYZ, and throwing it further.
But some how after this, the logExceptionABC method also gets invoked and throws a generic exception , say ExceptionABC.
I'm not able to understand as why logExceptionABC method is getting invoked?
Please let me know if someone knows about such an issue!
Regards,
Rahul
Same id is being assigned to both the aop:aspect tags. Similar is the case with the aop:pointcut tags as well.
Try with assigning unique IDs.

Mule CXF Marshall Response

I am using cxf:jaxws-client in Mule 3 and the response I get from my web service call is of type ReleasingInputStream. I have tried adding the http-response-to-message-transformer, but that generates an error - does anyone know how I can retrieve the response as an object as opposed to a ReleasingInputStream?
Many thanks.
To solve the issue put the <cxf-client> inside the <outbound-endpoint> section (NOT BEFORE IT), by modifying the following code
<cxf:jaxws-client
clientClass="com.xyz.services.WSServices"
port="WSServicesSoap"
wsdlLocation="classpath:wsdl-file.wsdl"
operation="GimmeDataOperation" />
<outbound-endpoint exchange-pattern="request-response" address="http://localhost:8083/OutboundService" />
which produces a ReleasingInputStream output to
<outbound-endpoint exchange-pattern="request-response" address="http://localhost:8083/OutboundService" >
<cxf:jaxws-client
clientClass="com.xyz.services.WSServices"
port="WSServicesSoap"
wsdlLocation="classpath:wsdl-file.wsdl"
operation="GimmeDataOperation" />
</outbound-endpoint>
that returns the expected object.
I was just having this same problem. I solved it by adding an ObjectToString transformer to the response side of the outbound endpoint like this:
<mule>
<object-to-string-transformer name="ObjectToString"/>
<flow>
...
...
...
<cxf:jaxws-client clientClass="com.my.ClientClass"
port="MyPort"
wsdlLocation="classpath:MyWsdl.wsdl"
operation="MyOperation" />
<outbound-endpoint address="http://some.address/path/to/service"
exchange-pattern="request-response"
responseTransformer-refs="ObjectToString" />
...
...
...
</flow>
</mule>
The whole point of jaxws-client is to receive the unmarshaled Java object, so getting the WS response as a String or ReleasingInputStream should not even be an option.
To make the <cxf:jaxws-client> "work" as one would expect the WS client to work - put the INSIDE of the <outbound-endpoint> you will be getting a correct Java object as a payload.

Resources