I have created a flow to compress a file from the Mule end, but I got an error:
java.lang.IllegalStateException: There are at least 2 connectors matching protocol "file", so the connector to use must be specified on the endpoint using the 'connector' property/attribute. Connectors in your configuration that support "file" are: input, output,
This is the flow:
<flow name="GZipCompress" doc:name="GZipCompress">
<file:inbound-endpoint path="C:backuptest" responseTimeout="10000" doc:name="File">
<file:filename-regex-filter pattern="abc.doc" caseSensitive="false" />
</file:inbound-endpoint> <string-to-byte-array-transformer doc:name="String to Byte Array" />
<logger message="Payload size before compression : #[Integer.parseInt(payload.size())/1024] KB" level="INFO" doc:name="Logger" />
<!-- If you send gzip a String then it gets serialized and mess ends up in the gzip file. To avoid this convert to byte[] first -->
<gzip-compress-transformer /> <logger message="Payload size after compression : #[Integer.parseInt(payload.size())/1024] KB" level="INFO" doc:name="Logger" />
<file:outbound-endpoint path="C:backuptestnewfolder" responseTimeout="10000" doc:name="File" /> </flow>
There are at least 2 connectors matching protocol "file", so the connector to use must be specified on the endpoint using the 'connector' property/attribute. Connectors in your configuration that support "file" are: input, output,
This error is stating that you've defined you file global connectors and now mule doesn't know which one to attach your stated file endpoint to. One solution is to define connector-ref property in your file inbound endpoint and refer to input connector you've defined.
<file:inbound-endpoint connector-ref="input" path="C:backuptest" responseTimeout="10000" doc:name="File"/>
Related
I'm using Apache Camel. Using XML DSL, I mean something like
<rests id="rests" xmlns="http://camel.apache.org/schema/spring">
<rest id="rest-custom">
<get uri="my_method" method="">
<description>...</description>
<param name="..." ... />
<route>
<process ref="..." />
<to uri="..." />
</route>
</get>
<post uri="another_method" method="" >
<description>...</description>
<param name="..." .../>
<route>
<process ref="..." />
<to uri="..." />
</route>
</post>
...
So if I want new route, I will just add new <get> or <post> and it works fine.
But now I want to add some DEFAULT method. I mean, something like <get uri="*"> and <post uri="*"> in the bottom of all configuration. So if my url doesn't match any from list - it goes to default one and I can handle it with custom processor (this is the behaviour I want).
For now I don't know, how to do it. Tried to handle 404 responses, but still no success. Looks like solution should be simple, but can't find it yet.
I see only one possible use case for such a default: if you got multiple URLs for the same functionality.
If this is the case and your clients don't want or can't switch to a single URL, you could still use URL rewriting on the incoming request before it reaches your Camel application.
If you want to "catch" all unknown URLs (errors), I guess you should use standard Camel error handling (see Error Handler and Exception clause) because these REST DSL blocks are internally converted to standard Camel routes.
Finally found the solution.
<get uri="/?matchOnUriPrefix=true&bridgeEndpoint=true" method="">
<description>Default GET method</description>
<route>
...
</route>
</get>
Parameters matchOnUriPrefix=true&bridgeEndpoint=true did the trick.
This is the mule config file for a service of a class , that basically reads order file and processes it. Sometime the code is confused and it processes two or more file and getting freezed. I want the code to read only one file at a time.
<quartz-connector name = "oneThreadQuartzConnector">
<quartz:factory-property key ="org.quartz.threadpool.threadcount" value="1"/>
</quartz-connector>
<service name="Retail Transfer Request Service">
<inbound>
<file:inbound-endpoint path="#{es.dir.008}" moveToDirectory="#{es.dir.008}/archive/ORD">
<file:filename-wildcard-filter pattern="OR*" />
</file:inbound-endpoint>
</inbound>
<component>
<spring-object bean="retailTransferRequestAction" />
</component>
<default-service-exception-strategy>
<vm:outbound-endpoint path="found.error.queue" />
</default-service-exception-strategy>
</service>
The quartz will pick data one by one if you want to make a synchronous call the best option is to choose processing strategy in the flow and make it synchronous
<flow name="sampleFlow" processingStrategy="synchronous">
I am using JSON file to show the schema and have give this config:
<flow name="api-schema" doc:name="api-schema">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="8080" path="schema" doc:name="HTTP"/>
<logger level="INFO" doc:name="Logger"/>
<http:static-resource-handler resourceBase="${app.home}/src/main/resources/" defaultFile="schema" doc:name="HTTP Static Resource Handler"/>
</flow>
But when I am running it, its always asking to download the file. I have tried in Chrome and Safari both. How can I instruct mule to display content on browser and don't download?
The way the browser determines what to do with a resource is by looking at the Content-Type header. You can set the header by creating an outbound property with the name "Content-Type" and the value "application/json" like so:
<set-property propertyName="Content-Type" value="application/json" />
Since the static-resource-handler is now deprecated, you could switch to the parse-template processor:
<parse-template location="#[message.inboundProperties['http.listener.path']]" />
Set "Content-Type" header to "application/json" then response will be in json format.
Similar to this discussion Maintain Payload State during mule flow execution
I would like to know how to maintain an entire Mule Message throughout my flow.
I am trying to call a jersey resource component after I have received information that the user is authorized to call it. In this authorization request the payload and original http request gets altered.
My predicament is that I don't want to call the resource first as that would be inefficient and insecure however I cannot see any other plausible way to do this.
<flow name="test">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="1234" path="test" doc:name="HTTP"/>
<!-- sub-flow here which changes the MuleMessage and loses all original inbound properties -->
<jersey:resources doc:name="REST">
<component class="com.Test" />
</jersey:resources>
</flow>
Thanks for any help in advance
Mule 3 includes two scopes that will allow you to preserve the original message, while executing other message processors:
If you must wait for the sub-flow to complete because you need to use information produced by the sub-flow, use a message enricher like so. This example assigns the variable "authorized" to whatever the payload is once the sub-flow finishes processing the message.
<enricher target="#[variable:authorized]">
<flow-ref name="checkAuthorization" />
</enricher>
If you do not need to wait for the sub-flow to complete before allowing your Jersey Resource to run, use the async scope like so:
<async>
<flow-ref name="goForthAndDoSomething" />
</async>
There are multiple ways to save a mule message and it's properties so that it could be retrieve when required .. In your case you could save the entire Mule message in a variable and retrieve it when required for example :
<flow name="test">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="1234" path="test" doc:name="HTTP"/>
<!-- You save your entire message in a session variable named entireMessage before calling a subflow-->
<set-session-variable variableName="entireMessage" value="#[message.payload]" />
<!-- You can now call your Sub flow -->
<jersey:resources doc:name="REST">
<component class="com.Test" />
</jersey:resources>
</flow>
Here in the above flow you store your Mule message in a session variable named entireMessage .. You can easily retrieve the value of this session variable whenever you need in any flow anywhere like the following :-
<logger level="INFO" message="#[sessionVars['entireMessage']]"/>
This will print you Mule message
There is also an alternative way to store the http headers before it get altered ..
you can also use the following :-
<flow name="test">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="1234" path="test" doc:name="HTTP"/>
<!-- You copy all the HTTP headers before calling a subflow-->
<copy-properties propertyName="http.*" doc:name="Copy All HTTP Headers"/>
<!-- You can now call your Sub flow -->
<jersey:resources doc:name="REST">
<component class="com.Test" />
</jersey:resources>
</flow>
The above flow will copy all the HTTP headers before calling any other flow
UPDATED FLOW :-
If you need the original unaltered payload for your Jersy component , please overwrite the current payload with the original payload stored in session variable using set payload component
<flow name="test">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="1234" path="test" doc:name="HTTP"/>
<!-- You save your entire message in a session variable named entireMessage before calling a subflow-->
<set-session-variable variableName="entireMessage" value="#[message.payload]" />
<!-- You can now call your Sub flow -->
<!-- overwrite current payload with original unaltered payload -->
<set-payload value="#[sessionVars['entireMessage']]" doc:name="Set Payload"/>
<jersey:resources doc:name="REST">
<component class="com.Test" />
</jersey:resources>
</flow>
Try somthing like this to store the original message in session:
<message-properties-transformer scope="session" doc:name="Save original message">
<add-message-property key="originalMessage" value="#[message:payload]"></add-message-property>
</message-properties-transformer>
Then try something like this to get it from session:
<expression-transformer evaluator="..." expression="SESSION:originalMessage" doc:name="Restore original message"></expression-transformer>
Thanks for all your help. The final solution answer was:
<flow name="test">
<http:inbound-endpoint exchange-pattern="request-response" host="0.0.0.0" port="1234" path="test" doc:name="HTTP"/>
<enricher target="#[variable:unwantedPayload]" source="#[payload]">
<flow-ref name="anotherFlowCalled" />
</enricher>
<jersey:resources doc:name="REST">
<component class="com.Test" />
</jersey:resources>
</flow>
best way to store the mule message into session , whether you flow contains subflows are private flow session vars carry till end of the execeution.
I'm new to Spring Integration and Spring Integration AMQP.
I have the following code:
<bean id="enricher" class="soft.Enricher"/>
<amqp:inbound-channel-adapter queue-names="QUEUE1" channel="amqpInboundChannel"/>
<int:channel id="amqpInboundChannel">
<int:interceptors>
<int:wire-tap channel="logger"/>
</int:interceptors>
</int:channel>
<int:header-enricher input-channel="amqpInboundChannel" output-channel="routingChannel">
<int:header name="store" value="sj" />
</int:header-enricher>
<int:channel id="routingChannel" />
<int:header-value-router input-channel="routingChannel" header-name="store">
<int:mapping value="sj" channel="channelSJ" />
<int:mapping value="jy" channel="channelJY" />
</int:header-value-router>
<amqp:outbound-channel-adapter channel="channelSJ" exchange-name="ex_store" routing-key="sj" amqp-template="rabbitTemplate"/>
<amqp:outbound-channel-adapter channel="channelJY" exchange-name="ex_store" routing-key="jy" amqp-template="rabbitTemplate"/>
<int:channel id="channelSJ" />
<int:channel id="channelJY" />
<int:logging-channel-adapter id="logger" level="ERROR" />
The setup is the following:
Everything is working fine except that headers are lost when a message is picked up by the inbound-channel-adapter.
Likewise the header being enriched called "store" is also lost when the message is being send to the exchange using the outbound-channel-adapter.
This is how a message is looking before being picked up by the inbound-channel-adapter:
This is how the same message is looking after the whole process (notice no headers)
I think your problem is described here:
"By default only standard AMQP properties (e.g. contentType) will be copied to and from Spring Integration MessageHeaders. Any user-defined headers within the AMQP MessageProperties will NOT be copied to or from an AMQP Message unless explicitly identified via 'requestHeaderNames' and/or 'replyHeaderNames' properties of this HeaderMapper. If you need to copy all user-defined headers simply use wild-card character ''.*"
So you need to define your own custom instance of DefaultAmqpHeaderMapper and configure the inbound-channel-adapter with it. See here.
It might look something like this:
<bean id="myHeaderMapper" class="org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper">
<property name="requestHeaderNames" value="*"/>
<property name="replyHeaderNames" value="*"/>
</bean>
<amqp:inbound-channel-adapter queue-names="QUEUE1" channel="amqpInboundChannel"
header-mapper="myHeaderMapper"/>