org.springframework.remoting.RemoteConnectFailureException: Could not connect to HTTP invoker remote

org.springframework.remoting.RemoteConnectFailureException: Could not connect to HTTP invoker remote service at 
[http://106.14.67.140/service/fileUploadService]; nested exception is java.net.ConnectException: Connection refused
一般报这个错误。首先确定对应的地址能不能访问
二是看看对应的系统是啥。因为在linux和Windows还是有点差别的。如果是这个原因造成的。要改下Hostname
在Spring框架中,`org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter` 是用于通过HTTP进行远程服务调用的一个关键类,`handleRequest` 方法在处理远程调用请求时起着核心作用。 `handleRequest` 方法主要负责接收HTTP请求,对请求中的数据进行反序列化,调用相应的服务方法,然后将方法调用的结果序列化并返回给客户端。以下为其详细的工作流程: ### 1. 接收HTTP请求 该方法会首先接收来自客户端的HTTP POST请求。客户端会将远程服务调用的相关信息(如服务方法名、参数等)封装在请求的Body中发送过来。 ### 2. 反序列化请求数据 `handleRequest` 方法会读取POST请求的Body,并将其中的数据进行反序列化。反序列化的目的是将客户端发送的字节流数据转换为Java对象,便于后续调用本地服务方法。 ### 3. 调用本地服务方法 根据反序列化得到的信息,`handleRequest` 方法会找到对应的本地服务,并调用相应的方法。调用过程会传入反序列化得到的参数。 ### 4. 序列化调用结果 方法调用结束后,会将返回的结果进行序列化,将其转换为字节流,以便于通过HTTP响应发送给客户端。 ### 5. 返回HTTP响应 最后,将序列化后的结果封装在HTTP响应中,返回给客户端。 以下是一个示例代码,模拟 `handleRequest` 方法的大致逻辑: ```java import org.springframework.remoting.support.RemoteInvocation; import org.springframework.remoting.support.RemoteInvocationResult; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public class HttpInvokerServiceExporter { private Object service; public HttpInvokerServiceExporter(Object service) { this.service = service; } public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { try { // 反序列化请求 ObjectInputStream ois = new ObjectInputStream(request.getInputStream()); RemoteInvocation invocation = (RemoteInvocation) ois.readObject(); ois.close(); // 调用本地服务方法 Object result = invocation.invoke(service); // 序列化结果 RemoteInvocationResult invocationResult = new RemoteInvocationResult(result); response.setContentType("application/x-java-serialized-object"); ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream()); oos.writeObject(invocationResult); oos.flush(); oos.close(); } catch (Exception e) { e.printStackTrace(); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Remote service invocation failed"); } } } ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值