Spring 企业级开发应用---------httpinvoke和spring的远程服务整合的应用

和burlap和hessian一样的配置细细

服务端服务的接口类

package cn.com.huawei.httpinvoker.service;

import java.util.List;

public interface IUserService {
  public List getUsernames();
}
服务端服务的实现类的应用

package cn.com.huawei.httpinvoker.service.impl;

import java.util.ArrayList;
import java.util.List;

import cn.com.huawei.httpinvoker.service.IUserService;

 

public class UserService  implements  IUserService{
   public List getUsernames()
   {
     List<String> usernames=new ArrayList<String>();
     usernames.add("xiaobai");
     usernames.add("xiaoli");
     return usernames;
   }
}

服务端web。xml的配置信息

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext.xml</param-value>
 </context-param>
 <listener>
  <listener-class>
   org.springframework.web.context.ContextLoaderListener
  </listener-class>
 </listener>
 <servlet>
  <servlet-name>remoting</servlet-name>
  <servlet-class>
   org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>remoting</servlet-name>
  <url-pattern>/remoting/*</url-pattern>
 </servlet-mapping>
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

 


服务端的applicationcontext。xml的配置信息

<?xml version="1.0" encoding="UTF-8"?>
<beans
 xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
       <bean id="userservicetarget" class="cn.com.huawei.httpinvoker.service.impl.UserService"/>
</beans>

 

 

服务端的remoting-servlet。xml的配置信息

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
 <bean name="/UserService-httpinvoker"
  class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
  <property name="service" ref="userservicetarget" />
  <property name="serviceInterface"
   value="cn.com.huawei.httpinvoker.service.IUserService" />
 </bean>
</beans>

 

 

客户端的配置信息如下

package cn.com.huawei.httpinvoker.client;

import java.util.List;

import cn.com.huawei.httpinvoker.service.IUserService;


public class HttpInvokerClient {

 private IUserService userservice;

 public IUserService getUserservice() {
  return userservice;
 }

 public void setUserservice(IUserService userservice) {
  this.userservice = userservice;
 }

 public List getUsernames() {
  return this.userservice.getUsernames();
 }

}

 

package cn.com.huawei.httpinvoker.client;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class HttpInvokerTest {
 public static void main(String[] args) {
  ApplicationContext ctx = new ClassPathXmlApplicationContext(
    "applicationContext.xml");
  HttpInvokerClient hessina = (HttpInvokerClient) ctx.getBean("httpInvokerclient");
  System.out.println("rmiclient:" + hessina.getUsernames());
 }
}


客户端的client。properties的属性信息

# Properties file with server URL settings for remote access.
# Applied by PropertyPlaceholderConfigurer from "clientContext.xml".

serverName=localhost
httpPort=8080
rmiPort=1199
serverPath=SpringHttpInvoker
contextPath=remoting/UserService-httpinvoker

 

 

客户端的applicationcontext。xml的配置信息

<?xml version="1.0" encoding="UTF-8"?>
<beans
 xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
     <bean id="propertyConfigurer"
  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location">
   <value>client.properties</value>
  </property>
 </bean>
     <bean id="httpInvokerclient" class="cn.com.huawei.httpinvoker.client.HttpInvokerClient">
       <property name="userservice">
         <ref bean="httpInvokerProxy"/>
       </property>
     </bean>
    <bean id="httpInvokerProxy" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
  <property name="serviceUrl">
   <value>http://${serverName}:${httpPort}/${serverPath}/${contextPath}</value>
  </property>
  <property name="serviceInterface">
   <value>cn.com.huawei.httpinvoker.service.IUserService</value>
  </property>
  <!--
  Comment the following in to use Apache Commons HttpClient instead of the JDK's
  standard HttpURLConnection (as used by the default SimpleHttpInvokerRequestExecutor).
  -->
  <!--
  <property name="httpInvokerRequestExecutor">
   <bean class="org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor"/>
  </property>
   -->
 </bean>

</beans>

部署发布接口

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值