日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Http Invoker的Spring Remoting支持

發布時間:2023/12/3 javascript 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Http Invoker的Spring Remoting支持 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Spring HTTP Invoker是Java到Java遠程處理的重要解決方案。 該技術使用標準的Java序列化機制通過HTTP公開服務,并且可以被視為替代解決方案,而不是Hessian和Burlap中的自定義序列化。 而且,它僅由Spring提供,因此客戶端和服務器應用程序都必須基于Spring。

Spring通過HttpInvokerProxyFactoryBean和HttpInvokerServiceExporter支持HTTP調用程序基礎結構。 HttpInvokerServiceExporter,它將指定的服務bean導出為HTTP調用程序服務端點,可通過HTTP調用程序代理訪問。 HttpInvokerProxyFactoryBean是用于HTTP調用程序代理的工廠bean。

此外,還提供了有關Spring Remoting簡介和RMI Service&Client示例項目的Spring Remoting支持和RMI文章。

讓我們看一下Spring Remoting Support,以開發Http Invoker Service&Client。

二手技術:

  • JDK 1.6.0_31
  • 春天3.1.1
  • Tomcat 7.0
  • Maven的3.0.2

步驟1:建立已完成的專案

創建一個Maven項目,如下所示。 (可以使用Maven或IDE插件來創建它)。

步驟2:圖書館

Spring依賴項已添加到Maven的pom.xml中。

<!-- Spring 3.1.x dependencies --> <properties><spring.version>3.1.1.RELEASE</spring.version> </properties><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-remoting</artifactId><version>2.0.8</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency> <dependencies>

步驟3:建立使用者類別

創建一個新的用戶類。

package com.otv.user;import java.io.Serializable;/*** User Bean** @author onlinetechvision.com* @since 24 Feb 2012* @version 1.0.0**/ public class User implements Serializable {private long id;private String name;private String surname;/*** Get User Id** @return long id*/public long getId() {return id;}/*** Set User Id** @param long id*/public void setId(long id) {this.id = id;}/*** Get User Name** @return long id*/public String getName() {return name;}/*** Set User Name** @param String name*/public void setName(String name) {this.name = name;}/*** Get User Surname** @return long id*/public String getSurname() {return surname;}/*** Set User Surname** @param String surname*/public void setSurname(String surname) {this.surname = surname;}@Overridepublic String toString() {StringBuilder strBuilder = new StringBuilder();strBuilder.append("Id : ").append(getId());strBuilder.append(", Name : ").append(getName());strBuilder.append(", Surname : ").append(getSurname());return strBuilder.toString();} }

步驟4:建立ICacheService介面

創建了代表遠程緩存服務接口的ICacheService接口。

package com.otv.cache.service;import java.util.concurrent.ConcurrentHashMap;import com.otv.user.User;/*** Cache Service Interface** @author onlinetechvision.com* @since 10 Mar 2012* @version 1.0.0**/ public interface ICacheService {/*** Get User Map** @return ConcurrentHashMap User Map*/public ConcurrentHashMap<Long, User> getUserMap();}

步驟5:創建CacheService類

CacheService類是通過實現ICacheService接口創建的。 它提供對遠程緩存的訪問…

