Brap 远程访问调用 (一)

       在开发远程访问时,你可以选择,Hessian,Burlap,EJB,XFire,CFX,Brap等,其中Brap,Hessian,Brap他们采用的Http协议基本的方式基本相似;

服务接口如下:

package com.easyway.tornado.brap.ws;
/**
 * Brap的服务的接口
 * @author longgangbai
 *
 */
public interface IBrapService {
	  public String getHello();
	  public String setHello(String hello);
}

 

服务接口的实现:

package com.easyway.tornado.brap.ws;

import java.io.Serializable;

import no.tornado.brap.auth.AnonymousPrincipal;
import no.tornado.brap.auth.AuthenticationContext;
import no.tornado.brap.common.UsernamePasswordPrincipal;

/**
 * Brap发布远程访问的方法
 * 
 * @author longgangbai
 *
 */
public class BrapServiceImpl  implements IBrapService{

	private String hello="I'm a chinese people!";
	@Override
	public String getHello() {
		return hello;
	}

	@Override
	public String  setHello(String name) {
		Serializable principal = AuthenticationContext.getPrincipal();
		if(principal instanceof UsernamePasswordPrincipal){
			
			UsernamePasswordPrincipal  upp=(UsernamePasswordPrincipal)principal;
			return "Hello there ,"+name +" ,your username is "+upp.getUsername()+" and your password is "+upp.getPassword();
			
		}
		if (principal instanceof AnonymousPrincipal) {
			      return "Hello there, " + name + ", you are authenticated anonymously.";
	    }
		return "Hello there, " + name;
	}

}

 

服务端的Web.xml配置如下:

	<servlet>
	    <servlet-name>brapWs</servlet-name>
	    <servlet-class>no.tornado.brap.servlet.ProxyServlet</servlet-class>
	    <init-param>
	        <param-name>service</param-name>
	        <param-value>com.easyway.tornado.brap.ws.BrapServiceImpl</param-value>
	    </init-param>
	   <init-param>
	        <param-name>authorizationProvider</param-name>
	        <param-value>no.tornado.brap.auth.AuthenticationNotRequiredAuthorizer</param-value>
	    </init-param>
	</servlet>
	
	<servlet-mapping>
	    <servlet-name>brapWs</servlet-name>
	    <url-pattern>/remoting/brapWs</url-pattern>
	</servlet-mapping>

 

客户端的代码如下:

package com.easyway.tornado.brap.ws;

import no.tornado.brap.client.ServiceProxyFactory;
/**
 * Brap以Servlet方式发布并远程访问的过程
 * @author longgangbai
 *
 */
public class BrapServiceClient {
	
	public static void main(String[] args) {
		IBrapService brapService = ServiceProxyFactory.createProxy(IBrapService.class, "http://localhost:8080/SpaceCommons/remoting/brapWs");
		String message=brapService.setHello("hello");
		System.out.println("message ="+message);
	}

}

 

你可能感兴趣的:(xml,Web,servlet,ejb)