日期:2014-05-16  浏览次数:20338 次

远程调用 HttpInvoker JSP工程之间的数据交互

在这里我所实现的一个功能是点击一个按钮需要将PCS工程的数据传递到PIS然后交由其对数据进行更新操作。

1、PIS上的相关配置与文件?? (服务器端)

web.xml? 里添加下述相关内容

 <!--与PCS工程交互的配置 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:/META-INF/**/spring-*.xml,classpath*:/META-INF/**/remote-servlet.xml</param-value>
    </context-param>
    <!-- spring 加载监视器 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>com.yihaodian.pis.webapp.listener.AppRequestListener</listener-class>
    </listener>
 <servlet>
	<servlet-name>remote</servlet-name>
	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
	<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
	<servlet-name>remote</servlet-name>
	<url-pattern>/remoting/*</url-pattern>
</servlet-mapping>
<!-- 另一个工程的配置-->
 <servlet>
        <description>HTTP Exporters</description>
        <servlet-name>services</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>services</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

?remote-servlet.xml? 的内容?????????? 将PIS的BEAN暴露给PCS然PCS对其进行调用

<?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.5.xsd">
   <bean id="rmiService" class="com.yihaodian.pis.service.testremoteinvoke.IRemoteServiceImpl"></bean>
    <bean class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter" name="/remoteService">
        <property name="service" ref="rmiService" />
        <property name="serviceInterface" value="com.yihaodian.pis.service.testremoteinvoke.IRemoteService"/>
    </bean>
</beans>
?

接口以及其实现类(有PCS对其实现类的方法进行调用)

实现类IRemoteServiceImpl。java:

package com.yihaodian.pis.service.testremoteinvoke;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.newheight.service.webservice.dto.BackOperator;
import com.yihaodian.pis.dto.ProductHistoryDTO;
import com.yihaodian.pis.dto.TaskDto;
import com.yihaodian.pis.service.TaskService;

public class IRemoteServiceImpl implements IRemoteService {
	private static final Logger logger = Logger
			.getLogger(IRemoteServiceImpl.class);

	public String getString(String msg) {
		String str = "正在请求调用。。。远程服务调用成功" + msg;
		return str;
	}

	public String getProduct(String siteid, String productCode) {
		ApplicationContext context = new ClassPathXmlApplicationContext(
				new String[] { "classpath*:/META-INF/**/spring-*.xml" });
		TaskService taskSvc = (TaskService) context.getBean("taskSvc");
		//当数据很多时就会出现数组指数出界
		String[] site = siteid.split(",");
		String[] productCodes = productCode.split(",");
		int len = site.length;
		Integer[] taskIds = new Integer[len];
		for (int i = 0; i < len; i++) {
			TaskDto taskD