package com.otv.cache.service;import java.util.concurrent.ConcurrentHashMap;import com.otv.user.User;/*** Cache Service Implementation** @author onlinetechvision.com* @since 10 Mar 2012* @version 1.0.0**/ public class CacheService implements ICacheService {//User Map is injected...ConcurrentHashMap<Long, User> userMap;/*** Get User Map** @return ConcurrentHashMap User Map*/public ConcurrentHashMap<Long, User> getUserMap() {return userMap;}/*** Set User Map** @param ConcurrentHashMap User Map*/public void setUserMap(ConcurrentHashMap<Long, User> userMap) {this.userMap = userMap;}}

步驟6:建立IHttpUserService接口

創建了代表Http用戶服務接口的IHttpUserService。 此外,它為Http客戶端提供了遠程方法。

package com.otv.http.server;import java.util.List;import com.otv.user.User;/*** Http User Service Interface** @author onlinetechvision.com* @since 10 Mar 2012* @version 1.0.0**/ public interface IHttpUserService {/*** Add User** @param User user* @return boolean response of the method*/public boolean addUser(User user);/*** Delete User** @param User user* @return boolean response of the method*/public boolean deleteUser(User user);/*** Get User List** @return List user list*/public List<User> getUserList();}

步驟7:創建HttpUserService類

HttpUserService類是通過實現IHttpUserService接口創建的。

package com.otv.http.server;import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger;import com.otv.cache.service.ICacheService; import com.otv.user.User;/*** Http User Service Implementation** @author onlinetechvision.com* @since 10 Mar 2012* @version 1.0.0**/ public class HttpUserService implements IHttpUserService {private static Logger logger = Logger.getLogger(HttpUserService.class);//Remote Cache Service is injected...ICacheService cacheService;/*** Add User** @param User user* @return boolean response of the method*/public boolean addUser(User user) {getCacheService().getUserMap().put(user.getId(), user);logger.debug("User has been added to cache. User : "+getCacheService().getUserMap().get(user.getId()));return true;}/*** Delete User** @param User user* @return boolean response of the method*/public boolean deleteUser(User user) {getCacheService().getUserMap().remove(user.getId());logger.debug("User has been deleted from cache. User : "+user);return true;}/*** Get User List** @return List user list*/public List<User> getUserList() {List<User> list = new ArrayList<User>();list.addAll(getCacheService().getUserMap().values());logger.debug("User List : "+list);return list;}/*** Get Remote Cache Service** @return ICacheService Remote Cache Service*/public ICacheService getCacheService() {return cacheService;}/*** Set Remote Cache Service** @param ICacheService Remote Cache Service*/public void setCacheService(ICacheService cacheService) {this.cacheService = cacheService;}}

步驟8:創建HttpUserService-servlet.xml

HttpUserService應用程序上下文如下所示。 該xml必須命名為your_servlet_name-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:util="http://www.springframework.org/schema/util"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-3.0.xsd"><!-- User Map Declaration --><bean id="UserMap" class="java.util.concurrent.ConcurrentHashMap" /><!-- Cache Service Declaration --><bean id="CacheService" class="com.otv.cache.service.CacheService"><property name="userMap" ref="UserMap"/></bean> <!-- Http User Service Bean Declaration --><bean id="HttpUserService" class="com.otv.http.server.HttpUserService" ><property name="cacheService" ref="CacheService"/></bean><!-- Http Invoker Service Declaration --><bean id="HttpUserServiceExporter" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"><!-- service represents Service Impl --><property name="service" ref="HttpUserService"/><!-- serviceInterface represents Http Service Interface which is exposed --><property name="serviceInterface" value="com.otv.http.server.IHttpUserService"/></bean><!-- Mapping configurations from URLs to request handler beans --><bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"><property name="mappings"><props><prop key="/HttpUserService">HttpUserServiceExporter</prop></props></property></bean></beans>

步驟9:創建web.xml

web.xml的配置如下:

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"><display-name>OTV_SpringHttpInvoker</display-name><!-- Spring Context Configuration' s Path definition --><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/HttpUserService-servlet.xml</param-value></context-param><!-- The Bootstrap listener to start up and shut down Spring's root WebApplicationContext. It is registered to Servlet Container --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- Central dispatcher for HTTP-based remote service exporters. Dispatches to registered handlers for processing web requests.--><servlet><servlet-name>HttpUserService</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><load-on-startup>2</load-on-startup></servlet><!-- Servlets should be registered with servlet container and mapped with url for the http requests. --><servlet-mapping><servlet-name>HttpUserService</servlet-name><url-pattern>/HttpUserService</url-pattern></servlet-mapping><welcome-file-list><welcome-file>/pages/index.xhtml</welcome-file></welcome-file-list></web-app>

步驟10:創建HttpUserServiceClient類

HttpUserServiceClient類已創建。 它調用遠程Http用戶服務并執行用戶操作。

package com.otv.http.client;import org.apache.log4j.Logger; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;import com.otv.http.server.IHttpUserService; import com.otv.user.User;/*** Http User Service Client** @author onlinetechvision.com* @since 24 Feb 2012* @version 1.0.0**/ public class HttpUserServiceClient {private static Logger logger = Logger.getLogger(HttpUserServiceClient.class);/*** Main method of the Http User Service Client**/public static void main(String[] args) {logger.debug("Http User Service Client is starting...");//Http Client Application Context is started...ApplicationContext context = new ClassPathXmlApplicationContext("httpClientAppContext.xml");//Remote User Service is called via Http Client Application Context...IHttpUserService httpClient = (IHttpUserService) context.getBean("HttpUserService");//New User is created...User user = new User();user.setId(1);user.setName("Bruce");user.setSurname("Willis");//The user is added to the remote cache...httpClient.addUser(user);//The users are gotten via remote cache...httpClient.getUserList();//The user is deleted from remote cache...httpClient.deleteUser(user);logger.debug("Http User Service Client is stopped...");} }

步驟11:創建httpClientAppContext.xml

Http客戶端應用程序上下文如下所示:

<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><!-- Http Invoker Client Declaration --><bean id="HttpUserService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"><!-- serviceUrl demonstrates Http Service Url which is called--><property name="serviceUrl" value="http://remotehost:port/OTV_SpringHttpInvoker-0.0.1-SNAPSHOT/HttpUserService"/><!-- serviceInterface demonstrates Http Service Interface which is called --><property name="serviceInterface" value="com.otv.http.server.IHttpUserService"/></bean></beans>

步驟12:部署項目

OTV_SpringHttpInvoker Project部署到Tomcat之后,將啟動Http用戶服務客戶端,并且輸出日志如下所示:

.... 15.03.2012 21:26:41 DEBUG (DispatcherServlet.java:819) - DispatcherServlet with name 'HttpUserService' processing POST request for [/OTV_SpringHttpInvoker-0.0.1-SNAPSHOT/HttpUserService] 15.03.2012 21:26:41 DEBUG (AbstractUrlHandlerMapping.java:124) - Mapping [/HttpUserService] to HandlerExecutionChain with handler [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter@f9104a] and 1 interceptor 15.03.2012 21:26:41 DEBUG (RemoteInvocationTraceInterceptor.java:73) - Incoming HttpInvokerServiceExporter remote call: com.otv.http.server.IHttpUserService.addUser 15.03.2012 21:26:41 DEBUG (HttpUserService.java:33) - User has been added to cache. User : Id : 1, Name : Bruce, Surname : Willis 15.03.2012 21:26:41 DEBUG (RemoteInvocationTraceInterceptor.java:79) - Finished processing of HttpInvokerServiceExporter remote call: com.otv.http.server.IHttpUserService.addUser 15.03.2012 21:26:41 DEBUG (DispatcherServlet.java:957) - Null ModelAndView returned to DispatcherServlet with name 'HttpUserService': assuming HandlerAdapter completed request handling 15.03.2012 21:26:41 DEBUG (FrameworkServlet.java:913) - Successfully completed request 15.03.2012 21:26:41 DEBUG (DispatcherServlet.java:819) - DispatcherServlet with name 'HttpUserService' processing POST request for [/OTV_SpringHttpInvoker-0.0.1-SNAPSHOT/HttpUserService] 15.03.2012 21:26:41 DEBUG (AbstractUrlHandlerMapping.java:124) - Mapping [/HttpUserService] to HandlerExecutionChain with handler [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter@f9104a] and 1 interceptor 15.03.2012 21:26:41 DEBUG (RemoteInvocationTraceInterceptor.java:73) - Incoming HttpInvokerServiceExporter remote call: com.otv.http.server.IHttpUserService.getUserList 15.03.2012 21:26:41 DEBUG (HttpUserService.java:57) - User List : [Id : 1, Name : Bruce, Surname : Willis] 15.03.2012 21:26:41 DEBUG (RemoteInvocationTraceInterceptor.java:79) - Finished processing of HttpInvokerServiceExporter remote call: com.otv.http.server.IHttpUserService.getUserList 15.03.2012 21:26:41 DEBUG (DispatcherServlet.java:957) - Null ModelAndView returned to DispatcherServlet with name 'HttpUserService': assuming HandlerAdapter completed request handling 15.03.2012 21:26:41 DEBUG (FrameworkServlet.java:913) - Successfully completed request 15.03.2012 21:26:41 DEBUG (DispatcherServlet.java:819) - DispatcherServlet with name 'HttpUserService' processing POST request for [/OTV_SpringHttpInvoker-0.0.1-SNAPSHOT/HttpUserService] 15.03.2012 21:26:41 DEBUG (AbstractUrlHandlerMapping.java:124) - Mapping [/HttpUserService] to HandlerExecutionChain with handler [org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter@f9104a] and 1 interceptor 15.03.2012 21:26:41 DEBUG (RemoteInvocationTraceInterceptor.java:73) - Incoming HttpInvokerServiceExporter remote call: com.otv.http.server.IHttpUserService.deleteUser 15.03.2012 21:26:41 DEBUG (HttpUserService.java:45) - User has been deleted from cache. User : Id : 1, Name : Bruce, Surname : Willis 15.03.2012 21:26:41 DEBUG (RemoteInvocationTraceInterceptor.java:79) - Finished processing of HttpInvokerServiceExporter remote call: com.otv.http.server.IHttpUserService.deleteUser 15.03.2012 21:26:41 DEBUG (DispatcherServlet.java:957) - Null ModelAndView returned to DispatcherServlet with name 'HttpUserService': assuming HandlerAdapter completed request handling 15.03.2012 21:26:41 DEBUG (FrameworkServlet.java:913) - Successfully completed request ...

步驟13:下載

OTV_SpringHttpInvoker

參考: Online Technology Vision博客上的JCG合作伙伴 Eren Avsarogullari 提供的Http Invoker的Spring Remoting支持 。


翻譯自: https://www.javacodegeeks.com/2012/04/spring-remoting-support-with-http.html

總結

以上是生活随笔為你收集整理的Http Invoker的Spring Remoting支持的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产极品美女在线 | 先锋av资源| 亚洲一区二区三区免费在线观看 | a级黄色片 | 人妻互换一区二区激情偷拍 | 91视频看看 | 精品国产一二三区 | 黄色三级生活片 | 久久久www免费人成人片 | 日本少妇一级 | 真实乱偷全部视频 | 亚洲黄色精品 | 男人爽女人下面动态图 | 蜜臀视频一区二区 | 特黄特色大片免费视频大全 | 香蕉一级视频 | 三级成人在线 | 涩涩视频网 | 韩国伦理片在线播放 | 精品一区二区三区电影 | 国产福利午夜 | 人人模人人干 | 超碰97色| 欧美国产在线视频 | 国产精品久久久久久久成人午夜 | 日韩精品一级 | 日爽夜爽 | 久久久久一区二区三区 | 一本久道久久综合 | 一级肉体全黄裸片中国 | 一区二区在线看 | 国产黄色美女视频 | 国产精品区在线观看 | 黄色av片三级三级三级免费看 | 超碰人人在线观看 | 农村少妇无套内谢粗又长 | 午夜一区二区三区在线观看 | 香蕉人妻av久久久久天天 | 舒淇裸体午夜理伦 | 在线精品免费视频 | 欧美视频自拍偷拍 | 国产精品久久久久久久久夜色 | 在线观看不卡的av | 亚洲网站在线免费观看 | 欧美另类自拍 | 久久机热这里只有精品 | 91久久精品www人人做人人爽 | 调教丰满的已婚少妇在线观看 | 久久夜色av | 丰满圆润老女人hd | 国产成人无码精品久久久久 | 日韩在线视频播放 | mm131国产精品 | 香蕉视频成人在线观看 | www.99re. | 亚洲人无码成www久久 | 欧美高清在线观看 | 亚一区 | 亚洲乱色熟女一区二区三区 | 天堂在线资源网 | 奶妈的诱惑 | 开心春色激情网 | 欧美尹人| 国产免费a | 韩日三级视频 | 久久久久久久久久久久国产 | 自拍色图 | 日本美女操 | 成年人小视频在线观看 | 午夜精品久久久久久久久久久久 | 久久精品国产亚洲a | 欧美亚洲色综久久精品国产 | 国产色无码精品视频国产 | 美女免费网站 | 成年人的免费视频 | 久热精品视频在线 | 亚洲精品国产精品国自产观看 | 成年人免费看 | 中国一级特黄真人毛片免费观看 | 天天综合精品 | 已满十八岁免费观看 | 亚洲天堂2018av | 乱色熟女综合一区二区三区 | 欧美混交群体交 | 佐山爱av在线 | 人人干免费 | 灌满闺乖女h高h调教尿h | 国产精品日韩一区二区三区 | 国产午夜精品在线观看 | 污视频在线网站 | 日韩三级视频在线 | 日韩一区免费 | 亚洲午夜久久 | 一级片视频免费观看 | 一区二区三区色 | 亚洲欧洲成人在线 | 精品久久久无码中文字幕 | www.欧美国产 | 久久系列 |