我有一个网络服务,我希望客户端通过网络方法在服务器上发送一个文件,然后读取客户端发送的文件。
网络方法是这样的:
@WebMethod(operationName = "getfile")
public void getfile(@WebParam(name = "getfile") DataHandler dh) throws IOException {
InputStream in = dh.getInputStream();
StringWriter writer = new StringWriter();
org.apache.commons.io.IOUtils.copy(in, writer, "UTF-8");
String theString = writer.toString();
System.out.println(theString);
}
客户端从这里调用该方法:
public static void main (String args[]) throws IOException, IOException_Exception{
SOAPService service = new SOAPService();
SOAPProxy = service.getGetXMLPort();
File file = new File("C:\\Users\\manos\\Downloads\\manos.txt");
FileDataSource fd = new FileDataSource(file);
DataHandler datahandler = new DataHandler(fd);
InputStream in = datahandler.getInputStream();
byte [] array = org.apache.commons.io.IOUtils.toByteArray(in);
SOAPProxy.getfile(array);
}
但我在 SOAPProxy.getfile(array); 行中得到了 NullPointerException
这是错误:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: java.lang.NullPointerException
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:111)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:129)
at $Proxy32.getfile(Unknown Source)
at com.mantsap.getxmlclient.SOAPClient.main(SOAPClient.java:25)
Java 结果:1
数组的长度是 8!我做了一个system.out来确定。
文件 manos 只是一个文本文件。
提前致谢。:)