我使用骡子 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 处使用(本机方法)在 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 [main]: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 connected=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”已停止