4
Java Web Services를 처음 사용하므로 잘못 처리했을 수 있습니다. ,Java 웹 서비스 : DataHandler 클래스를 사용하여 파일 전송
package fileclient;
import java.io.FileOutputStream;
import java.io.OutputStream;
import javax.activation.DataHandler;
/**
*
* @author pc1
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
fspg.WSFileSenderService service = new fspg.WSFileSenderService();
fspg.WSFileSender port = service.getWSFileSenderPort();
DataHandler handler = port.getfile("FileSender/file.jpg");
OutputStream out = new FileOutputStream("dest.jpg");
handler.writeTo(out);
out.close();
System.out.println("Done");
} catch (Exception ex) {
// TODO handle custom exceptions here
}
}
}
것 같다 :
웹 서비스 :
이import java.net.MalformedURLException;
import java.net.URL;
import javax.activation.DataHandler;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlMimeType;
/**
*
* @author pc1
*/
@WebService()
public class WSFileSender {
@WebMethod(operationName = "getfile")
public @XmlMimeType("application/octet-stream") DataHandler getfile(@WebParam(name = "path") String path) {
DataHandler datahandler = null;
try {
datahandler = new DataHandler(new URL(path));
}
catch (MalformedURLException e) {
System.out.println("Bad");
}
return datahandler;
}
}
클라이언트이 내가있어 무엇인가 -
나는 DataHandler에를 사용하여 파일을 전송하기 위해 노력하고있어 마치 모든 일이 제대로 수행되고 있지만 생성 된 파일이 비어있는 것처럼 - 내가 뭘 잘못하고 있니?
================= 편집 ================== GETFILE 의해
DataHandler에 객체를 리턴()가 null 인 경우 - 웹 서비스에서이 객체를 반환 할 수 있습니까?
FileDataSource가 정상적으로 작동합니다. 감사합니다. – zbigh