项目中有遇到两个网络不通但是需要访问的情况我们可以通过配置mule来实现网络互通,
客户端(外网)配置ftp目录需要两个ftp
< mule xmlns:ftp=“http://www.mulesoft.org/schema/mule/ee/ftp” xmlns:file=“http://www.mulesoft.org/schema/mule/file”
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.6.1”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://www.mulesoft.org/schema/mule/ee/ftp http://www.mulesoft.org/schema/mule/ee/ftp/current/mule-ftp-ee.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”>
< global-property name=“responseFilePath” value=“D:\temp\response” doc:name=“Global Property”>< /global-property>
< global-property name=“requestFilePath” value=“D:\temp\request” doc:name=“Global Property”>< /global-property>
< global-property name=“client.ftp.host.get” value=“192.168.2.222” doc:name=“Global Property”>< /global-property>
< global-property name=“client.ftp.port.get” value=“21” doc:name=“Global Property”>< /global-property>
< global-property name=“client.ftp.user.get” value=“shs” doc:name=“Global Property”>< /global-property>
< global-property name=“client.ftp.password.get” value=“123456” doc:name=“Global Property”>< /global-property>
< global-property name=“client.ftp.host.send” value=“192.168.2.222” doc:name=“Global Property”>< /global-property>
< global-property name=“client.ftp.port.send” value=“24” doc:name=“Global Property”>< /global-property>
< global-property name=“client.ftp.user.send” value=“shs1” doc:name=“Global Property”>< /global-property>
< global-property name=“client.ftp.password.send” value=“123456” doc:name=“Global Property”>< /global-property>
< flow name=“clientSendFileToFTP”>
< file:inbound-endpoint path="${requestFilePath}" responseTimeout=“10000” doc:name=“File” pollingFrequency=“100” encoding=“UTF-8”>< /file:inbound-endpoint>
<ftp:outbound-endpoint host="${client.ftp.host.send}" port="${client.ftp.port.send}" responseTimeout="10000" doc:name="FTP" outputPattern="#[message.inboundProperties['originalFilename']]" password="${client.ftp.password.send}" user="${client.ftp.user.send}" path="" encoding="UTF-8"></ftp:outbound-endpoint>
</flow>
<flow name="clientGetFileFromFTP">
<ftp:inbound-endpoint host="${client.ftp.host.get}" port="${client.ftp.port.get}" responseTimeout="10000" doc:name="FTP" password="${client.ftp.password.get}" user="${client.ftp.user.get}" path="" pollingFrequency="100" encoding="UTF-8"></ftp:inbound-endpoint>
<file:outbound-endpoint path="${responseFilePath}" responseTimeout="10000" doc:name="File" outputPattern="#[message.inboundProperties['originalFilename']]" encoding="UTF-8"></file:outbound-endpoint>
</flow>
< /mule>
客户端监听端口配置(可以配置监听多个端口):
< mule xmlns:file=“http://www.mulesoft.org/schema/mule/file”
xmlns:http=“http://www.mulesoft.org/schema/mule/http”
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.6.1”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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”>
<!--监听IP,通常是本机内网IP;监听端口1-->
<http:listener-config name="HTTP_Listener_Configuration_Java_service" host="192.168.2.111" port="8080" doc:name="HTTP Listener Configuration" connectionIdleTimeout="60000"/>
<sub-flow name="send-get">
<set-property propertyName="filename" value="#[function:uuid].json" doc:name="filename"/>
<set-variable variableName="responseFilePath" value="${responseFilePath}" doc:name="responseFilePath"/>
<custom-transformer class="com.netbox.proxy.SaveRequest" doc:name="SaveRequest" encoding="UTF-8"/>
<file:outbound-endpoint path="${requestFilePath}" responseTimeout="20000" doc:name="File" encoding="UTF-8"/>
<custom-transformer class="com.netbox.proxy.GetResponse" doc:name="GetResponse" encoding="UTF-8"/>
<logger level="INFO" doc:name="Logger"/>
</sub-flow>
<flow name="FLOW_Java_service">
<http:listener config-ref="HTTP_Listener_Configuration_Java_service" path="/*" allowedMethods="Get,Post" doc:name="HTTP" responseStreamingMode="ALWAYS">
<http:response-builder>
<http:header headerName="Access-Control-Allow-Origin" value="*"/>
<http:header headerName="Access-Control-Allow-Methods" value="POST,GET"/>
<http:header headerName="Access-Control-Allow-Credentials" value="true"/>
<http:header headerName="Content-Type" value="text/html; charset=utf-8"/>
</http:response-builder>
</http:listener>
<!--对应管综网安网服务子系统TOMCAT地址例:http://IP:8080/ -->
<set-variable variableName="serviceUrl" value="http://192.168.2.234:8080/" doc:name="serviceUrl"/>
<set-variable variableName="charset" value="utf-8" doc:name="charset"/>
<set-variable variableName="serviceType" value="java" doc:name="serviceType"/>
<flow-ref name="send-get" doc:name="send-get"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
<!--监听IP,通常是本机内网IP;监听端口1-->
<http:listener-config name="HTTP_Listener_Configuration_App_service" host="192.168.2.111" port="8088" doc:name="HTTP Listener Configuration" connectionIdleTimeout="60000"/>
<sub-flow name="send-get-app">
<set-property propertyName="filename" value="#[function:uuid].json" doc:name="filename"/>
<set-variable variableName="responseFilePath" value="${responseFilePath}" doc:name="responseFilePath"/>
<custom-transformer class="com.netbox.proxy.SaveRequestApp" doc:name="SaveRequest" encoding="UTF-8"/>
<file:outbound-endpoint path="${requestFilePath}" responseTimeout="20000" doc:name="File" encoding="UTF-8"/>
<custom-transformer class="com.netbox.proxy.GetResponse" doc:name="GetResponse" encoding="UTF-8"/>
<logger level="INFO" doc:name="Logger"/>
</sub-flow>
<flow name="FLOW_App_service">
<http:listener config-ref="HTTP_Listener_Configuration_App_service" path="/*" allowedMethods="Get,Post" doc:name="HTTP" responseStreamingMode="ALWAYS">
<http:response-builder>
<http:header headerName="Access-Control-Allow-Origin" value="*"/>
<http:header headerName="Access-Control-Allow-Methods" value="POST,GET"/>
<http:header headerName="Access-Control-Allow-Credentials" value="true"/>
<http:header headerName="Content-Type" value="text/html; charset=utf-8"/>
</http:response-builder>
</http:listener>
<!--对应管综网安网服务子系统TOMCAT地址例:http://IP:8080/ -->
<set-variable variableName="serviceUrl" value="http://192.168.2.234:8088/" doc:name="serviceUrl"/>
<set-variable variableName="charset" value="utf-8" doc:name="charset"/>
<set-variable variableName="serviceType" value="java" doc:name="serviceType"/>
<flow-ref name="send-get-app" doc:name="send-get"/>
<logger level="INFO" doc:name="Logger"/>
</flow>
< /mule>
服务端配置(内网)配置的是外网的两个ftp和自己本地的临时目录用于取文件和写文件:
<?xml version="1.0" encoding="UTF-8"?>< mule xmlns:ftp=“http://www.mulesoft.org/schema/mule/ee/ftp” xmlns:file=“http://www.mulesoft.org/schema/mule/file”
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.6.1”
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=“http://www.mulesoft.org/schema/mule/ee/ftp http://www.mulesoft.org/schema/mule/ee/ftp/current/mule-ftp-ee.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”>
< global-property name=“serviceRequestFilePath” value=“D:\temp\wangan\request” doc:name=“Global Property”>< /global-property>
< global-property name=“serviceResponseFilePath” value=“D:\temp\wangan\response” doc:name=“Global Property”>< /global-property>
< global-property name=“server.ftp.host.get” value=“192.168.2.222” doc:name=“Global Property”>< /global-property>
< global-property name=“server.ftp.port.get” value=“24” doc:name=“Global Property”>< /global-property>
< global-property name=“server.ftp.user.get” value=“shs1” doc:name=“Global Property”>< /global-property>
< global-property name=“server.ftp.password.get” value=“123456” doc:name=“Global Property”>< /global-property>
< global-property name=“server.ftp.host.send” value=“192.168.2.222” doc:name=“Global Property”>< /global-property>
< global-property name=“server.ftp.port.send” value=“21” doc:name=“Global Property”>< /global-property>
< global-property name=“server.ftp.user.send” value=“shs” doc:name=“Global Property”>< /global-property>
< global-property name=“server.ftp.password.send” value=“123456” doc:name=“Global Property”>< /global-property>
< flow name=“serverGetFileFromFTP”>
<ftp:inbound-endpoint host="
s
e
r
v
e
r
.
f
t
p
.
h
o
s
t
.
g
e
t
"
p
o
r
t
=
"
{server.ftp.host.get}" port="
server.ftp.host.get"port="{server.ftp.port.get}" responseTimeout=“10000” doc:name=“FTP” password="
s
e
r
v
e
r
.
f
t
p
.
p
a
s
s
w
o
r
d
.
g
e
t
"
u
s
e
r
=
"
{server.ftp.password.get}" user="
server.ftp.password.get"user="{server.ftp.user.get}" path="" pollingFrequency=“100” encoding=“UTF-8”>< /ftp:inbound-endpoint>
< set-property propertyName=“filename” value="#[message.inboundProperties[‘originalFilename’]]" doc:name=“filename”>< /set-property>
< /set-property>
< custom-transformer class=“com.netbox.proxy.DoHttpRequest” doc:name=“DoHttpRequest” encoding=“UTF-8”>< /custom-transformer>
< file:outbound-endpoint path="KaTeX parse error: Expected 'EOF', got '#' at position 82: …outputPattern="#̲[message.inboun…{serviceResponseFilePath}" responseTimeout=“10000” doc:name=“File” pollingFrequency=“100” encoding=“UTF-8”>< /file:inbound-endpoint>
<ftp:outbound-endpoint host="
s
e
r
v
e
r
.
f
t
p
.
h
o
s
t
.
s
e
n
d
"
p
o
r
t
=
"
{server.ftp.host.send}" port="
server.ftp.host.send"port="{server.ftp.port.send}" responseTimeout=“10000” doc:name=“FTP” outputPattern="#[message.outboundProperties[‘filename’]]" password="
s
e
r
v
e
r
.
f
t
p
.
p
a
s
s
w
o
r
d
.
s
e
n
d
"
u
s
e
r
=
"
{server.ftp.password.send}" user="
server.ftp.password.send"user="{server.ftp.user.send}" path="" encoding=“UTF-8”>< /ftp:outbound-endpoint>
< /flow>
< /mule>