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>

部署发布接口

 

你可能感兴趣的:(spring,bean,xml,servlet,企业应用)