spring的httpinvoker 链接超时问题

最近做一个项目,用spring的httpinvoker远程调用方式,配置成功了。。一切没有问题。为了更加完美,考虑到假如服务提供方的服务出现问题,链接不上,那么客户端连接就一直会等待,这样对客户来说,是很不好的方式,,,10几秒没有反映。。。最后还会报cannot connect to 某某 ip 某某服务。。

不知道httpinvoker对服务的超时问题可以在什么地方配置不?
为了大家了解我配置的httpinvoker。把相关的代码贴出来。。。

首先是服务器端:
web.xml
[code=Java]
<servlet>
<servlet-name>remote</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>

</servlet>
[/code]
remote-servlet.xml
[code=Java]
</bean>

<bean name="/requestXmlData" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service">
<ref bean="xml"/>
</property>
<property name="serviceInterface">
<value>com.eway.wap.remote.businessinterface.RequestParser</value>
</property>
</bean>
[/code]

spring的配置文件中
[code=Java]
<!--httpinvoker服务器端配置-->
<bean id="xml" class="com.eway.wap.remote.businessinterface.RequestParserImpl"/>
[/code]

客户端:
[code=Java]
<!--httpinvoker调用远程服务-->
<bean id="httpInvokerRequestParser"
class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="eway"/>
<property name="httpInvokerRequestExecutor" ref="httpInvokerRequestExecutor"/>
<property name="serviceInterface" value="com.eway.wap.remote.businessinterface.RequestParser"/>
</bean>

<bean id="httpInvokerRequestExecutor" class="com.eway.wap.remote.invoke.httpinvoker.EwayHttpInvokerRequestExecutor"/>
[/code]


------------------------------
附录:
使用到的java接口和类如下:

com.eway.wap.remote.businessinterface.RequestParser
[code=Java]
package com.eway.wap.remote.businessinterface;

import com.eway.wap.exception.sub.NotGetRemoteDataHttpInvokerException;

/**
* Created by IntelliJ IDEA.
* User: yuchen
* Date: 2008-9-24
* Time: 10:17:17
* To change this template use File | Settings | File Templates.
*/
public interface RequestParser {
/**
*
* @param _request
* @return
* @throws NotGetRemoteDataHttpInvokerException
*/
public String parse(String _request) ;
}

[/code]


[code=Java]

package com.eway.wap.remote.businessinterface;

import com.eway.wap.exception.sub.NotGetRemoteDataHttpInvokerException;
import com.eway.wap.remote.axis.AxisJavaCallDotNet;

/**
* Created by IntelliJ IDEA.
* User: yuche
* Date: 2008-9-24
* Time: 10:40:19
* To change this template use File | Settings | File Templates.
*/
public class RequestParserImpl implements RequestParser {
public String parse(String requestXml) {
System.out.println("***************************************requestXml:"+requestXml);
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<response>\n" +
"\t<sysid>0001</sysid>\n" +
"\t<sysname></sysname>\n" +
"\t<user>123123</user>\n" +
"\t<type>wapdata</type>\n" +
"\t<date></date>\n" +
"\t<list>\n" +
"\t\t<item date=\"2008-9-20\">工程管理待办列表(10)</item>\n" +
"\t\t<item date=\"2008-9-20\">工程管理已办列表(7)</item>\n" +
"\t</list>\n" +
"</response>";
}

}


[/code]

[code=Java]
package com.eway.wap.remote.businessinterface;

/**
* Created by IntelliJ IDEA.
* User: yuchen
* Date: 2008-11-8
* Time: 11:27:36
* To change this template use File | Settings | File Templates.
*/
public interface HttpInvokerRequestParser extends RequestParser{
/**
*
* @param _request
* @return
* @throws com.eway.wap.exception.sub.NotGetRemoteDataHttpInvokerException
*/
public String parse(String _request) ;
}
[/code]


[code=Java]
package com.eway.wap.remote.invoke.httpinvoker;

import com.eway.wap.core.context.RemoteServiceContextHolder;
import org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration;
import org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;

import sun.net.www.protocol.http.HttpURLConnection;

public class EwayHttpInvokerRequestExecutor extends SimpleHttpInvokerRequestExecutor {

protected HttpURLConnection openConnection(HttpInvokerClientConfiguration config) throws IOException {

String serviceUrl = RemoteServiceContextHolder.getContext().getServiceUrl();
System.out.println("serviceUrl========"+serviceUrl);
URLConnection con = new URL(serviceUrl).openConnection();
if (!(con instanceof HttpURLConnection)) {
throw new IOException("Service URL [" + config.getServiceUrl() + "] is not an HTTP URL");
}
return (HttpURLConnection) con;
}
}


[/code]

大体就是这样。。。
现在遇到的问题。。就是考虑到,加入服务器段出现故障(服务器停了,电源故障,====),反正是客户段不能正常的访问了,,那么客户段回一直等待,,,为了避免长时间的等待,,不知道怎么设置。。。httpinvoker如何处理超时问题。。。。

交流也可以,我的一个java的Q..Q 群号:26572256
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值