如何使用Mule 2连接到https服务器

如何使用Mule 2连接到https服务器

问题描述:

我使用此命令将 .pem 文件转换为 .jks 一个(来源):

I used this command to convert a .pem file to a .jks one (source):

keytool -importcert -alias debian -file cert.pem -keystore cert.jks -storepass passwd

这是Mule文件:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:http="http://www.mulesource.org/schema/mule/http/2.2"
    xmlns:https="http://www.mulesource.org/schema/mule/https/2.2"
    xsi:schemaLocation="
        http://www.mulesource.org/schema/mule/http/2.2 http://www.mulesource.org/schema/mule/http/2.2/mule-http.xsd
        http://www.mulesource.org/schema/mule/https/2.2 http://www.mulesource.org/schema/mule/https/2.2/mule-https.xsd
        http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd">

    <https:connector name="SslConnector" keepSendSocketOpen="true">
        <https:tls-client path="${mule.home}/cert.jks"
                          storePassword="passwd"/>
    </https:connector>

    <model>
        <service name="ConnectToHTTPS">
            <inbound>
                <http:inbound-endpoint host="localhost"
                                       port="9000"
                                       synchronous="true"/>
            </inbound>
            <outbound>
                <chaining-router>
                    <outbound-endpoint address="https://localhost"
                                       synchronous="true"/>
                </chaining-router>
            </outbound>
        </service>
    </model>
</mule>

现在,我明白了:

ERROR 2011-07-08 12:06:51,210 [main] org.mule.MuleServer: 
********************************************************************************
Message               : Initialisation Failure: Error creating bean with name 'SslConnector': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: The Key password cannot be null
Type                  : org.mule.api.lifecycle.InitialisationException
Code                  : MULE_ERROR-72085
JavaDoc               : http://www.mulesource.org/docs/site/current2/apidocs/org/mule/api/lifecycle/InitialisationException.html
Object                : org.mule.config.spring.SpringRegistry@160bf50
********************************************************************************
Exception stack is:
1. The Key password cannot be null (java.lang.IllegalArgumentException)
  org.mule.api.security.tls.TlsConfiguration:290 (null)
2. Error creating bean with name 'SslConnector': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: The Key password cannot be null (org.springframework.beans.factory.BeanCreationException)
  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory:1338 (null)
3. Initialisation Failure: Error creating bean with name 'SslConnector': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: The Key password cannot be null (org.mule.api.lifecycle.InitialisationException)
  org.mule.registry.AbstractRegistry:76 (http://www.mulesource.org/docs/site/current2/apidocs/org/mule/api/lifecycle/InitialisationException.html)

sidenote :这扩展了是否有办法通过仅指定Mule 2中的网址来连接到https服务器?

在尝试配置后,我发现还需要一个tls-key-store元素。

After experimenting with your config, I figured that a tls-key-store element is also needed.

以下HTTPS配置允许ConnectToHTTPS成功点击HTTPS出站目标:

The following HTTPS configuration allows "ConnectToHTTPS" to successfully hit an HTTPS outbound target:

<https:connector name="SslConnector" keepSendSocketOpen="true">
    <https:tls-client path="${mule.home}/cert.jks"
                      storePassword="passwd"/>
    <https:tls-key-store path="${mule.home}/cert.jks"
                         keyPassword="passwd"
                         storePassword="passwd" />
</https:connector>