Elmah Filter for Nancy MVC Framework - elmah

I'm using Nancy MVC and Nancy.Elmah. Currently, there's a bug in Nancy that raises an exception for requests with accept headers of "*". Here's the Elmah log:
System.ArgumentException
inputString not in correct Type/SubType format Parameter name: *
System.ArgumentException: inputString not in correct Type/SubType format
Parameter name: *
at Nancy.Responses.Negotiation.MediaRange.FromString(String contentType)
at Nancy.Routing.DefaultRouteInvoker.<>c__DisplayClass5a.<>c__DisplayClass5c.<GetCompatibleHeaders>b__4f(MediaRange mr)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Nancy.Routing.DefaultRouteInvoker.GetCompatibleHeaders(IEnumerable`1 coercedAcceptHeaders, NancyContext context, Negotiator negotiator)
at Nancy.Routing.DefaultRouteInvoker.ProcessAsNegotiator(Object routeResult, NancyContext context)
at Nancy.Routing.DefaultRouteInvoker.InvokeRouteWithStrategy(Object result, NancyContext context)
at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
at CallSite.Target(Closure , CallSite , DefaultRouteInvoker , Object , NancyContext )
at Nancy.Routing.DefaultRouteInvoker.Invoke(Route route, DynamicDictionary parameters, NancyContext context)
at Nancy.Routing.DefaultRequestDispatcher.Dispatch(NancyContext context)
at Nancy.NancyEngine.InvokeRequestLifeCycle(NancyContext context, IPipelines pipelines)
I tried filtering it with the following web.config
<errorFilter>
<test>
<or>
<regex binding="Exception" pattern="inputString not in correct Type/SubType format Parameter name: \*" />
</or>
</test>
</errorFilter>
But the errors are not filtered out.
Also tried binding="BaseException.Message" without luck.
I would like a way to filter these messages from being logged. Could some "correct" my filter configuration above to do so? Thanks!

Well, after a few more hours of trail and error I discovered the issue is that the, "Parameter name: *" portion is not part of the actual exception message. I'm guessing that the message in the log is a concatenation of the exception message and parameter values. Changed the filter as shown and it's works.
<errorFilter>
<test>
<regex binding="Exception.Message" pattern="inputString not in correct Type/SubType format" />
</test>
</errorFilter>

Related

You called the function 'Value Selector' with these arguments

I am in the process of implementing a LoanBroker with Mulesoft but have an error message when sending a request. I get the following error message back from Postman and Mulesoft Anypoint Studio:
ERROR 2021-06-27 15:20:51,133 [[MuleRuntime].uber.04: [loanbroker].LoanBrokerFlow_Gr7.CPU_LITE #254be3ee] [processor: LoanBrokerFlow_Gr7/processors/0; event: 7e49f560-d74a-11eb-b598-b66921dc5aa5] org.mule.runtime.core.internal.exception.OnErrorPropagateHandler:
********************************************************************************
Message: "You called the function 'Value Selector' with these arguments:
1: Binary ("" as Binary {base: "64"})
2: Name ("amount")
But it expects one of these combinations:
(Array, Name)
(Array, String)
(Date, Name)
(DateTime, Name)
(LocalDateTime, Name)
(LocalTime, Name)
(Object, Name)
(Object, String)
(Period, Name)
(Time, Name)
1| payload.amount
^^^^^^^^^^^^^^
Trace:
at main (line: 1, column: 1)" evaluating expression: "payload.amount".
Element : LoanBrokerFlow_Gr7/processors/0 # loanbroker:bi_gruppe7.xml:34 (Copy_of_setAmount)
Element DSL : <set-variable value="#[payload.amount]" doc:name="Copy_of_setAmount" doc:id="cbcca557-1a69-4cf2-80b1-64333175589d" variableName="amount"></set-variable>
Error type : MULE:EXPRESSION
FlowStack : at LoanBrokerFlow_Gr7(LoanBrokerFlow_Gr7/processors/0 # loanbroker:bi_gruppe7.xml:34 (Copy_of_setAmount))
(set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
Can anyone help me?
Thanks
This generally happens when one tries to access inner value of a payload like json but incoming payload is NOT actually a json type.
One could check the payload mediaType and then try to access the amount in order to avoid Value Selector exception.
%dw 2.0
output application/java
---
if( !isEmpty(payload) and payload.^mediaType contains "json" )
payload.amount
else
read(payload, "application/json").amount //best effort
Would recommend creating a separate dataweave file like dwl/set-amount.dwl and referencing it.
You are probably sending some body in the HTTP request from Postman but Mule doesn't know how to read it. Maybe you did not the Content-Type header in the request to let DataWeave know it is a JSON (application/json) or XML (application/XML).
Ensure you are sending the right content type.
I ran into the same situation. I know exactly the base64 is a json. So, I tried to set the MIME Type by
<set-payload value="#[payload]" doc:name="Set Payload" mimeType="application/json"/>
It works for me.

Using ColdFusion to parse WSDL/SOAP

I'm passing in a USERID into what I believe to be either a SOAP request. I've never worked with SOAP and not quite sure where to start so if my question doesn't quite make sense, let me know and I'll try to fill in missing details.
Context for question:
I'm converting an excel macro (the macro will query pass the userid to the server and the server will return employee details such as name, email, address, etc.) and turning into a web lookup.
I have the following code:
<cfscript>
variables.sso = '55555';
variables.serverURL = "http://search.corporate.ge.com/ldq/Query";
variables.queryString = "?serverID=ssoprod&searchBase=ou=domainWorker,+o=domain.com&Prebuilt=true&scope=2&filter=(domainoraclehrid=#variables.sso#)";
variables.webservice = "#variables.serverURL##variables.queryString#";
</cfscript>
<cfdump var="#variables.webservice#">
<cfhttp url="#variables.webservice#" method="get" result="response"></cfhttp>
<cfdump var="#response.fileContent#" label="soap content">
When I take the value from the dump of variables.webservice, and paste it directly into a browser, I get the following (assume userID of 55555):
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dsml="http://www.dsml.org/DSML">
<SOAP-ENV:Body>
<dsml:dsml xmlns:dsml="http://www.dsml.org/DSML">
<dsml:directory-entries>
<dsml:entry dn="domainssouid=1D8B0D04-91F0-1CAE-9BD7-002128B20D70,ou=domainWorker, o=domain.com">
...
<dsml:attr name="employeetype">
<dsml:value>Contractor</dsml:value>
</dsml:attr>
<dsml:attr name="givenname">
<dsml:value>John</dsml:value>
</dsml:attr>
<dsml:attr name="postalcode">
<dsml:value>90210</dsml:value>
</dsml:attr>
<dsml:attr name="domainoraclehrid">
<dsml:value>456456987</dsml:value>
</dsml:attr>
<dsml:attr name="mail">
<dsml:value>John.Doe#domain.com</dsml:value>
</dsml:attr>
<dsml:attr name="cn">
<dsml:value>Doe, John</dsml:value>
</dsml:attr>
...
</dsml:entry>
</dsml:directory-entries>
</dsml:dsml>
</SOAP-ENV:Body>
BUT when I dump of #response.fileContent#, I get something different, I get:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:f="http://www.w3.org/2001/06/soap-faults">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<SOAP-ENV:faultcode>MustUnderstand</SOAP-ENV:faultcode>
<SOAP-ENV:faultstring>ou=domainWorker,+o=domain.com: [LDAP: error code 34 - Invalid DN], Name Not valid - ou=domainWorker,+o=domain.com - filter -(domainoraclehrid=55555) </SOAP-ENV:faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Ultimately what I'd like to do is parse out the "cn", and "mail" details. What am I missing here? I suspect it might have something to do with ME accessing the URL directly (logged in user) where as the request is being made from a server and isn't "authenticated". If that is the case, how can I resolve this?
Update:
(Originally, I was a little perplexed about why I couldn't reproduce your results with CF2018, but now that I know you're using Lucee, the difference makes sense.)
Looking over the successful response, I noticed it doesn't contain a +, before the "o" (organization Name):
<dsml:entry dn="domainssouid=xxxx,ou=domainWorker, o=domain.com">
Which means the VBA call is treating the + as an encoding for a space, but CFHTTP is encoding it as a literal plus sign instead, causing an error because it breaks the LDAP query:
[LDAP: error code 34 - Invalid DN], Name Not valid - ou=domainWorker,+o=domain.com
The solution is to get rid of the plus sign + and replace it with a space:
searchBase=ou=domainWorker, o=domain.com
Interestingly, dumping the http request data shows that apparently CF2018 does things differently. Unlike Lucee, CF2018 treats the plus sign as a space.
CF2018 => %20 (space)
searchBase=ou%3DdomainWorker%2C%20o%3Ddomain.com
Lucee 5.2.8.50 => %2B (plus sign)
searchBase=ou%3DdomainWorker%2C%2Bo%3Ddomain.com

Camunda-Pass parameter between HTTP-CONNECTOR

I want to pass output of one REST API to another REST-API in camunda . My first API is returning JSON which has value of email .
I am getting output from first REST-API using HTTP-CONNECTOR script variable
<camunda:outputParameter name="email">
<camunda:script scriptFormat="JavaScript">var value = S(NUMBER, 'application/json');
print("DATA ::: "+ value);
var response = S(connector.getVariable("response"), 'application/json');
print("Response ::: "+ response );
print("Email :::"+ response.prop("email"));
response.prop("email");</camunda:script>
</camunda:outputParameter>
now I want to pass email in payload of another rest-API call for which I am using HTTP-CONNECTOR
<camunda:connector>
<camunda:inputOutput>
<camunda:inputParameter name="url">http://localhost:8080/step2</camunda:inputParameter>
<camunda:inputParameter name="method">POST</camunda:inputParameter>
<camunda:inputParameter name="header">
<camunda:map>
<camunda:entry key="accept">application/json</camunda:entry>
<camunda:entry key="content-type">application/json</camunda:entry>
</camunda:map>
</camunda:inputParameter>
<camunda:inputParameter name="payload">
<camunda:script scriptFormat="JavaScript">var email=execution.getVariable("email");</camunda:script>
</camunda:inputParameter>
</camunda:inputOutput>
<camunda:connectorId>http-connector</camunda:connectorId>
</camunda:connector>
but it's giving error as
w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type '' not supported]
How to pass output variable to next REST-API ?
<camunda:inputParameter name="header"> instead of this <camunda:inputParameter name="headers"> should be used , more-ever it's not possible to pass script as input to text variable.
so I used
<camunda:outputParameter name="email">
${response}
</camunda:outputParameter>
to pass complete response to next service

Wanted to remove property name while printing the log in WSO2

Here I have one doubt
I am creating log mediator in WSO2 and setting one property msg and it gives me output as follows
[2017-08-04 18:13:10,041] [] INFO - LogMediator Msg = Msg Coming************************
Here I just want the output like Msg Coming************************ I dont want to print property name...
How I will able to do it..
Example
<property name="*******************" value="hello" />
or
<property name="*******************" expression="translate('some string to log', 'abcdefg.....z', '****************************')" />
In first case you will get unknown property, in second unkond property with unknown value. Why you need such logging

Mock a message from a 3rd party system in Mule using MUnit

I'm writing a test suite (using Munit) for a Mule application that is processing new data coming from an instance of Magento. One of my flows is polling Magento for new customers and the message it receives is of type: com.magento.api.CustomerCustomerEntity
I'm wondering how I'd mock this so that in my test case, when the Magento message processor is called I can return a payload of the same type and make the appropriate assertations?
Currently my Munit test looks as follows:
<mock:config name="mock_MagentoToSalesforce" doc:name="Mock configuration"/>
<spring:beans>
<spring:import resource="classpath:MagentoToSalesforce.xml"/>
<spring:bean id="myBean" name="myBean" class="com.magento.api.CustomerCustomerEntity">
<spring:property name="email" value="test#test.com"/>
</spring:bean>
</spring:beans>
<munit:test name="MagentoToSalesforce-test-getCustomersFlowTest" description="Test">
<mock:when config-ref="mock_MagentoToSalesforce" messageProcessor=".*:.*" doc:name="Mock">
<mock:with-attributes>
<mock:with-attribute whereValue-ref="#[string:Get New Customers]" name="doc:name"/>
</mock:with-attributes>
<mock:then-return payload-ref="#[app.registry.myBean]"/>
</mock:when>
<flow-ref name="getCustomers" doc:name="Flow-ref to getCustomers"/>
</munit:test>
And the flow I'm trying to test is:
<flow name="getCustomers" processingStrategy="synchronous">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="30" timeUnit="SECONDS"/>
<watermark variable="watermark" default-expression="#[new org.mule.el.datetime.DateTime().plusYears(-30)]" update-expression="#[new org.mule.el.datetime.DateTime().plusYears(-0)]" selector-expression="#[new org.mule.el.datetime.DateTime(payload.created_at, 'yyyy-MM-dd HH:mm:ss')]"/>
<magento:list-customers config-ref="Magento" filter="dsql:SELECT confirmation,created_at,created_in,customer_id,dob,email,firstname,group_id,increment_id,lastname,middlename,password_hash,prefix,store_id,suffix,taxvat,updated_at,website_id FROM CustomerCustomerEntity WHERE updated_at > '#[flowVars.watermark]'" doc:name="Get New Customers"/>
</poll>
<foreach doc:name="For Each">
<data-mapper:transform config-ref="MagentoCustomer_To_SalesforceContact" doc:name="Map Customer to SFDC Contact">
<data-mapper:input-arguments>
<data-mapper:input-argument key="ContactSource">Magento</data-mapper:input-argument>
</data-mapper:input-arguments>
</data-mapper:transform>
<flow-ref name="upsertSalesforceContactFlow" doc:name="upsertSalesforceContactFlow"/>
</foreach>
</flow>
Update following Ryan's answer:
Changed the expression to return a payload of #[ent = new com.magento.api.CustomerCustomerEntity(); ent.setEmail('test#test.com'); return [ent];] - note, changed the method to setEmail to match the documentation here. The error I get with this is:
ERROR 2015-06-22 09:58:34,719 [main] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Object "org.mule.transport.NullPayload" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException). Message payload is of type: NullPayload
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Object "org.mule.transport.NullPayload" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException)
org.mule.util.collection.EventToMessageSequenceSplittingStrategy:64 (null)
2. Object "org.mule.transport.NullPayload" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}" (java.lang.IllegalArgumentException). Message payload is of type: NullPayload (org.mule.api.MessagingException)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.IllegalArgumentException: Object "org.mule.transport.NullPayload" not of correct type. It must be of type "{interface java.lang.Iterable,interface java.util.Iterator,interface org.mule.routing.MessageSequence,interface java.util.Collection}"
at org.mule.util.collection.EventToMessageSequenceSplittingStrategy.split(EventToMessageSequenceSplittingStrategy.java:64)
at org.mule.util.collection.EventToMessageSequenceSplittingStrategy.split(EventToMessageSequenceSplittingStrategy.java:25)
at org.mule.routing.CollectionSplitter.splitMessageIntoSequence(CollectionSplitter.java:29)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
One way is to build up the object yourself using the constructor or properties/setters.
From the docs:
http://mulesoft.github.io/magento-connector/2.1.2/java/com/magento/api/CustomerCustomerEntity.html
<mock:then-return payload-ref="#[ent = new com.magento.api.CustomerCustomerEntity(); ent.email('test#test.com'); return ent;]"/>
You can also create these objects aS reusable spring beans and reference them from MEL.
<bean class="com.magento.api.CustomerCustomerEntity" id="myEntityWithEmail">
<property name="email" value="test#test.com" />
</bean>
<mock:then-return payload-ref="#[app.registry.myEntityWithEmail]"/>
After your update I can see that you sre using a foreach which expects a collection or iterable. YOu can return a collection of you custom object simply in MEL using: [] for example:
#[ent = new com.magento.api.CustomerCustomerEntity(); ent.email('test#test.com'); return [ent];]
More on MEL here: https://developer.mulesoft.com/docs/display/current/Mule+Expression+Language+MEL
Or again you can use Spring to return a list:
<util:list id="entities">
<ref bean="myEntityWithEmail" />
</util:list>