`
longgangbai
  • 浏览: 7383151 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Brap 远程访问调用 和Spring整合(二)

阅读更多

             Brap和 Spring 整合使用如下:

服务端接口:

package com.easyway.space.spring.remoting.rmi;
public interface IPersonService {
 public  String getPerson(PersonVO personVo);
}

 

服务端的实现:

package com.easyway.space.spring.remoting.rmi;
public class PersonServiceImpl implements IPersonService {
 @Override
 public String getPerson(PersonVO personVo) {
  return personVo.getUsername();
 }
}

 

 spring的配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans
	xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:p="http://www.springframework.org/schema/p"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
   <bean id="rpersonService" class="com.easyway.space.spring.remoting.rmi.PersonServiceImpl">
   </bean>
   
     <!-- 身份验证提供者 -->
   <bean id="authenticationProvider" class="no.tornado.brap.auth.SingleUsernamePasswordAuthenticator">
	        <property name="username">
			       <value>jhon</value>     
	        </property>
	        <property name="password">
			       <value>secret</value>     
	        </property>
    </bean>
    
    
    <!--  授权提供器-->
   <bean id="authorizationProvider" class="no.tornado.brap.auth.AuthenticationNotRequiredAuthorizer" />
    
    <!--远程服务包装器  不使用验证时的备注 -->
 <bean id="personServiceWraper"  class="no.tornado.brap.servlet.ServiceWrapper" >
         <property name="service">
             <ref bean="rpersonService"/>
         </property>
         <property name="authorizationProvider">
             <ref bean="authorizationProvider"/>
         </property>
   </bean>
   
</beans>

 

在web.xml配置如下:

	<context-param>
	    <param-name>contextConfigLocation</param-name>
	    <param-value>classpath*:remoting/applicationContext-remoting-server.xml</param-value>
	</context-param>
		<listener>
	  <listener-class>
	      org.springframework.web.context.ContextLoaderListener
	  </listener-class>
	</listener>
<!-- Brap 和SPring的整合 -->
    <servlet>
       <servlet-name>brapSpring</servlet-name>
       <servlet-class>no.tornado.brap.spring.SpringProxyServlet</servlet-class>
       <init-param>
          <param-name>beanName</param-name>
          <param-value>personServiceWraper</param-value>
       </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>brapSpring</servlet-name>
        <url-pattern>/remoting/brapSpring</url-pattern>
    </servlet-mapping>

 

 

客户端访问如下:

 

package com.easyway.tornado.brap.ws;

import no.tornado.brap.client.ServiceProxyFactory;

import com.easyway.space.spring.remoting.rmi.IPersonService;
import com.easyway.space.spring.remoting.rmi.PersonVO;

/**
 * Spring和Brap整合使用的开发远程访问方式
 * @author longgangbai
 *
 */
public class BrapServiceSpringClient {
	public static void main(String[] args) {
		IPersonService pService = ServiceProxyFactory.createProxy(IPersonService.class, "http://localhost:8080/SpaceCommons/remoting/brapSpring");
		PersonVO personVO=new PersonVO();
		personVO.setPassword("password");
		personVO.setUsername("username");
		String msg=pService.getPerson(personVO);
		System.out.println("message ="+msg);
	}
}

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics