This is my code ....
@Path("/services/upload")
@WebService(serviceName = "upload", name = "UploadWebService",
targetNamespace = "http://ws.surajchh.com")
public interface TestServiceAPI {
@Consumes("multipart/form-data")
@WebMethod(operationName = "video")
@POST
@Path("/video")
@WebResult(name = "UploadedUrl")
public String uploadVideo(@WebParam(name = "data") @PathParam("data")
@XmlMimeType("application/octet-stream")DataHandler data) throws
ServiceException;
}
----------------------------
public class TestServiceAPIImpl implements TestServiceAPI {
private final Log logger = LogFactory.getLog(this.getClass());
@Autowired
@Qualifier("wsMessageSource")
private MessageSource messageSource;
private String videoPath;
@Override
public String uploadVideo(DataHandler data) throws ServiceException {
try {
this.videoPath =
messageSource.getMessage("video.rootDirectory", null,
null,null);
this.logger.info("vpath = "+this.videoPath);
if(videoPath== null)
throw new ServiceException("Configuration
error");
this.logger.info("Validate.....");
this.logger.info("Uploading video......");
this.logger.info("VideoRootPath ="+videoPath);
this.logger.info("Uploading video......contanint
found");
//InputStream inputStream =
dataHandler.getInputStream();
this.logger.info("Uploading video......inserting video
info");
String url = this.videoService.createVideo(videoInfo);
this.logger.info("Uploading video......processing
upload");
String uploadPath = this.processUpload(data);
return uploadPath;
} catch (Exception e) {
throw new ServiceException(e.getMessage());
}
}
private String processUpload(DataHandler dataHandler) throws Exception {
int videoId = 22;
String videoPath = this.videoPath+ File.separator + videoId;
File f = new File(videoPath);
final String uploadPath = f.getPath() + File.separator +
videoId + "."+
avi;
File tempFile = File.createTempFile("upload" + videoId,
fileType);
OutputStream outputStream = new FileOutputStream(tempFile);//
new//
File(uploadPath)
synchronized (dataHandler) {
synchronized (outputStream) {
byte[] b = new byte[2048];
while (true) {
int byteRead =
dataHandler.getInputStream().read(b);
if (byteRead == -1)
break;
outputStream.write(b, 0, byteRead);
}
outputStream.flush();
outputStream.close();
File serverFile = new File(uploadPath);
tempFile.renameTo(serverFile);
logger.debug("Uploading Done...");
return uploadPath;
}
}
}
}
------------------Testuploader------------------
public class UploadClientTest {
public static void main(String args[]) throws Exception {
testVideoUpload();
System.exit(0);
}
private static void testVideoUpload() {
TestServiceAPI client = createUploadService();
String fileName = System.getProperty("user.home")+
File.separator+"Videos"+File.separator+"videos.zip";
System.out.println("File path :" +fileName);
DataSource source = new FileDataSource(new File(fileName));
client.uploadVideo(new DataHandler(source));
}
private static TestServiceAPI createUploadService() {
System.out.println("File path :" +s);
long timeout = 100000L;//60000
Map<String,Object> props = new HashMap<String, Object>();
props.put("mtom-enabled", Boolean.TRUE);
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.getInInterceptors().add(new LoggingInInterceptor());
factory.getOutInterceptors().add(new LoggingOutInterceptor());
factory.setServiceClass(UploadService.class);
factory.setAddress("http://localhost:8080/uplaodTest/api/services/upload");
factory.setProperties(props);
UploadService client = (UploadService) factory.create();
//
Client clientCfx = ClientProxy.getClient(client);
HTTPConduit conduit = (HTTPConduit) clientCfx.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setConnectionTimeout(0);
httpClientPolicy.setReceiveTimeout(0);
httpClientPolicy.setAllowChunking(true);
// ((HTTPConduit)
factory.getClientFactoryBean().getClient().getConduit()).setClient(httpClientPolicy);
conduit.setClient(httpClientPolicy);
return client;
}
}
--
View this message in context:
http://old.nabble.com/MTOM-OutOfMemory-tp26544421p26832040.html
Sent from the cxf-user mailing list archive at Nabble.com.