扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/config">
<wsdl location="web-inf/conf/BinaryService.wsdl"
packageName="wsidotnet" />
</configuration>
到目前为止,还有两个文件没有提供:
jaxrpc-ri.xml:
<?xml version="1.0" encoding="UTF-8"?>
<webServices xmlns="http://java.sun.com/xml/ns/jax-rpc/ri/dd"
version="1.0"
targetNamespaceBase="http://java.sun.com/xml/ns/jax-rpc/wsi/wsdl"
typeNamespaceBase="http://java.sun.com/xml/ns/jax-rpc/wsi/types"
urlPatternBase="/ws">
<endpoint name="ImageBinaryService" displayName="Stock Example"
description="Stock Example Web Service endpoint"
interface="wsidotnet.IImage" implementation="wsidotnet.IImage_Impl"
model="/WEB-INF/model.xml.gz" />
<endpointMapping endpointName="ImageBinaryService" urlPattern="/binary" />
</webServices>
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">
<context-param>
<param-name>BinaryPath</param-name>
<param-value>更改成你的本地文件路径</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.jws</welcome-file>
</welcome-file-list>
</web-app>
下面就是构建过程,首先,执行wsi server service得到服务器端的java制品,包括重新生成的SEI,wscompile还生成了一个实现文件IImage_Impl ,后面要修改这个类,在其中加入有用的方法.
wsidotnet.IImage清单:
package wsidotnet;
public interface IImage extends java.rmi.Remote {
public wsidotnet.ConstrucMsgResponse construcMsg(wsidotnet.ConstrucMsg parameters) throws
java.rmi.RemoteException;
public wsidotnet.FetchFileListResponse fetchFileList(wsidotnet.FetchFileList parameters) throws
java.rmi.RemoteException;
public wsidotnet.FetchImageResponse fetchImage(wsidotnet.FetchImage parameters) throws
java.rmi.RemoteException;
public wsidotnet.GetFileListResponse getFileList(wsidotnet.GetFileList parameters) throws
java.rmi.RemoteException;
}
和前面的com.bin.IImage接口相比很不同了.因为采用文档样式的绑定,所以这里就产生了所谓的包装类了.
实现文件为:
package wsidotnet;
import java.io.File;
import java.io.FileInputStream;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Calendar;
import java.util.Date;
import javax.servlet.ServletContext;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.server.ServiceLifecycle;
import javax.xml.rpc.server.ServletEndpointContext;
public class IImage_Impl implements wsidotnet.IImage, java.rmi.Remote,ServiceLifecycle {
ServletEndpointContext servletEndpointContext = null;
String binarypath = "";
ServletContext servletContext = null;
public wsidotnet.ConstrucMsgResponse construcMsg(wsidotnet.ConstrucMsg parameters) throws
java.rmi.RemoteException {
wsidotnet.ConstrucMsgResponse _retVal = null;
return _retVal;
}
public wsidotnet.FetchFileListResponse fetchFileList(wsidotnet.FetchFileList parameters) throws
java.rmi.RemoteException {
wsidotnet.FetchFileListResponse _retVal = new FetchFileListResponse();
_retVal.setResult(fetchFileList());
return _retVal;
}
public wsidotnet.FetchImageResponse fetchImage(wsidotnet.FetchImage parameters) throws
java.rmi.RemoteException {
wsidotnet.FetchImageResponse _retVal = new FetchImageResponse();
_retVal.setResult(fetchImage(parameters.getString_1()));
return _retVal;
}
public wsidotnet.GetFileListResponse getFileList(wsidotnet.GetFileList parameters) throws
java.rmi.RemoteException {
wsidotnet.GetFileListResponse _retVal = null;
return _retVal;
}
private FileInfo[] fetchFileList() {
File file = new File(this.binarypath);
System.out.println(this.binarypath);
File[] c = file.listFiles();
FileInfo[] fis = new FileInfo[c.length];
for (int i = 0; i < c.length; i++) {
FileInfo fi = new FileInfo();
fi.setIsdir(c[i].isDirectory());
fi.setFilename(c[i].getName());
fi.setFilelength(c[i].length());
fi.setFilepath(c[i].getAbsolutePath());
Calendar cal=Calendar.getInstance();
cal.setTime(new Date(c[i].lastModified()));
fi.setCreatedate(cal);
fis[i] = fi;
}
return fis;
}
private byte[] fetchImage(String sn) {
File file = new File(sn);
byte[] b=null;
MappedByteBuffer buffer = null;
try {
FileInputStream is = new FileInputStream(file);
b=new byte[(int)file.length()];
is.read(b,0,(int)file.length());
/*
FileChannel fc = is.getChannel();
buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
buffer.get
*/
} catch (Exception ex) {
System.out.println(ex);
}
//return buffer.array();
return b;
}
public void destroy() {
// TODO Auto-generated method stub
servletEndpointContext = null;
servletContext = null;
}
public void init(Object arg0) throws ServiceException {
// TODO Auto-generated method stub
servletEndpointContext = (ServletEndpointContext) arg0;
servletContext = servletEndpointContext.getServletContext();
binarypath = servletContext.getInitParameter("BinaryPath");
}
}
这里展示的实现类,已经过修改,让它扩展了ServiceLifecycle接口,以便运行环境送给它小金豆.这里就是获得了文件路径.此外,还提供了两个私有方法:fetchImage,fetchFileList用于具体执行功能,这里也可以把这两个方法移动到一个新类,然后IImage_Impl使用这个新类,使IImage_Impl类变成调用者对外部类的适配器,这样就形成了一个适配器模式.
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者