【发布时间】:2012-10-05 20:40:43
【问题描述】:
我使用 Mule 3.x
我有一个测试 MuleClient 连接性的代码。
这个测试没问题并且工作正常:
public void testHello() throws Exception
{
MuleClient client = new MuleClient(muleContext);
MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
//TODO Assert the correct data has been received
assertEquals("hello", result.getPayloadAsString());
}
但是这个测试不好 - 它失败并出现连接异常:
public void testHello_with_Spring() throws Exception {
MuleClient client = new MuleClient("mule-config-test.xml");
client.getMuleContext().start();
//it fails here
MuleMessage result = client.send("http://127.0.0.1:8080/hello", "some data", null);
assertNotNull(result);
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
//TODO Assert the correct data has been received
assertEquals("hello", result.getPayloadAsString());
}
'mule-config-test.xml' 用于两个测试,这个文件的路径没问题,我检查了。
这是我最后得到的错误信息:
异常堆栈是: 1.地址已经在使用(java.net.BindException) java.net.PlainSocketImpl:-2 (null) 2. 无法绑定到 uri "http://127.0.0.1:8080/hello" (org.mule.transport.ConnectException)
org.mule.transport.tcp.TcpMessageReceiver:81 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/transport/ConnectException.html) -------------------------------------------------- ------------------------------ 根异常堆栈跟踪:java.net.BindException:地址已在 在 java.net.PlainSocketImpl.socketBind(Native Method) 处使用 java.net.PlainSocketImpl.bind(PlainSocketImpl.java:383) 在 java.net.ServerSocket.bind(ServerSocket.java:328) + 3 个以上(设置调试级别日志记录或 '-Dmule.verbose.exceptions=true' 为所有内容)
[10-05 16:33:37] 错误 HttpConnector [主]: org.mule.transport.ConnectException:无法绑定到 uri “http://127.0.0.1:8080/hello”[10-05 16:33:37] 错误 ConnectNotifier [main]:连接/重新连接失败:HttpConnector {
name=connector.http.mule.default 生命周期=stop this=7578a7d9
numberOfConcurrentTransactedReceivers=4
createMultipleTransactedReceivers=true 已连接=false
supportedProtocols=[http] serviceOverrides= } 。根异常 是:地址已在使用中。类型:类 java.net.BindException [10-05 16:33:37] 错误 DefaultSystemExceptionStrategy [main]:绑定失败 到 uri "http://127.0.0.1:8080/hello"org.mule.api.lifecycle.LifecycleException:无法将事件处理为 “connector.http.mule.default”已停止
【问题讨论】: