Mule ESB HTTPS INBOUND ENDPOINT CONNECTION FAILURE

时间:2015-03-05 13:08:43

标签: java-ee mule

我目前正在使用Mule Studio CE 1.3.2作为开发环境的一部分。我试图为测试目的设置一个基本流程,其中包含一个HTTPS入站端点,目的是从运行基于JSSE的客户端的远程机器上发布一些数据。所用流程的实际位如下所示:

`<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" 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.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/https http://www.mulesoft.org/schema/mule/https/current/mule-https.xsd 
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.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 ">
    <https:connector name="HTTP_HTTPS" cookieSpec="netscape" validateConnections="true" sendBufferSize="0" receiveBufferSize="0" receiveBacklog="0" clientSoTimeout="10000" serverSoTimeout="10000" socketSoLinger="0" doc:name="HTTP\HTTPS">
        <https:tls-key-store path="Mule.jks" keyPassword="abc" storePassword="cdfg"/>
        <https:tls-server path="Mule.jks" storePassword="cdfg"/>
        <https:tls-protocol-handler property="com.sun.net.ssl.internal.www.protocol"/>
    </https:connector>
    <flow name="HttpsServerTestFlow1" doc:name="HttpsServerTestFlow1" processingStrategy="asynchronous">
        <https:inbound-endpoint exchange-pattern="one-way" host="192.168.178.4" port="8080" path="test" mimeType="text/plain" connector-ref="HTTP_HTTPS" contentType="application/x-www-form-urlencoded" doc:name="HTTP"/>
        <scripting:component doc:name="Python">
            <scripting:script engine="jython">
                <scripting:text><![CDATA[print "Mule message:"
print message
]]></scripting:text>
            </scripting:script>
        </scripting:component>
    </flow>
</mule>` 

现在尝试从java客户端连接时,其代码(使用已弃用的软件包授予它,但仅用作快速测试)是:

`import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.Security;
import com.sun.net.ssl.HostnameVerifier;
import com.sun.net.ssl.HttpsURLConnection;


public class HTTPSClient {

    private HttpsURLConnection urlConnection=null;

    private static String host_address="192.168.178.47";

    private static int ssl_port=8080;

    public static void setHost_address(String host_address) {
        HTTPSClient.host_address = host_address;
    }

    public static String getHost_address() {
        return host_address;
    }

    public static void setSsl_port(int ssl_port) {
        HTTPSClient.ssl_port = ssl_port;
    }

    public static int getSsl_port() {
        return ssl_port;
    }

    static{

        Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

        System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");

        System.setProperty("javax.net.ssl.keyStore", "C:/Users/vangelis/client.jks");

        System.setProperty("javax.net.ssl.keyStorePassword", "xxxx");

        System.setProperty("javax.net.ssl.trustStore", "C:/Users/vangelis/trust-client.jks");

        System.setProperty("javax.net.ssl.trustStorePassword", "xxxxc");

        System.setProperty("https.protocols", "SSLv3");
    }


    public void sendData(String content){

        try {

            HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier(){

                @Override
                public boolean verify(String hostname, String session) {
                    // TODO Auto-generated method stub
                    return (true);
                }
            });

            URL url=new URL("https://"+getHost_address()+":"+getSsl_port()+"/test");

            urlConnection=(HttpsURLConnection)url.openConnection();

            urlConnection.setRequestMethod("POST");

            urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0");

            urlConnection.setRequestProperty("Accept-Language", "en-US,en;q=0.5");

            urlConnection.setDoOutput(true);

            urlConnection.connect();

            OutputStream out_stream = urlConnection.getOutputStream();

            DataOutputStream out_stream_writer=new DataOutputStream(out_stream);

            out_stream_writer.writeBytes(content);

            out_stream_writer.close();

        }

        catch (MalformedURLException e) {

            e.printStackTrace();
        }

        catch (java.net.SocketException e){

            e.printStackTrace();
        }

        catch (IOException e) {

            e.printStackTrace();
        }
    }


    public static void main(String[] args) {

        String data="data%3Dhello";

        HTTPSClient secure_client= new HTTPSClient();

        secure_client.sendData(data);

        System.out.print("Done...");

    }

}`

我总是在骡子端收到以下堆栈跟踪:

    **`ERROR 2015-03-05 14:56:09,525 [[httpsservertest].HTTP_HTTPS.receiver.02] org.mule.exception.DefaultSystemExceptionStrategy: Caught exception in Exception Strategy: Connection reset
java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)
    at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:755)
    at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
    at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:50)
    at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78)
    at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106)
    at org.mule.transport.http.HttpServerConnection.readLine(HttpServerConnection.java:219)
    at org.mule.transport.http.HttpServerConnection.readRequest(HttpServerConnection.java:185)
    at org.mule.transport.http.HttpMessageReceiver$HttpWorker.run(HttpMessageReceiver.java:155)
    at org.mule.work.WorkerContext.run(WorkerContext.java:311)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)`**

请记住,如果我使用第二个mule流,使用https-outbound端点以连接到上面讨论的入站端点的流,那么一切正常,没有任何错误。似乎问题在于java客户端代码。有人可以帮助我,因为一个快速而肮脏的集成测试案例开始让我解决问题。 谢谢 范吉利斯

1 个答案:

答案 0 :(得分:1)

你的家庭成长的HTTP客户端没有读取Mule的HTTP响应,因此Mule抱怨客户端已经过早关闭了连接。

修复客户端以读取Mule的响应或使用正确的HTTP客户端(例如Apache's HTTP Client)。