Brap的创建WebService
??? 通过Brap开发WebService,通过Brap的WebService暴露类,ProxyServlet实现相关的类。需要相关配置的初始化参数。service,authorizationProvider,authenticationProvider等实现。
?
服务接口:
package com.easyway.remoting.braps;/** * 服务实现的接口 * @author longgangbai * */public interface HelloService { public String sayHello(String name);}
?
接口实现类:
package com.easyway.remoting.braps;/** * 服务端的服务实现类 * @author longgangbai * */public class HelloServiceImpl implements HelloService { public String sayHello(String name) { return "Hello world, " + name; }}
?
web.xml配置:
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <!-- 需要暴露brap的一种服务 --><servlet><servlet-name>hello</servlet-name><servlet-class>no.tornado.brap.servlet.ProxyServlet</servlet-class><!-- 需要暴露的bean名称 --> <init-param> <param-name>service</param-name> <param-value>com.easyway.remoting.braps.HelloServiceImpl</param-value> </init-param> <init-param> <param-name>authorizationProvider</param-name> <param-value>no.tornado.brap.auth.AuthenticationNotRequiredAuthorizer</param-value> </init-param> <init-param> <param-name>authenticationProvider</param-name> <param-value>no.tornado.brap.auth.AuthenticationNotRequiredAuthenticator</param-value> </init-param> <load-on-startup>1</load-on-startup></servlet> <!-- 暴露的路径名称 --><servlet-mapping><servlet-name>hello</servlet-name><url-pattern>/remoting/hello</url-pattern></servlet-mapping> </web-app>
?
客户端调用代码:
package com.easyway.ws.brap.service.client;import java.net.MalformedURLException;import no.tornado.brap.client.ServiceProxyFactory;import com.easyway.remoting.braps.HelloService;/** * 客户端调用代码 * @author longgangbai * */public class BrapClient {public static void main(String[] args) throws MalformedURLException {//客户端的服务信息HelloService service = ServiceProxyFactory.createProxy(HelloService.class,"http://localhost:8080/BrapServiceWS/remoting/hello");//客户端的操作System.out.println(service.sayHello("Hello"));}}
?