I have an engine set up that validates an xml at a given endpoint.
localhost/rules/my-rule, if the xml file is consistent it returns the xml content. If not however, an exception is thrown:
GeneralException: Combination missmatch
Which is an exception I declared. It's a normal Java Exception.
When I post a faulty file with a tool like postman I get this result:
Can't invoke perform method on "class %rule class%" with request data of
"%data sent to endpoint%"
(reason: ch.package.GeneralException: Combination missmatch). Combination missmatch
Which would be perfect. However upon sending it with mule I get:
Route 0: Caught exception in Exception Strategy: HTTP POST on resource 'http://localhost/rules/my-rule/executions' failed: bad request (400).
Why can't I just get the error message? There isn't more insight when looking at the log:
org.mule.runtime.core.internal.message.ErrorBuilder$ErrorImplementation
{ description=HTTP POST on resource
'http://localhost/rules/my-rule/executions'
failed: bad request (400). detailedDescription=HTTP POST on resource
'http://localhost/rules/my-rule/executions'
failed: bad request (400). errorType=HTTP:BAD_REQUEST
cause=org.mule.extension.http.api.request.validator.ResponseValidatorTypedException
errorMessage=
org.mule.runtime.core.internal.message.DefaultMessageBuilder$MessageImplementation
{
payload=org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider#3239ebf7
mediaType=text/plain; charset=UTF-8
attributes=org.mule.extension.http.api.HttpResponseAttributes {
Status Code=400 Reason Phrase= Headers=[
content-type=text/plain
transfer-encoding=chunked
date=Wed, 03 Jul 2019 07:16:19 GMT
connection=close ] } attributesMediaType=/ } childErrors=[] }] }
My flow configutation:
<scatter-gather doc:name="Distribute workload" doc:id="15151949-c61d-4629-9fd4-0a4e16d62eec" >
<route >
<!--Access to localhost/rules/my-rule>
<flow-ref doc:name="CategoryToType" doc:id="e5d39afa-3b2a-45ef-81c0-afce77a76aef" name="validateCategoryToType" />
</route>
</scatter-gather>
<error-handler>
<on-error-propagate enableNotifications="true" logException="true" doc:name="On Error Propagate" doc:id="16001c58-7609-42a6-9bfa-1cd756998f27" >
<logger level="INFO" doc:name="Logger" doc:id="8ec2af18-3e45-4d15-a373-5e9af74723d7" message='#[error]'/>
</on-error-propagate>
</error-handler>
<sub-flow name="validateCategoryToType" doc:id="da38db3a-7d51-4fd1-bd06-9e58b872d468" >
<foreach doc:name="For Each" doc:id="ff9944ba-5f87-4a5a-9392-a4b27c2f5fb0" collection="payload.Kunden" rootMessageVariableName="Kunden">
<ee:transform doc:name="Transform Message" doc:id="f33fa5ea-0b4d-4ac5-a247-90fd6978248d">
<ee:message>
<ee:set-payload>
<!--Some transformy stuff-->
</ee:set-payload>
</ee:message>
</ee:transform>
<http:request method="POST" doc:name="Request" doc:id="53df928a-4fd1-4125-88e0-be73b006beee" config-ref="HTTP_Request_configuration" path="/rules/my-rule/execution>
<http:headers><![CDATA[#[output application/java
---
{
"Content-Type" : "application/xml",
"Accept" : "application/xml"
}]]]></http:headers>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="cc02312e-b71b-461c-bba0-077bfb1e9b7e" message="#[payload]" />
</foreach>
</sub-flow>
Use Global error handler, i have composed HTTP error request for you. You can expand it to other error types like API tool kit etc..
Also, extend further error messages by creating variables and capture postman payload into a variable
<on-error-propagate type="HTTP:BAD_REQUEST"
enableNotifications="true" logException="true" doc:name="On Error Propagate"
doc:id="73b29eaf-ebcd-4857-baea-4c2fb963b055">
<set-variable value="#[400]" doc:name="HTTP Status - 400"
doc:id="4017a80c-f968-4f09-8fbb-eaa4ce5d1413" variableName="httpStatus" />
<set-variable
value="Service is unable to handle request"
doc:name="errorMessage" doc:id="9ab2b50b-7aad-4460-b276-f5d50ffd1efe"
variableName="errorMessage" />
<ee:transform doc:name="Transform Message" doc:id="df98f927-584c-454e-971e-79d2ff1e842d" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
error: {
errorCode: error.errorType.identifier,
errorDateTime: now() as String { format: "yyyy-MM-dd'T'HH:mm:ss" },
errorDescription: error.description
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<ee:transform doc:name="Transform Message" doc:id="6e6c0017-2b23-4bfa-83ef-2f77cc25aa08" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload]]></ee:set-payload>
</ee:message>
</ee:transform>
</on-error-propagate>
Related
We have a Mule Service running on a server. I am developing a stand alone Mule Client that connects directly into the Mule service.
When I run the client, I am receiving the below error:
ERROR 2015-09-23 10:36:02,724 [[cheetah-web-services].connector.http.mule.default.receiver.03] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Failed to transform from "byte[]" to "Object"
Type : org.mule.api.transformer.TransformerException
Code : MULE_ERROR-109
JavaDoc : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html
Transformer : ByteArrayToMuleMessage{this=1574dd9, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=org.mule.api.MuleMessage, mimeType='*/*'}, sourceTypes=[SimpleDataType{type=[B, mimeType='*/*'}, SimpleDataType{type=java.io.InputStream, mimeType='*/*'}]}
********************************************************************************
Exception stack is:
1. com.mycompany.myapp.service.model.ServiceSearch; class invalid for deserialization (java.io.InvalidClassException)
java.io.ObjectStreamClass$ExceptionInfo:150 (null)
2. java.io.InvalidClassException: com.mycompany.myapp.service.model.ServiceSearch; class invalid for deserialization (org.apache.commons.lang.SerializationException)
org.mule.util.SerializationUtils:85 (null)
3. Failed to transform from "byte[]" to "Object" (org.mule.api.transformer.TransformerException)
org.mule.transformer.simple.ByteArrayToSerializable:54 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
********************************************************************************
Root Exception stack trace:
java.io.InvalidClassException: com.mycompany.myapp.service.model.ServiceSearch; class invalid for deserialization
I have setup a remote dispatcher agent on the server.
<client:remote-dispatcher-agent>
<client:remote-endpoint address="http://localhost:20809" exchange-pattern="request-response" responseTimeout="10000"/>
I have created a separate mule client.
<client:remote-dispatcher-agent>
<client:remote-endpoint ref="remoteDispatcherChannel" />
<client:xml-wire-format/>
</client:remote-dispatcher-agent>
<http:endpoint name="remoteDispatcherChannel"
host="localhost"
port="20809"
path="_remoting"
exchange-pattern="request-response" />
Below is the Client Code. The ServiceSearch object implements all Serializable.
MuleClient muleClient = new MuleClient(true);
RemoteDispatcher dispatcher2 = muleClient.getRemoteDispatcher("http://127.0.0.1:20809/_remoting");
MuleMessage result = dispatcher2.sendToRemoteComponent("myAppServiceDelegate", ServiceSearch, msgMap);
Below is the Mule Service flow on the server I am trying to get into. I am coming in on the invoker step. I choice this step as I could sent the object directly to the service in the required format
<flow name="post:/service/search:my-web-services-config" initialState="started">
<logger level="INFO" doc:name="Log Request Properties" message="Request Type: #[message.inboundProperties.'http.method'], Request Path: #[message.inboundProperties.'http.request.path'], Request Params: #[message.inboundProperties.'http.query.params']" />
<json:json-to-object-transformer returnClass="com.mycompany.myapp.service.model.ServiceSearch" ignoreBadInput="true" mimeType="application/json" doc:name="Request JSON to ServiceSearch" />
<invoke object-ref="myappServiceDelegate" method="processSearch" methodArguments="#[payload],#[flowVars.'CLIENT_ID']" doc:name="Calling Search Delegate" />
<logger message="Generated DSL: #[payload.queryDSL]" level="INFO" doc:name="Log Query DSL" />
<flow-ref name="BigDataSearchFlow" doc:name="Big Data Flow" />
<exception-strategy ref="globalResponseExceptionStrategy" doc:name="Reference Exception Strategy" />
</flow>
I would appreciate some feedback on this approach and suggestions on what I should look for in the ServiceSearch object.
Russ
You are using an order/newer version of com.mycompany.myapp.service.model.ServiceSearch or none at all at the server side.
Please make sure both ends do have the very same version of the file.
I have a requirement where i need to poll a rest service and then proxy the response from this web service on to a REST web service.
I am using Mule 3.5 and my flow looks like the below.
I get the below exception where the REST service is being invoked
********************************************************************************
Message : Failed to invoke JerseyResourcesComponent{TestFlow.component.1106552446}. Component that caused exception is: JerseyResourcesComponent{TestFlow.component.1106552446}. Message payload is of type: String
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. null (java.lang.NullPointerException)
org.mule.module.jersey.JerseyResourcesComponent:192 (null)
2. Failed to invoke JerseyResourcesComponent{TestFlow.component.1106552446}. Component that caused exception is: JerseyResourcesComponent{TestFlow.component.1106552446}. Message payload is of type: String (org.mule.component.ComponentException)
org.mule.component.AbstractComponent:144 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
java.lang.NullPointerException
at org.mule.module.jersey.JerseyResourcesComponent.getBaseUri(JerseyResourcesComponent.java:192)
at org.mule.module.jersey.JerseyResourcesComponent.doInvoke(JerseyResourcesComponent.java:146)
at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:122)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
After debugging i figured out it is because Mule expects the MuleMessage inbound property for contextPath to be populated however in this case it is null.
In JerseyResourcesComponent line 117 is returned as null and hence line 195 throws a NPE.
I wanted to know if this kind of requirement/pattern is invalid or is it some kind of limitation in the way Mule is handling its messaging infrastructure ?
The flow xml just in case you want to inspect it.
<flow name="TestFlow" doc:name="TestFlow">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="10" timeUnit="SECONDS" startDelay="10"/>
<http:outbound-endpoint exchange-pattern="request-response" host="localhost" port="8080" doc:name="Order Generator" method="GET" contentType="application/json" path="order"/>
</poll>
<object-to-string-transformer doc:name="Object to String"/>
<jersey:resources doc:name="Tax Calculator">
<component class="org.nthdimenzion.TaxCalculator"/>
</jersey:resources>
<logger level="INFO" doc:name="Logger"/>
</flow>
PS : The work around i got was to use a java/spring component instead of a REST WS and then call the REST WS from the Java component.
I am new to Mule, I want to validate the timestamp and nonce parameter from URI for preventing the replay attack. I use choice-when router, when the timestamp and nonce is valid(the validation process is complex), forward the request to backend rest service, otherwise return error code and message. I found a lot of MEL usage for choice-when, but can I define a custom expression use java? and there is a example available?
URI example:
http://muledemo.org/ci2/ni/del?id=0xe413×tamp=1376022133&nonce=a03ed9c
code snippets:
<choice doc:name="Choice">
<when expression="???how to call a java validator???">
</when>
<otherwise>
<processor-chain doc:name="Processor Chain">
<echo-component doc:name="Echo" />
<http:outbound-endpoint exchange-pattern="request-response" method="POST"
address="http://localhost:8081#[message.inboundProperties['http.request']]" doc:name="HTTP" />
</processor-chain>
</otherwise>
</choice>
EDIT:
XML config:
<spring:beans>
<spring:bean id="replayAttackCheck" class="org.jamee.demo.mule.ReplayAttackCheck"/>
</spring:beans>
... ...
<when expression="#[replayAttackCheck.validate(payload)]">
<expression-component doc:name="Check Required Params"><![CDATA[payload="{\"code\":\"PA002\", \"message\":\"timestamp or nonce is illegal\"}"]]>
</expression-component>
</when>
Error log:
ERROR 2013-08-09 14:32:39,090 [[demo.router].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Execution of the expression "replayAttackCheck.validate(payload)" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: HashMap
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. [Error: unresolvable property or identifier: replayAttackCheck]
[Near : {... replayAttackCheck.validate(pay ....}]
Correct MEL syntax:
<when expression="#[app.registry.replayAttackCheck.validate(payload)]">
You just use the fully qualified path
#[com.mulesoft.foo(payload, someFooVar)]
Alternatively you can define it globally for your app in your configuration and the use the "foo" function in your MEL expressions
<configuration doc:name="Config">
<expression-language autoResolveVariables="false">
<global-functions>
def foo(fooVar){
return com.mulesoft.foo(payload, fooVar);
}
</global-functions>
</expression-language>
</configuration>
I am addressing a fail-safe scenario as below.
But in the recoveryflow I am not able to get the exception or exceptionPayload that occurred due to the failure of the subflow1 or subflow2.
Is there any way I can get the exception thrown by the unsuccessful message processors in the First-sucessful routing processor.
I have looked into the Mule FirstSuccessful class code. From the loop in it, I can see the exception is caught but not saved.
Is there a way I can extend and have my own first-successful which can provide me the exception as well?
<flow name="main_flow" >
....
....
<first-successful>
<flow-ref name="subflow_1" />
<flow-ref name="recoveryFlow1" />
</first-successful>
....
....
<first-successful>
<flow-ref name="subflow_2" />
<flow-ref name="recoveryFlow2" />
</first-successful>
....
....
</flow>
<sub-flow name="subflow_1">
....
....
<out-bound call to web-service />
....
....
</sub-flow>
<sub-flow name="subflow_2">
....
....
<out-bound call to web-service />
....
....
</sub-flow>
<sub-flow name="revoceryFlow1" >
<process communication based on the exception thrown by previous unsuccessful sub-flow 1>
<some more processing so that the remaining main flow is not impacted because of the failue of the subflow 1 >
</sub-flow>
<sub-flow name="revoceryFlow2" >
<process communication based on the exception thrown by previous unsuccessful sub-flow 2>
<some more processing so that the remaining main flow is not impacted because of the failue of the subflow 2 >
</sub-flow>
Please advise if I am going in wrong direction. Is there any better approach than mine?
I got the solution.
There is not straight solution from the Mule.
I have overwriten the FirstSuccessful behaviour and added properties with the exception details. These properties are then accessed in the next message processors inside the first-successful.
catch (Exception ex)
{
event.getMessage().setProperty("prevError", ex.getMessage() , PropertyScope.INVOCATION);
event.getMessage().setProperty("prevErrorClass", ex.getClass() , PropertyScope.INVOCATION);
failed = true;
}
while implementing a SSL-secured WebService with Apache CXF v2.7.3 I wanted to test how a custom exception class (e.g. MyException) is handled by the client.
Therefore I have the following server-side method:
#WebMethod
public void foo() throws MyException {
throw new MyException("test!");
}
I have also configured to log in- and outgoing messages in the cxf.xml via:
<bean id="logInbound" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
<bean id="logOutbound" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
<jaxws:inInterceptors>
<ref bean="logInbound"/>
</jaxws:inInterceptors>
<jaxws:outInterceptors>
<ref bean="logOutbound"/>
</jaxws:outInterceptors>
Calling this function with a client results in following console-output
INFO: Inbound Message
----------------------------
ID: 1
Address: https://localhost:8443/WebApp/services/ClientService
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml; charset=UTF-8
Headers: {Accept=[*/*], cache-control=[no-cache], connection=[keep-alive], Content-Length=[184], content-type=[text/xml; charset=UTF-8], host=[localhost:8443], pragma=[no-cache], SOAPAction=[""], user-agent=[Apache CXF 2.7.3]}
Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:foo xmlns:ns2="http://services.client.test.cloud.org/"/></soap:Body></soap:Envelope>
--------------------------------------
18.02.2013 22:49:02 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
INFO: Application {http://services.client.test.cloud.org/}ClientService#{http://services.client.test.cloud.org/}foo has thrown exception, unwinding now: org.cloud.test.client.exception.MyException: test!
18.02.2013 22:49:02 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
INFO: Application {http://services.client.test.cloud.org/}ClientService#{http://services.client.test.cloud.org/}foo has thrown exception, unwinding now: java.lang.NullPointerException: null
The client gets a "Error reading XMLStreamReader." due to a "Unexpected EOF". I guess, that no response is written by the server. Do you know why 2 exceptions are thrown and why there isn't any response to the client?
I already searched for exceptions not redirected to the client in Apache CXF-applications, but could not find any solution.
Thanks in advance!