<!-- rmi方式 ,不能穿透防火墙-->
<bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="fileServiceImpl" />
<!-- 定义服务名 -->
<property name="serviceName" value="RmiFileService" />
<property name="serviceInterface" value="com.roiland.interf.FileService" />
<property name="registryPort" value="8088" />
</bean>
http://my.oschina.net/linuxfelix/blog/120202
<!--spring invokerService spring自带远程接口服务-->
<!-- 交给Spring管理,bean的名称是:userServiceabc, com.roiland.cms.pxd.UserInter的实现类-->
<bean id="userServiceabc" class="com.roiland.cms.pxd.impl.UserInterImpl"/>
<!-- 这个配置,就是把userService接口,提供给远程调用 -->
<bean id="httpServiceabc" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service">
<ref bean="userServiceabc" />
</property>
<property name="serviceInterface"
value="com.roiland.cms.pxd.UserInter"><!--为客户端提供的接口,-->
</property>
</bean>
<!-- 远程服务的URL http://www.audi-online.cn:8080/audionline/test.html-->
<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/test.html">httpServiceabc</prop><!--映射访问一个地址test.html-->
</props>
</property>
</bean>
<!--服务端实现类-->
package com.roiland.cms.pxd.impl;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.springframework.web.multipart.MultipartFile;
import com.roiland.cms.pxd.UserInter;
public class UserInterImpl implements UserInter {
@Override
public String add(String name) {
// TODO Auto-generated method stub
String res = "欢迎"+name+"访问接口上传文件";
System.out.println(name+"访问接口");
return res;
}
@Override
public boolean upload(String filename,byte [] b) {
boolean result = false;
if(b.length==0){
return result;
}
try {
String path = System.getProperty("user.dir");
path = path.substring(0,path.indexOf(":"))+"://upload/"+filename;
System.out.println(path+"-----------上传文件");
File file = new File(path);
if(!file.exists()){
file.createNewFile();
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
out.write(b);
out.flush();
out.close();
result = true;
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
@Override
public boolean uploadfile(InputStream is) {
// TODO Auto-generated method stub
if(is!=null){
System.out.println(2222);
}
return false;
}
}
<!--客户端配置-->
<bean id="fs" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="http://www.audi-online.cn:8080/audionline/test.html"></property>
<property name="serviceInterface" value="com.roiland.cms.pxdinterface.FileService" /> <!--客户端要有这个接口,跟服务端一样,用于接收-->
</bean>
<bean id="serviceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="service" ref="fileServiceImpl" />
<!-- 定义服务名 -->
<property name="serviceName" value="RmiFileService" />
<property name="serviceInterface" value="com.roiland.interf.FileService" />
<property name="registryPort" value="8088" />
</bean>
http://my.oschina.net/linuxfelix/blog/120202
<!--spring invokerService spring自带远程接口服务-->
<!-- 交给Spring管理,bean的名称是:userServiceabc, com.roiland.cms.pxd.UserInter的实现类-->
<bean id="userServiceabc" class="com.roiland.cms.pxd.impl.UserInterImpl"/>
<!-- 这个配置,就是把userService接口,提供给远程调用 -->
<bean id="httpServiceabc" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service">
<ref bean="userServiceabc" />
</property>
<property name="serviceInterface"
value="com.roiland.cms.pxd.UserInter"><!--为客户端提供的接口,-->
</property>
</bean>
<!-- 远程服务的URL http://www.audi-online.cn:8080/audionline/test.html-->
<bean
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/test.html">httpServiceabc</prop><!--映射访问一个地址test.html-->
</props>
</property>
</bean>
<!--服务端实现类-->
package com.roiland.cms.pxd.impl;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.springframework.web.multipart.MultipartFile;
import com.roiland.cms.pxd.UserInter;
public class UserInterImpl implements UserInter {
@Override
public String add(String name) {
// TODO Auto-generated method stub
String res = "欢迎"+name+"访问接口上传文件";
System.out.println(name+"访问接口");
return res;
}
@Override
public boolean upload(String filename,byte [] b) {
boolean result = false;
if(b.length==0){
return result;
}
try {
String path = System.getProperty("user.dir");
path = path.substring(0,path.indexOf(":"))+"://upload/"+filename;
System.out.println(path+"-----------上传文件");
File file = new File(path);
if(!file.exists()){
file.createNewFile();
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
out.write(b);
out.flush();
out.close();
result = true;
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
@Override
public boolean uploadfile(InputStream is) {
// TODO Auto-generated method stub
if(is!=null){
System.out.println(2222);
}
return false;
}
}
<!--客户端配置-->
<bean id="fs" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="http://www.audi-online.cn:8080/audionline/test.html"></property>
<property name="serviceInterface" value="com.roiland.cms.pxdinterface.FileService" /> <!--客户端要有这个接口,跟服务端一样,用于接收-->
</bean>