Cloud - Computing - Practical 6 - MTOM
Cloud - Computing - Practical 6 - MTOM
Downloads Required:
Netbeans 8.0.2: https://dlc-cdn.sun.com/netbeans/8.0.2/final/bundles/netbeans-8.0.2-
windows.exe
Java JDK 8: https://www.oracle.com/in/java/technologies/javase/javase8u211-later-
archive-downloads.html#license-lightbox
Click Next
Click Next
Click Finish
import java.io.*;
import javax.jws.Oneway;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.xml.ws.soap.MTOM;
@WebMethod(operationName = "upload")
@Oneway
public void upload(@WebParam(name = "Filename") String Filename, @WebParam(name =
"ImageBytes") byte[] ImageBytes) {
String filePath = "C:/Picture/upload/" + Filename;
try {
FileOutputStream fos = new FileOutputStream(filePath);
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write(ImageBytes);
bos.close();
System.out.println("Received file: " + filePath);
} catch (Exception ex) {
ex.printStackTrace();
}
}
@WebMethod(operationName = "download")
public byte[] download(@WebParam(name = "Filename") String Filename) {
String filePath = "C:/Picture/upload/" + Filename;
System.out.println("Sending file: " + filePath);
try {
File file = new File(filePath);
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);
byte[] fileBytes = new byte[(int) file.length()];
bis.read(fileBytes);
bis.close();
return fileBytes;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
}
Save File.
Run Project
Right Click on Mtomapplication > New > Web Service Client.
If not available click on Others
Select on Browse
Package: pkg
Finish
New > JSP
Deploy Project