I need to call a flow (server) from another flow (client) in two different applications.
I'd prefer not to create a jar of the server and include it in the client as explained in:
http://www.mulesoft.org/documentation/display/current/Sharing+Custom+Configuration+Fragments
I try to do that using vm inbound / outbound components but it doesn't work, here you are the configurations file.
For the client flow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
<quartz:connector name="quartzConnector_vm" validateConnections="true" doc:name="Quartz">
<quartz:factory-property key="org.quartz.scheduler.instanceName" value="MuleSchedulerClient1"/>
<quartz:factory-property key="org.quartz.threadPool.class" value="org.quartz.simpl.SimpleThreadPool"/>
<quartz:factory-property key="org.quartz.threadPool.threadCount" value="3"/>
<quartz:factory-property key="org.quartz.scheduler.rmi.proxy" value="false"/>
<quartz:factory-property key="org.quartz.scheduler.rmi.export" value="false"/>
<quartz:factory-property key="org.quartz.jobStore.class" value="org.quartz.simpl.RAMJobStore"/>
</quartz:connector>
<flow name="scheduleFlow2" doc:name="scheduleFlow2">
<quartz:inbound-endpoint jobName="myQuartzJobName2" repeatInterval="7000" responseTimeout="10000" doc:name="Quartz">
<quartz:event-generator-job groupName="DEFAULT" jobGroupName="DEFAULT">
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<expression-component doc:name="Expression"><![CDATA[payload="test";]]></expression-component>
<vm:outbound-endpoint exchange-pattern="request-response" path="dispatchSingleConfiguration" doc:name="VM">
<vm:transaction action="NONE"/>
</vm:outbound-endpoint>
</flow>
The server flow is simply something like this:
<flow name="prepareInputData" doc:name="prepareInputData">
<vm:inbound-endpoint exchange-pattern="request-response" path="dispatchSingleConfiguration" doc:name="VM">
<vm:transaction action="NONE"/>
</vm:inbound-endpoint>
<set-variable variableName="nomeFileProperties" value="#[payload]" doc:name="Variable"/>
</flow>
Is it possible to set properly the path in the vm endpoints to let inbound/outbound VM communication?
I could use an http call, but I think that VM call is a cleaner solution.
Am I wrong? Thank you
VM is currently (Mule 3.4) only for calls within the same application: to perform remote calls, the easiest is to use HTTP.
Related
I am trying to use Basic authentication and get the credentials in Mule flows.
Here is my Mule flows:
<http:listener config-ref="httpConfig" path="/*" doc:name="HTTP" allowedMethods="get, post, delete" />
<apikit:router config-ref="api-config" doc:name="APIkit Router" />
<flow name="get:/sourcing/helloworld-secure:api-config">
<flow-ref name="authenticate-ldap" doc:name="authenticate-ldap"/>
</flow>
<flow name="authenticate-ldap">
<logger message="Name: #[message.inboundProperties.get('username')] Password:#[message.inboundProperties['password']] level="INFO"/>
<component class="com.test.AuthTest" doc:name="Java"/>
<logger message="After java: #[flowVars.username] #[flowVars.password]" level="INFO" doc:name="Logger"/>
<json:object-to-json-transformer doc:name="Object to JSON"/>
<data-mapper:transform config-ref="Map_auth_to_ldap_request" doc:name="Map auth to ldap request"/>
</flow>
Java code:
public class AuthTest implements Callable {
#Override
public Map<String, String> onCall(MuleEventContext eventContext) throws Exception {
Map<String, String> authMap = new HashMap<String, String>();
final String authorization = eventContext.getMessage().getInboundProperty("authorization");
if (authorization != null && authorization.startsWith("Basic")) {
String base64Credentials = authorization.substring("Basic".length()).trim();
String credentials = new String(Base64.decode(base64Credentials), Charset.forName(Base64.PREFERRED_ENCODING));
if (credentials != null) {
final String[] values = credentials.split(":",2);
eventContext.getMessage().setInvocationProperty("username", values[0]);
eventContext.getMessage().setInvocationProperty("password", values[1]);
authMap.put("username", values[0]);
authMap.put("password", values[1]);
}
}
return authMap;
}
}
To run this application, I am using rest client in Chrome and selecting Basic Auth, then giving username and password.
Above code is working fine. What I need is instead of getting credentials in Java then put into Map, I need to get the credentials in Mule flows without using Java code. Is this possible in Mule flows directly?
I have implemented with Spring security which is working fine, but in this case I need user to enter credentials and proceed further.
For implementing the basic-authentication you can use the "mule-ss:security-manager" element to provide the source of the authentication and the "http:basic-security-filter" element to establish the restriction. Finally you can get the the credentials in the flow by using the "expresion-transformer" element. Here you have an example:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:ftp="http://www.mulesoft.org/schema/mule/ftp"
xmlns:db="http://www.mulesoft.org/schema/mule/db"
xmlns:mule-xml="http://www.mulesoft.org/schema/mule/xml"
xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey"
xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:ws="http://www.mulesoft.org/schema/mule/ws"
xmlns:smtps="http://www.mulesoft.org/schema/mule/smtps"
xmlns:email="http://www.mulesoft.org/schema/mule/email"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:mule-ss="http://www.mulesoft.org/schema/mule/spring-security"
xmlns:ss="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ftp http://www.mulesoft.org/schema/mule/ftp/current/mule-ftp.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
http://www.mulesoft.org/schema/mule/smtps http://www.mulesoft.org/schema/mule/smtps/current/mule-smtps.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd
http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/3.1/mule-spring-security.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
">
<spring:beans>
<ss:authentication-manager alias="authenticationManager">
<ss:authentication-provider>
<ss:user-service id="userService">
<ss:user name="user" password="password" authorities="ROLE_ADMIN" />
<ss:user name="anon" password="anon" authorities="ROLE_ANON" />
</ss:user-service>
</ss:authentication-provider>
</ss:authentication-manager>
</spring:beans>
<mule-ss:security-manager>
<mule-ss:delegate-security-provider name="memory-provider" delegate-ref="authenticationManager" />
</mule-ss:security-manager>
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="9091" doc:name="HTTP Listener Configuration"/>
<flow name="testingFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/*" doc:name="HTTP"/>
<logger message="Before Authentication" level="INFO" doc:name="Log Failure"/>
<http:basic-security-filter realm="mule-realm"/>
<set-payload value="#[message.inboundProperties.'Authorization']"/>
<set-payload value="#[message.payloadAs(java.lang.String).substring('Basic'.length()).trim()]"/>
<expression-transformer expression="#[new String(org.mule.util.Base64.decode(payload),java.nio.charset.Charset.forName('UTF-8')).split(':');]" />
<set-payload value="#[['user':payload[0],'password':payload[1]]]"/>
<logger message="#[payload]" level="INFO" doc:name="User - Password"/>
</flow>
</mule>
Documentation reference:
https://docs.mulesoft.com/mule-user-guide/v/3.7/http-listener-connector#authentication
My below code perfectly send email as an attachment, but the problem is
1) payload is copying to the mail body. I want mail to be sent only as an attachment, don't want to include attachment in body part of the mail.
2) email triggers twice always. I have given thread count as 1. Not sure from where the second event is triggering.
Code:
<mule xmlns:email="http://www.mulesoft.org/schema/mule/email" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:context="http://www.springframework.org/schema/context" xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd">
<spring:beans>
<context:property-placeholder location="accord.properties"/>
<spring:bean id="transmission" class="com.creativeworld.service.InvokeTransmission"/>
</spring:beans>
<quartz:connector name="ABCQuartz" validateConnections="true" doc:name="ABC Quartz">
<quartz:factory-property key="org.quartz.scheduler.instanceName" value="ABC_XYZKReport"/>
<quartz:factory-property key="org.quartz.threadPool.class" value="org.quartz.simpl.SimpleThreadPool"/>
<quartz:factory-property key="org.quartz.threadPool.threadCount" value="1"/>
<quartz:factory-property key="org.quartz.scheduler.rmi.proxy" value="false"/>
<quartz:factory-property key="org.quartz.scheduler.rmi.export" value="false"/>
</quartz:connector>
<smtp:connector name="ABCSMTP" validateConnections="true" doc:name="SMTP" subject="ABC_XYZK Report"/>
<flow name="flow1" doc:name="flow1" processingStrategy="synchronous">
<quartz:inbound-endpoint jobName="ABCQuartz" repeatInterval="180000" responseTimeout="10000" connector-ref="ABCQuartz" doc:name="ABC XYZK">
<quartz:event-generator-job groupName="creativeworld" jobGroupName="creativeworld">
<quartz:payload>Creative World Quartz Scheduler.</quartz:payload>
</quartz:event-generator-job>
</quartz:inbound-endpoint>
<scripting:component doc:name="Python">
<scripting:script engine="jython" file="ABC_XYZK.py"/>
</scripting:component>
<set-session-variable variableName="outputfilepath" value="${OUTPUT_FILE}${FILE_NAME}-#[server.dateTime.format('${DATETIME_FORMAT}')]${FILE_TYPE}" doc:name="File Name" />
<set-payload value="${COMMAND_PATH}#[' ']${DB_NAME}${OUTPUT_FILE}${URL}" doc:name="Transmission Commands"/>
<set-payload value="#[message.payload]#[' -outputpath ']#[outputfilepath]" doc:name="Output Config"/>
<invoke object-ref="transmission" method="invoke" methodArgumentTypes="java.lang.String" methodArguments="#[payload]" name="transmissionAPI"/>
<vm:outbound-endpoint exchange-pattern="one-way" path="smtp" doc:name="VM"/>
</flow>
<flow name="smtp" doc:name="smtp" processingStrategy="synchronous">
<vm:inbound-endpoint exchange-pattern="one-way" path="smtp" doc:name="VM"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[new File(sessionVars['outputfilepath']).text]]></scripting:script>
</scripting:component>
<set-attachment attachmentName="${FILE_NAME}-#[server.dateTime.format('${DATETIME_FORMAT}')]${FILE_TYPE}" value="#[payload]" contentType="text/plain" doc:name="ABC_XYZK Report"/>
<smtp:outbound-endpoint host="mailrelay.ad.corp.local" responseTimeout="10000" doc:name="SMTP" connector-ref="ABCSMTP" mimeType="text/plain" from="mymailid#mycompany.com" subject="ABC_XYZK" to="mymailid#mycompany.com">
<!-- <email:email-to-string-transformer/> -->
</smtp:outbound-endpoint>
</flow>
Simple solution :- If you don't want the same payload in the mail body simply put <set-payload value="Hi this is the mail content " doc:name="Output Config"/> just after <set-attachment > tag with the content you like to have as mail body eg :-
<set-attachment attachmentName="${FILE_NAME}-#[server.dateTime.format('${DATETIME_FORMAT}')]${FILE_TYPE}" value="#[payload]" contentType="text/plain" doc:name="ABC_XYZK Report"/>
<set-payload value="Hi this is the mail content " doc:name="Output Config"/>
<smtp:outbound-endpoint host="mailrelay.ad.corp.local" responseTimeout="10000" doc:name="SMTP" connector-ref="ABCSMTP" mimeType="text/plain" from="mymailid#mycompany.com" subject="ABC_XYZK" to="mymailid#mycompany.com">
<!-- <email:email-to-string-transformer/> -->
</smtp:outbound-endpoint>
The payload you set after attachment will be in your mail body
I am playing with Google Task connector and ended up with following error
The content of element 'google-tasks:config-with-oauth' is not complete. One of '{"http://www.mulesoft.org/schema/mule/core":annotations, "http://www.mulesoft.org/schema/mule/google-tasks":oauth-callback-config}' is expected.
Here is my configuration
<google-tasks:config-with-oauth name="Google_Tasks"
consumerKey="sagitec.mygbiz.com"
consumerSecret="oeX9wb_GhldQJYjHKLDqC-EB" doc:name="Google Tasks"/>
<flow name="google_taskFlow1" doc:name="google_taskFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<google-tasks:authorize config-ref="Google_Tasks" accessTokenUrl="https://accounts.google.com/o/oauth2/token"
authorizationUrl="https://accounts.google.com/o/oauth2/auth"
access_type="online" force_prompt="auto" doc:name="Google Tasks"/>
<logger level="INFO" doc:name="Logger" message="#[payload]"/> </flow>
If i enter "localhost" in Domain (which is specified as optional) under Oauth tab for google-tasks:config-with-oauth, i am not getting any build error.
So my first question is, what value i have to enter under Domain and where i can get it from.
2) What is the difference between Consumer Key/Secret and ClientKey/secret.
3) in one of the sample, i saw ${google.apiKey}. What is this and if this is a variable, wgere and how to declare it.
It will be really nice if any sample provided.
Thanks in advance,
Kannan
here i added sample example for google calender authentication using google connector
your
client id >>consumerKey
client secret >> consumerSecret
${google.apiKey} >> your global google calendar config name i.e. name="Google_Calendars" in below flow
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data- mapper" xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"
xmlns:objectstore="http://www.mulesoft.org/schema/mule/objectstore"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:google-calendars="http://www.mulesoft.org/schema/mule/google-calendars"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.5.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/google-calendars http://www.mulesoft.org/schema/mule/google-calendars/1.0/mule-google-calendars.xsd
http://www.mulesoft.org/schema/mule/objectstore http://www.mulesoft.org/schema/mule/objectstore/1.0/mule-objectstore.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd">
<google-calendars:config-with-oauth
name="Google_Calendars"
consumerKey="${consumer-key}"
consumerSecret="${consumer-secret}" doc:name="Google Calendars"
applicationName="test">
<google-calendars:oauth-callback-config
domain="localhost" localPort="8083" path="list"
remotePort="8083" />
<google-calendars:oauth-store-config objectStore-ref="ObjectStoreBean" />
</google-calendars:config-with-oauth>
<spring:beans>
<spring:bean id="ObjectStoreBean" name="ObjectStoreBean"
class="org.mule.util.store.SimpleMemoryObjectStore" />
</spring:beans>
<flow name="authorizationAndAuthenticationFlow" doc:name="authorizationAndAuthenticationFlow">
<http:inbound-endpoint host="localhost" port="8080"
path="oauth-authorize" doc:name="HTTP" />
<google-calendars:authorize config-ref="Google_Calendars"
doc:name="Google Calendars" />
<http:response-builder status="200"
doc:name="HTTP Response Builder">
<set-payload value="You have successfully authorized the connector" />
</http:response-builder>
<catch-exception-strategy doc:name="Catch Exception Strategy">
<http:response-builder status="404"
doc:name="HTTP Response Builder">
<set-payload value="An error has occurred authorizing the connector" />
</http:response-builder>
</catch-exception-strategy>
</flow>
</mule>
I published a web service in mule 3.3.0 CE with cxf proxy-service.
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"
xmlns:cxf-core="http://cxf.apache.org/core" xmlns:mule-xml="http://www.mulesoft.org/schema/mule/xml"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:mule-ss="http://www.mulesoft.org/schema/mule/spring-security"
xmlns:ss="http://www.springframework.org/schema/security" xmlns:test="http://www.mulesoft.org/schema/mule/test"
xsi:schemaLocation=" http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/3.3/mule-spring-security.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/current/mule-test.xsd "
version="CE-3.3.0">
<flow name="wbs" doc:name="wbs">
<http:inbound-endpoint host="localhost" port="9094"
path="myPath/app" exchange-pattern="request-response" doc:name="HTTP">
</http:inbound-endpoint>
<cxf:proxy-service doc:name="wbsrv" service="AppWSService"
wsdlLocation="schema/wsdl/App/WSService.wsdl" namespace="http://wbservice.com/"
payload="body"></cxf:proxy-service>
<copy-properties propertyName="SOAPAction" doc:name="Property" />
<cxf:proxy-client doc:name="wbsrv" />
<http:outbound-endpoint address="http://websrv.mydns.com:8080/App/WSService"
doc:name="HTTP" encoding="UTF-8" responseTimeout="1000000"
exchange-pattern="request-response">
</http:outbound-endpoint>
</flow>
Ip of my mule server is : 192.168.0.59. I can see outbound address (http://websrv.mydns.com:8080/App/WSService) just by that Ip (192.168.0.59).
after runnig web service I can see my wsdl that I publish it with cxf proxy but when I checked it with SoapUI, I can't receive response. I have below error in SoapUI xml:
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Failed to route event via endpoint: DefaultOutboundEndpoint{endpointUri=http://websrv.mydns.com:8080/App/WSService, connector=HttpConnector
{ name=httpConnector lifecycle=start this=16a2c7b
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true connected=true
supportedProtocols=[http] serviceOverrides=
session.handler=org.mule.session.NullSessionHandler } , name='endpoint.http.websrv.mydns.com.8080.App.WSService',
mep=REQUEST_RESPONSE, properties={},
transactionConfig=Transaction{factory=null, action=INDIFFERENT,
timeout=0}, deleteUnacceptedMessages=false, initialState=started,
responseTimeout=1000000, endpointEncoding=UTF-8,
disableTransportTransformer=false}. Message payload is of type:
websrvMethod
</faultstring>
</soap:Fault>
How to redirect outbound address that I can use it each server and IP?
Try with the following configuration:
<flow name="wbs">
<http:inbound-endpoint host="localhost" port="9094"
path="myPath/app" exchange-pattern="request-response">
<cxf:proxy-service service="AppWSService"
wsdlLocation="schema/wsdl/App/WSService.wsdl"
namespace="http://wbservice.com/"
payload="body" />
</http:inbound-endpoint>
<copy-properties propertyName="SOAPAction" />
<http:outbound-endpoint address="http://websrv.mydns.com:8080/App/WSService"
encoding="UTF-8" responseTimeout="1000000"
exchange-pattern="request-response">
<cxf:proxy-client payload="body" />
</http:outbound-endpoint>
</flow>
My HTTP Endpoint responsible for downloading the file at the end of the flow is erroring out. It keeps trying to communicate with http://:80/ instead of the URL passed in. What am I doing wrong here?
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd ">
<flow name="BingFlow1" doc:name="BingFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" doc:name="HTTP"/>
<https:outbound-endpoint exchange-pattern="request-response" host="api.datamarket.azure.com" port="443" path="Data.ashx/Bing/Search/v1/Web?Query=%27contract%20california%27&WebFileType=%27PDF%27&$top=50&$format=Json" user="*****" password="*****" doc:name="Bing"/>
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
<expression-transformer expression="#[message.payload.d.results]" doc:name="Expression"/>
<collection-splitter doc:name="Collection Splitter"/>
<expression-transformer expression="#[org.mule.util.StringUtils.substringAfter(message.payload.Url, 'http://')]" doc:name="Expression"/>
<logger message="Payload is: #[message.payload]" level="INFO" doc:name="Logger"/>
<http:outbound-endpoint exchange-pattern="request-response" host="#[org.mule.util.StringUtils.substringBefore(message.payload, '/')]" port="80" method="GET" doc:name="HTTP" contentType="application/pdf" mimeType="application/pdf" path="#[org.mule.util.StringUtils.substringAfter(message.payload, '/')]"/>
<file:outbound-endpoint responseTimeout="10000" doc:name="File" outputPattern="#[org.mule.util.StringUtils.replace(message.payload, '/','.')]" path="/home/user/Documents/output" mimeType="application/pdf"/>
</flow>
</mule>
When changed to match the first answer, I get this exception:
********************************************************************************
Message : Failed to invoke REST service "http://santaclaraca.gov/modules/ShowDocument.aspx?documentid=108?followRedirects=true". Message payload is of type: LinkedHas
hMap
Code : MULE_ERROR--2
--------------------------------------------------------------------------------
Exception stack is:
1. Failed to invoke REST service "http://santaclaraca.gov/modules/ShowDocument.aspx?documentid=108?followRedirects=true". Message payload is of type: LinkedHashMap (org.mule.transp
ort.http.components.RestServiceException)
org.mule.transport.http.components.RestServiceWrapper:219 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/http/components/RestServiceException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.transport.http.components.RestServiceException: Failed to invoke REST service "http://santaclaraca.gov/modules/ShowDocument.aspx?documentid=108?followRedirects=true". Mess
age payload is of type: LinkedHashMap
at org.mule.transport.http.components.RestServiceWrapper.doInvoke(RestServiceWrapper.java:219)
at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:126)
at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:61)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************
--- SOLVED ---
Big thanks to David. This is my final solution:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:https="http://www.mulesoft.org/schema/mule/https" xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd ">
<configuration doc:name="Configuration">
<expression-language>
<import class="org.mule.util.StringUtils" />
</expression-language>
</configuration>
<flow name="BingQuery" doc:name="BingQuery">
<http:inbound-endpoint exchange-pattern="one-way"
host="localhost" port="8082" doc:name="HTTP" />
<https:outbound-endpoint exchange-pattern="request-response"
host="api.datamarket.azure.com" port="443"
path="Data.ashx/Bing/Search/v1/Web?Query=%27california%20school%20district%20contract%27&WebFileType=%27PDF%27&$top=10&$format=Json"
user="*****" password="*****"
doc:name="Bing" />
<json:json-to-object-transformer
returnClass="java.util.Map" doc:name="JSON to Object" />
<expression-transformer expression="#[message.payload.d.results]"
doc:name="Expression" />
<collection-splitter doc:name="Collection Splitter" />
<vm:outbound-endpoint exchange-pattern="one-way"
doc:name="VM" path="fileWriter" />
</flow>
<flow name="RestProcessor" doc:name="RestProcessor">
<vm:inbound-endpoint exchange-pattern="one-way"
doc:name="VM" path="fileWriter" />
<set-variable variableName="fileName" value="#[message.payload.ID].pdf"
doc:name="Variable" />
<http:rest-service-component
serviceUrl="#[joinChar=message.payload.Url.contains('?')?'&':'?' ; StringUtils.join(new String[]{message.payload.Url,(String)joinChar,'followRedirects=true'})]"
httpMethod="GET">
<http:error-filter>
<expression-filter
expression="#[Integer.valueOf(message.inboundProperties['http.status']) >= 400]"></expression-filter>
</http:error-filter>
</http:rest-service-component>
<file:outbound-endpoint responseTimeout="10000"
doc:name="File" outputPattern="#[flowVars.fileName]" path="/home/ken/Documents/output"
mimeType="application/pdf" />
</flow>
</mule>
I can't spot the error: your flow looks good (except a problem I'll detail below) so, alternatively to using an http:outbound-endpoint, which can be finicky at times, you could use the http:rest-service-component.
Your next problem will be in the outputPattern of the file endpoint: remember at this point message.payload will be the response from the HTTP endpoint not the (partial) URL anymore. You need to pre-compute the file name and store it in a flow variable, then use it.
This would give:
<configuration>
<expression-language>
<import class="org.mule.util.StringUtils" />
</expression-language>
</configuration>
<flow name="BingFlow1" doc:name="BingFlow1">
<http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8081" doc:name="HTTP"/>
<https:outbound-endpoint exchange-pattern="request-response" host="api.datamarket.azure.com" port="443" path="Data.ashx/Bing/Search/v1/Web?Query=%27contract%20california%27&WebFileType=%27PDF%27&$top=50&$format=Json" user="*****" password="*****" doc:name="Bing"/>
<json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/>
<expression-transformer expression="#[message.payload.d.results]" doc:name="Expression"/>
<collection-splitter doc:name="Collection Splitter"/>
<set-variable variableName="fileName" value="#[org.mule.util.StringUtils.substringAfter(message.payload.Url, 'http://').replace('/','.')]" />
<http:rest-service-component serviceUrl="#[joinChar=message.payload.Url.contains('?')?'&':'?' ; StringUtils.join(new String[]{message.payload.Url,(String)joinChar,'followRedirects=true'})]" httpMethod="GET">
<http:error-filter>
<expression-filter expression="#[Integer.valueOf(message.inboundProperties['http.status']) >= 400]" />
</http:error-filter>
</http:rest-service-component>
<file:outbound-endpoint responseTimeout="10000" doc:name="File" outputPattern="#[flowVars.fileName]" path="/home/user/Documents/output" mimeType="application/pdf"/>
</flow>